Shutdown gracefully, fixes #227.

This commit is contained in:
Cheng Zhao 2014-04-10 15:22:17 +08:00
parent 538bd1116d
commit f0d9ee4ca9
5 changed files with 14 additions and 23 deletions

View file

@ -8,6 +8,7 @@
#include "atom/browser/atom_browser_main_parts.h"
#include "atom/browser/window_list.h"
#include "base/message_loop/message_loop.h"
namespace atom {
@ -30,11 +31,16 @@ void Browser::Quit() {
atom::WindowList* window_list = atom::WindowList::GetInstance();
if (window_list->size() == 0)
NotifyAndTerminate();
NotifyAndShutdown();
window_list->CloseAllWindows();
}
void Browser::Shutdown() {
is_quiting_ = true;
base::MessageLoop::current()->Quit();
}
std::string Browser::GetVersion() const {
if (version_override_.empty()) {
std::string version = GetExecutableFileVersion();
@ -88,7 +94,7 @@ void Browser::DidFinishLaunching() {
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnFinishLaunching());
}
void Browser::NotifyAndTerminate() {
void Browser::NotifyAndShutdown() {
bool prevent_default = false;
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillQuit(&prevent_default));
@ -97,7 +103,7 @@ void Browser::NotifyAndTerminate() {
return;
}
Terminate();
Shutdown();
}
void Browser::OnWindowCloseCancelled(NativeWindow* window) {
@ -112,7 +118,7 @@ void Browser::OnWindowCloseCancelled(NativeWindow* window) {
void Browser::OnWindowAllClosed() {
if (is_quiting_)
NotifyAndTerminate();
NotifyAndShutdown();
else
FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWindowAllClosed());
}

View file

@ -26,8 +26,8 @@ class Browser : public WindowListObserver {
// Try to close all windows and quit the application.
void Quit();
// Quit the application immediately without cleanup work.
void Terminate();
// Cleanup everything and shutdown the application gracefully.
void Shutdown();
// Focus the application.
void Focus();
@ -88,8 +88,8 @@ class Browser : public WindowListObserver {
// Returns the name of application bundle or executable file.
std::string GetExecutableFileProductName() const;
// Send the will-quit message and then terminate the application.
void NotifyAndTerminate();
// Send the will-quit message and then shutdown the application.
void NotifyAndShutdown();
// Tell the system we have cancelled quiting.
void CancelQuit();

View file

@ -12,11 +12,6 @@
namespace atom {
void Browser::Terminate() {
is_quiting_ = true;
exit(0);
}
void Browser::Focus() {
// Focus on the first visible window.
WindowList* list = WindowList::GetInstance();

View file

@ -10,11 +10,6 @@
namespace atom {
void Browser::Terminate() {
is_quiting_ = true;
[[AtomApplication sharedApplication] terminate:nil];
}
void Browser::Focus() {
[[AtomApplication sharedApplication] activateIgnoringOtherApps:YES];
}

View file

@ -33,11 +33,6 @@ BOOL CALLBACK WindowsEnumerationHandler(HWND hwnd, LPARAM param) {
} // namespace
void Browser::Terminate() {
is_quiting_ = true;
PostQuitMessage(0);
}
void Browser::Focus() {
// On Windows we just focus on the first window found for this process.
DWORD pid = GetCurrentProcessId();