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.
This commit is contained in:
Cheng Zhao 2014-04-15 00:02:33 +08:00
parent 6f4aed83f0
commit b994ae8174
6 changed files with 2 additions and 20 deletions

View file

@ -31,7 +31,7 @@
} else { } else {
// System started termination. // System started termination.
atom::Browser::Get()->Quit(); atom::Browser::Get()->Quit();
return NSTerminateLater; return NSTerminateCancel;
} }
} }

View file

@ -107,13 +107,10 @@ void Browser::NotifyAndShutdown() {
} }
void Browser::OnWindowCloseCancelled(NativeWindow* window) { void Browser::OnWindowCloseCancelled(NativeWindow* window) {
if (is_quiting_) { if (is_quiting_)
// Once a beforeunload handler has prevented the closing, we think the quit // Once a beforeunload handler has prevented the closing, we think the quit
// is cancelled too. // is cancelled too.
is_quiting_ = false; is_quiting_ = false;
CancelQuit();
}
} }
void Browser::OnWindowAllClosed() { void Browser::OnWindowAllClosed() {

View file

@ -91,9 +91,6 @@ class Browser : public WindowListObserver {
// Send the will-quit message and then shutdown the application. // Send the will-quit message and then shutdown the application.
void NotifyAndShutdown(); void NotifyAndShutdown();
// Tell the system we have cancelled quiting.
void CancelQuit();
bool is_quiting_; bool is_quiting_;
private: private:

View file

@ -32,8 +32,4 @@ std::string Browser::GetExecutableFileProductName() const {
return "Atom-Shell"; return "Atom-Shell";
} }
void Browser::CancelQuit() {
// No way to cancel quit on Linux.
}
} // namespace atom } // namespace atom

View file

@ -26,10 +26,6 @@ std::string Browser::GetExecutableFileProductName() const {
return base::SysNSStringToUTF8(version); return base::SysNSStringToUTF8(version);
} }
void Browser::CancelQuit() {
[[AtomApplication sharedApplication] replyToApplicationShouldTerminate:NO];
}
int Browser::DockBounce(BounceType type) { int Browser::DockBounce(BounceType type) {
return [[AtomApplication sharedApplication] requestUserAttention:type]; return [[AtomApplication sharedApplication] requestUserAttention:type];
} }

View file

@ -61,8 +61,4 @@ std::string Browser::GetExecutableFileProductName() const {
return "Atom-Shell"; return "Atom-Shell";
} }
void Browser::CancelQuit() {
// TODO(zcbenz): Research on how to cancel shutdown in Windows.
}
} // namespace atom } // namespace atom