]> khamidou — GitHub mirrors - electron.git/commitdiff
Shutdown gracefully, fixes #227.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 10 Apr 2014 07:22:17 +0000 (15:22 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 10 Apr 2014 07:22:17 +0000 (15:22 +0800)
atom/browser/browser.cc
atom/browser/browser.h
atom/browser/browser_linux.cc
atom/browser/browser_mac.mm
atom/browser/browser_win.cc

index f071005e63652a5e8c084ff6745c59d82c6b8fc9..bc5afafaec3b1cb027933aa737682b4ee43d00f2 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "atom/browser/atom_browser_main_parts.h"
 #include "atom/browser/window_list.h"
+#include "base/message_loop/message_loop.h"
 
 namespace atom {
 
@@ -30,11 +31,16 @@ void Browser::Quit() {
 
   atom::WindowList* window_list = atom::WindowList::GetInstance();
   if (window_list->size() == 0)
-    NotifyAndTerminate();
+    NotifyAndShutdown();
 
   window_list->CloseAllWindows();
 }
 
+void Browser::Shutdown() {
+  is_quiting_ = true;
+  base::MessageLoop::current()->Quit();
+}
+
 std::string Browser::GetVersion() const {
   if (version_override_.empty()) {
     std::string version = GetExecutableFileVersion();
@@ -88,7 +94,7 @@ void Browser::DidFinishLaunching() {
   FOR_EACH_OBSERVER(BrowserObserver, observers_, OnFinishLaunching());
 }
 
-void Browser::NotifyAndTerminate() {
+void Browser::NotifyAndShutdown() {
   bool prevent_default = false;
   FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillQuit(&prevent_default));
 
@@ -97,7 +103,7 @@ void Browser::NotifyAndTerminate() {
     return;
   }
 
-  Terminate();
+  Shutdown();
 }
 
 void Browser::OnWindowCloseCancelled(NativeWindow* window) {
@@ -112,7 +118,7 @@ void Browser::OnWindowCloseCancelled(NativeWindow* window) {
 
 void Browser::OnWindowAllClosed() {
   if (is_quiting_)
-    NotifyAndTerminate();
+    NotifyAndShutdown();
   else
     FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWindowAllClosed());
 }
index 89481b2ec642371d3f41bd57d476dc484860a107..d8dd38a05ffc9ec2b3019b12dee3125903a73a3a 100644 (file)
@@ -26,8 +26,8 @@ class Browser : public WindowListObserver {
   // Try to close all windows and quit the application.
   void Quit();
 
-  // Quit the application immediately without cleanup work.
-  void Terminate();
+  // Cleanup everything and shutdown the application gracefully.
+  void Shutdown();
 
   // Focus the application.
   void Focus();
@@ -88,8 +88,8 @@ class Browser : public WindowListObserver {
   // Returns the name of application bundle or executable file.
   std::string GetExecutableFileProductName() const;
 
-  // Send the will-quit message and then terminate the application.
-  void NotifyAndTerminate();
+  // Send the will-quit message and then shutdown the application.
+  void NotifyAndShutdown();
 
   // Tell the system we have cancelled quiting.
   void CancelQuit();
index a62042710d40ec935924ab0a0c989a8e1587170b..c8d50a722ecf195fda9ceeecaf67e535c7e53fc0 100644 (file)
 
 namespace atom {
 
-void Browser::Terminate() {
-  is_quiting_ = true;
-  exit(0);
-}
-
 void Browser::Focus() {
   // Focus on the first visible window.
   WindowList* list = WindowList::GetInstance();
index d88be3ca5985a62f74cf401179a8f99e027572e5..23404edd56ce6b2fb3635ea397419010ceefc1f2 100644 (file)
 
 namespace atom {
 
-void Browser::Terminate() {
-  is_quiting_ = true;
-  [[AtomApplication sharedApplication] terminate:nil];
-}
-
 void Browser::Focus() {
   [[AtomApplication sharedApplication] activateIgnoringOtherApps:YES];
 }
index 74953cf0903262714732a1bb8884c13927554602..c0698f8f3637f44d3d06a4b0d514b45f1be54356 100644 (file)
@@ -33,11 +33,6 @@ BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) {
 
 }  // namespace
 
-void Browser::Terminate() {
-  is_quiting_ = true;
-  PostQuitMessage(0);
-}
-
 void Browser::Focus() {
   // On Windows we just focus on the first window found for this process.
   DWORD pid = GetCurrentProcessId();