]> khamidou — GitHub mirrors - electron.git/commitdiff
mac: Always cancel application termination.
authorCheng Zhao <zcbenz@gmail.com>
Mon, 14 Apr 2014 16:02:33 +0000 (00:02 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 14 Apr 2014 16:13:00 +0000 (00:13 +0800)
OS X's application termination doesn't work very well with C++ message
loops. Especially when we return NSTerminateLater for shouldTerminate,
it would be impossible for the C++ message loop to quit, because unless
we explictly let NSApp terminate the application, the message loop would
think the application is not terminated and will run forever.

The fix is to simply ignore the Cocoa's application termination request
and let the C++ message loop deal with it compeletey. But we had the
side effect that atom-shell would always cancel OS X's shutdown request,
this is also the approach chosen by Chromium.

Fixes #229.
Fixes atom/atom#1864.

atom/browser/atom_application_delegate_mac.mm
atom/browser/browser.cc
atom/browser/browser.h
atom/browser/browser_linux.cc
atom/browser/browser_mac.mm
atom/browser/browser_win.cc

index 2f5519b7ce9b36b4cc91fa876a0ba33f93476fc6..9dfb86565413b533f0b5578e6d383a3ca36418b3 100644 (file)
@@ -31,7 +31,7 @@
   } else {
     // System started termination.
     atom::Browser::Get()->Quit();
-    return NSTerminateLater;
+    return NSTerminateCancel;
   }
 }
 
index bc5afafaec3b1cb027933aa737682b4ee43d00f2..76a269e276272e6e4cc990a8ab1eca00da594cb4 100644 (file)
@@ -107,13 +107,10 @@ void Browser::NotifyAndShutdown() {
 }
 
 void Browser::OnWindowCloseCancelled(NativeWindow* window) {
-  if (is_quiting_) {
+  if (is_quiting_)
     // Once a beforeunload handler has prevented the closing, we think the quit
     // is cancelled too.
     is_quiting_ = false;
-
-    CancelQuit();
-  }
 }
 
 void Browser::OnWindowAllClosed() {
index d8dd38a05ffc9ec2b3019b12dee3125903a73a3a..3a7527fa45131c7959df527b121a1ccb6be416e7 100644 (file)
@@ -91,9 +91,6 @@ class Browser : public WindowListObserver {
   // Send the will-quit message and then shutdown the application.
   void NotifyAndShutdown();
 
-  // Tell the system we have cancelled quiting.
-  void CancelQuit();
-
   bool is_quiting_;
 
  private:
index c8d50a722ecf195fda9ceeecaf67e535c7e53fc0..b85781a76e94af7b03324095719bcfdf64fa4c87 100644 (file)
@@ -32,8 +32,4 @@ std::string Browser::GetExecutableFileProductName() const {
   return "Atom-Shell";
 }
 
-void Browser::CancelQuit() {
-  // No way to cancel quit on Linux.
-}
-
 }  // namespace atom
index 23404edd56ce6b2fb3635ea397419010ceefc1f2..a0ee535faaf7756063ab5b033e2b6b7088bc6796 100644 (file)
@@ -26,10 +26,6 @@ std::string Browser::GetExecutableFileProductName() const {
   return base::SysNSStringToUTF8(version);
 }
 
-void Browser::CancelQuit() {
-  [[AtomApplication sharedApplication] replyToApplicationShouldTerminate:NO];
-}
-
 int Browser::DockBounce(BounceType type) {
   return [[AtomApplication sharedApplication] requestUserAttention:type];
 }
index c0698f8f3637f44d3d06a4b0d514b45f1be54356..a9b82e495af3ef9877c538a0d6833de49d8a21af 100644 (file)
@@ -61,8 +61,4 @@ std::string Browser::GetExecutableFileProductName() const {
   return "Atom-Shell";
 }
 
-void Browser::CancelQuit() {
-  // TODO(zcbenz): Research on how to cancel shutdown in Windows.
-}
-
 }  // namespace atom