From 850ecb23dfff0dc06d1fa339bf74865f224da4b7 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Wed, 1 May 2013 13:52:56 -0700 Subject: [PATCH] Atom will auto-update on close if a newer version is on Speakeasy The first call to terminate is canceled so that every window can be closed. On AtomCefClient the OnBeforeClose method is called when a browser is finished closing. Once all windows have finished closing, AtomCefClient calls terminate again, which will terminate the application. Closes #527 --- native/atom_application.mm | 17 +++++++++++++---- native/atom_cef_client.cpp | 2 +- native/atom_cef_client.h | 1 + native/atom_cef_client_mac.mm | 4 ++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/native/atom_application.mm b/native/atom_application.mm index 6a4092665..c831239c3 100644 --- a/native/atom_application.mm +++ b/native/atom_application.mm @@ -278,12 +278,21 @@ } } +// The first call to terminate is canceled so that every window can be closed. +// On AtomCefClient the OnBeforeClose method is called when a browser is +// finished closing. Once all windows have finished closing, AtomCefClient calls +// terminate again, which will terminate the application. - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { - for (NSWindow *window in [self windows]) { - [window performClose:self]; + if (self.windows.count > 0) { + for (NSWindow *window in self.windows) { + [window performClose:self]; + } + return NSTerminateCancel; + } + else { + CefQuitMessageLoop(); + return NSTerminateNow; } - - return NSTerminateCancel; } # pragma mark CefAppProtocol diff --git a/native/atom_cef_client.cpp b/native/atom_cef_client.cpp index 025a7921d..b25cee48e 100644 --- a/native/atom_cef_client.cpp +++ b/native/atom_cef_client.cpp @@ -174,7 +174,7 @@ void AtomCefClient::OnBeforeClose(CefRefPtr browser) { m_Browser = NULL; numberOfOpenBrowsers--; if (numberOfOpenBrowsers == 0) { - CefQuitMessageLoop(); + Terminate(); } } diff --git a/native/atom_cef_client.h b/native/atom_cef_client.h index 83c07ec12..8f93c384c 100644 --- a/native/atom_cef_client.h +++ b/native/atom_cef_client.h @@ -127,6 +127,7 @@ class AtomCefClient : public CefClient, void ShowSaveDialog(int replyId, CefRefPtr browser); CefRefPtr CreateReplyDescriptor(int replyId, int callbackIndex); void Exit(int status); + void Terminate(); void Log(const char *message); void Show(CefRefPtr browser); void ToggleFullScreen(CefRefPtr browser); diff --git a/native/atom_cef_client_mac.mm b/native/atom_cef_client_mac.mm index 72573ebb2..bb7acb242 100644 --- a/native/atom_cef_client_mac.mm +++ b/native/atom_cef_client_mac.mm @@ -159,6 +159,10 @@ void AtomCefClient::Exit(int status) { exit(status); } +void AtomCefClient::Terminate() { + [NSApp terminate:NSApp]; +} + void AtomCefClient::Log(const char *message) { NSLog(@"%s", message); }