From b994ae8174837b0accc3bc1d4655283eb461ec9a Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Tue, 15 Apr 2014 00:02:33 +0800 Subject: [PATCH] mac: Always cancel application termination. 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 | 2 +- atom/browser/browser.cc | 5 +---- atom/browser/browser.h | 3 --- atom/browser/browser_linux.cc | 4 ---- atom/browser/browser_mac.mm | 4 ---- atom/browser/browser_win.cc | 4 ---- 6 files changed, 2 insertions(+), 20 deletions(-) diff --git a/atom/browser/atom_application_delegate_mac.mm b/atom/browser/atom_application_delegate_mac.mm index 2f5519b7..9dfb8656 100644 --- a/atom/browser/atom_application_delegate_mac.mm +++ b/atom/browser/atom_application_delegate_mac.mm @@ -31,7 +31,7 @@ } else { // System started termination. atom::Browser::Get()->Quit(); - return NSTerminateLater; + return NSTerminateCancel; } } diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index bc5afafa..76a269e2 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -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() { diff --git a/atom/browser/browser.h b/atom/browser/browser.h index d8dd38a0..3a7527fa 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -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: diff --git a/atom/browser/browser_linux.cc b/atom/browser/browser_linux.cc index c8d50a72..b85781a7 100644 --- a/atom/browser/browser_linux.cc +++ b/atom/browser/browser_linux.cc @@ -32,8 +32,4 @@ std::string Browser::GetExecutableFileProductName() const { return "Atom-Shell"; } -void Browser::CancelQuit() { - // No way to cancel quit on Linux. -} - } // namespace atom diff --git a/atom/browser/browser_mac.mm b/atom/browser/browser_mac.mm index 23404edd..a0ee535f 100644 --- a/atom/browser/browser_mac.mm +++ b/atom/browser/browser_mac.mm @@ -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]; } diff --git a/atom/browser/browser_win.cc b/atom/browser/browser_win.cc index c0698f8f..a9b82e49 100644 --- a/atom/browser/browser_win.cc +++ b/atom/browser/browser_win.cc @@ -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 -- 2.43.0