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); }