Include exit code with quit event
This commit is contained in:
		
					parent
					
						
							
								aa82eddca8
							
						
					
				
			
			
				commit
				
					
						92433be888
					
				
			
		
					 10 changed files with 19 additions and 14 deletions
				
			
		|  | @ -180,8 +180,8 @@ void App::OnWindowAllClosed() { | |||
|   Emit("window-all-closed"); | ||||
| } | ||||
| 
 | ||||
| void App::OnQuit() { | ||||
|   Emit("quit"); | ||||
| void App::OnQuit(const int code) { | ||||
|   Emit("quit", code); | ||||
| 
 | ||||
|   if (process_singleton_.get()) { | ||||
|     process_singleton_->Cleanup(); | ||||
|  | @ -344,7 +344,7 @@ mate::ObjectTemplateBuilder App::GetObjectTemplateBuilder( | |||
|   auto browser = base::Unretained(Browser::Get()); | ||||
|   return mate::ObjectTemplateBuilder(isolate) | ||||
|       .SetMethod("quit", base::Bind(&Browser::Quit, browser)) | ||||
|       .SetMethod("_exit", base::Bind(&Browser::Exit, browser)) | ||||
|       .SetMethod("exit", base::Bind(&Browser::Exit, browser)) | ||||
|       .SetMethod("focus", base::Bind(&Browser::Focus, browser)) | ||||
|       .SetMethod("getVersion", base::Bind(&Browser::GetVersion, browser)) | ||||
|       .SetMethod("setVersion", base::Bind(&Browser::SetVersion, browser)) | ||||
|  |  | |||
|  | @ -42,7 +42,7 @@ class App : public AtomBrowserClient::Delegate, | |||
|   void OnBeforeQuit(bool* prevent_default) override; | ||||
|   void OnWillQuit(bool* prevent_default) override; | ||||
|   void OnWindowAllClosed() override; | ||||
|   void OnQuit() override; | ||||
|   void OnQuit(int code) override; | ||||
|   void OnOpenFile(bool* prevent_default, const std::string& file_path) override; | ||||
|   void OnOpenURL(const std::string& url) override; | ||||
|   void OnActivate(bool has_visible_windows) override; | ||||
|  |  | |||
|  | @ -34,17 +34,12 @@ app.setAppPath = (path) -> | |||
| app.getAppPath = -> | ||||
|   appPath | ||||
| 
 | ||||
| appExitCode = undefined | ||||
| app.exit = (exitCode) -> | ||||
|   appExitCode = exitCode | ||||
|   app._exit(exitCode) | ||||
| 
 | ||||
| # Map process.exit to app.exit, which quits gracefully. | ||||
| process.exit = app.exit | ||||
| 
 | ||||
| # Emit a process 'exit' event on app quit. | ||||
| app.on 'quit', -> | ||||
|   process.emit 'exit', appExitCode | ||||
| app.on 'quit', (event, exitCode) -> | ||||
|   process.emit 'exit', exitCode | ||||
| 
 | ||||
| # Routes the events to webContents. | ||||
| for name in ['login', 'certificate-error', 'select-client-certificate'] | ||||
|  |  | |||
|  | @ -61,6 +61,10 @@ bool AtomBrowserMainParts::SetExitCode(int code) { | |||
|   return true; | ||||
| } | ||||
| 
 | ||||
| int AtomBrowserMainParts::GetExitCode() { | ||||
|   return exit_code_ != nullptr ? *exit_code_ : 0; | ||||
| } | ||||
| 
 | ||||
| base::Closure AtomBrowserMainParts::RegisterDestructionCallback( | ||||
|     const base::Closure& callback) { | ||||
|   auto iter = destructors_.insert(destructors_.end(), callback); | ||||
|  |  | |||
|  | @ -34,6 +34,9 @@ class AtomBrowserMainParts : public brightray::BrowserMainParts { | |||
|   // Sets the exit code, will fail if the the message loop is not ready.
 | ||||
|   bool SetExitCode(int code); | ||||
| 
 | ||||
|   // Gets the exit code
 | ||||
|   int GetExitCode(); | ||||
| 
 | ||||
|   // Register a callback that should be destroyed before JavaScript environment
 | ||||
|   // gets destroyed.
 | ||||
|   // Returns a closure that can be used to remove |callback| from the list.
 | ||||
|  |  | |||
|  | @ -72,7 +72,8 @@ void Browser::Shutdown() { | |||
|   is_shutdown_ = true; | ||||
|   is_quiting_ = true; | ||||
| 
 | ||||
|   FOR_EACH_OBSERVER(BrowserObserver, observers_, OnQuit()); | ||||
|   int exitCode = AtomBrowserMainParts::Get()->GetExitCode(); | ||||
|   FOR_EACH_OBSERVER(BrowserObserver, observers_, OnQuit(exitCode)); | ||||
| 
 | ||||
|   if (base::MessageLoop::current()) { | ||||
|     base::MessageLoop::current()->PostTask( | ||||
|  |  | |||
|  | @ -24,7 +24,7 @@ class BrowserObserver { | |||
|   virtual void OnWindowAllClosed() {} | ||||
| 
 | ||||
|   // The browser is quitting.
 | ||||
|   virtual void OnQuit() {} | ||||
|   virtual void OnQuit(const int code) {} | ||||
| 
 | ||||
|   // The browser has opened a file by double clicking in Finder or dragging the
 | ||||
|   // file to the Dock icon. (OS X only)
 | ||||
|  |  | |||
|  | @ -44,6 +44,7 @@ describe 'app module', -> | |||
|       output = '' | ||||
|       appProcess.stdout.on 'data', (data) -> output += data | ||||
|       appProcess.on 'close', (code) -> | ||||
|         console.log output | ||||
|         assert.notEqual output.indexOf('Exit event with code: 123'), -1 | ||||
|         assert.equal code, 123 | ||||
|         done() | ||||
|  |  | |||
							
								
								
									
										2
									
								
								spec/fixtures/api/quit-app/main.js
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								spec/fixtures/api/quit-app/main.js
									
										
									
									
										vendored
									
									
								
							|  | @ -5,5 +5,5 @@ app.on('ready', function () { | |||
| }) | ||||
| 
 | ||||
| process.on('exit', function (code) { | ||||
|   console.log('Exit event with code: ' + code) | ||||
|   console.log('Exit event with code: ' + JSON.stringify(code, null, 2)) | ||||
| }) | ||||
|  |  | |||
|  | @ -56,6 +56,7 @@ | |||
|   mocha.ui('bdd').reporter(isCi ? 'tap' : 'html'); | ||||
| 
 | ||||
|   var query = Mocha.utils.parseQuery(window.location.search || ''); | ||||
|   query.grep = 'app.exit' | ||||
|   if (query.grep) mocha.grep(query.grep); | ||||
|   if (query.invert) mocha.invert(); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Kevin Sawicki
				Kevin Sawicki