]> khamidou — GitHub mirrors - electron.git/commitdiff
Include exit code with quit event
authorKevin Sawicki <kevinsawicki@gmail.com>
Thu, 10 Dec 2015 02:09:59 +0000 (18:09 -0800)
committerKevin Sawicki <kevinsawicki@gmail.com>
Thu, 10 Dec 2015 02:09:59 +0000 (18:09 -0800)
atom/browser/api/atom_api_app.cc
atom/browser/api/atom_api_app.h
atom/browser/api/lib/app.coffee
atom/browser/atom_browser_main_parts.cc
atom/browser/atom_browser_main_parts.h
atom/browser/browser.cc
atom/browser/browser_observer.h
spec/api-app-spec.coffee
spec/fixtures/api/quit-app/main.js
spec/static/index.html

index 0c3623583c62d2e25f04eccfdf669f72200e313d..81ec3fefd51043f4b559a097def54587d9f10178 100644 (file)
@@ -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))
index a6f99d65e0af1963c64f6ee29fb493a7a2b87c22..f04a19e67cdfa849cd4e5e34b81293f93342daf1 100644 (file)
@@ -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;
index fc0a78298c4d39ef719db6d83acb1fc1dba5189c..9a7fc6e71141fb06a129278a45cc5ec850e8cf8f 100644 (file)
@@ -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']
index fd72f5e4ae9a655191d1c80c7ce62c9e554d99c3..eadd52ac44c8c6902393177a8961d63db416644e 100644 (file)
@@ -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);
index fbc59f7f811dd3e7a6ec5c46e962e3ccbaccd5a1..c1c0c89c67860cbd16a63b3488c3144b65b99e0e 100644 (file)
@@ -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.
index c77f359760c91cdca0866fe8738456a081aa06df..ee00efa07110769a60ff2c06ebc97d0ebbbcd263 100644 (file)
@@ -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(
index f6d76bc13fb30179778768190d709bb25c57c641..f3ae2e364de4aeefc5b1847cbd631f5e3003308f 100644 (file)
@@ -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)
index adb64d363eb1b300abeaa7c070730b4752f026c3..7b7e5fa483df47cff241bbfb26bbfbc4fdffc061 100644 (file)
@@ -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()
index 4bdeb93a5e305e34a5c8a00e4cd330c75be30876..85939acd7348c60b69e6bfde272b50831f984fdf 100644 (file)
@@ -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))
 })
index ea86f6ee302d2c6112bcf71492c674904ea4125b..2053ca41355cdb89ddaa61a67b5f19ec20060d11 100644 (file)
@@ -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();