auto browser = base::Unretained(Browser::Get());
return mate::ObjectTemplateBuilder(isolate)
.SetMethod("quit", base::Bind(&Browser::Quit, browser))
+ .SetMethod("exit", base::Bind(&Browser::Exit, browser))
.SetMethod("focus", base::Bind(&Browser::Focus, browser))
.SetMethod("getVersion", base::Bind(&Browser::GetVersion, browser))
.SetMethod("setVersion", base::Bind(&Browser::SetVersion, browser))
# Be compatible with old API.
app.once 'ready', -> @emit 'finish-launching'
app.terminate = app.quit
-app.exit = process.exit
app.getHomeDir = -> @getPath 'home'
app.getDataPath = -> @getPath 'userData'
app.setDataPath = (path) -> @setPath 'userData', path
AtomBrowserMainParts::AtomBrowserMainParts()
: fake_browser_process_(new BrowserProcess),
+ exit_code_(nullptr),
browser_(new Browser),
node_bindings_(NodeBindings::Create(true)),
atom_bindings_(new AtomBindings),
return self_;
}
+bool AtomBrowserMainParts::SetExitCode(int code) {
+ if (!exit_code_)
+ return false;
+
+ *exit_code_ = code;
+ return true;
+}
+
void AtomBrowserMainParts::RegisterDestructionCallback(
const base::Closure& callback) {
destruction_callbacks_.push_back(callback);
#endif
}
+bool AtomBrowserMainParts::MainMessageLoopRun(int* result_code) {
+ exit_code_ = result_code;
+ return brightray::BrowserMainParts::MainMessageLoopRun(result_code);
+}
+
void AtomBrowserMainParts::PostMainMessageLoopStart() {
brightray::BrowserMainParts::PostMainMessageLoopStart();
#if defined(OS_POSIX)
static AtomBrowserMainParts* Get();
+ // Sets the exit code, will fail if the the message loop is not ready.
+ bool SetExitCode(int code);
+
// Register a callback that should be destroyed before JavaScript environment
// gets destroyed.
void RegisterDestructionCallback(const base::Closure& callback);
void PreEarlyInitialization() override;
void PostEarlyInitialization() override;
void PreMainMessageLoopRun() override;
+ bool MainMessageLoopRun(int* result_code) override;
void PostMainMessageLoopStart() override;
void PostMainMessageLoopRun() override;
#if defined(OS_MACOSX)
// with a task runner that will post all work to main loop.
scoped_refptr<BridgeTaskRunner> bridge_task_runner_;
+ // Pointer to exit code.
+ int* exit_code_;
+
scoped_ptr<Browser> browser_;
scoped_ptr<JavascriptEnvironment> js_env_;
scoped_ptr<NodeBindings> node_bindings_;
#include <string>
#include "atom/browser/atom_browser_main_parts.h"
+#include "atom/browser/native_window.h"
#include "atom/browser/window_list.h"
#include "base/message_loop/message_loop.h"
#include "content/public/browser/client_certificate_delegate.h"
window_list->CloseAllWindows();
}
+void Browser::Exit(int code) {
+ if (!AtomBrowserMainParts::Get()->SetExitCode(code)) {
+ // Message loop is not ready, quit directly.
+ exit(code);
+ } else {
+ // Prepare to quit when all windows have been closed..
+ is_quiting_ = true;
+
+ // Must destroy windows before quitting, otherwise bad things can happen.
+ atom::WindowList* window_list = atom::WindowList::GetInstance();
+ if (window_list->size() == 0) {
+ NotifyAndShutdown();
+ } else {
+ // Unlike Quit(), we do not ask to close window, but destroy the window
+ // without asking.
+ for (NativeWindow* window : *window_list)
+ window->CloseContents(nullptr); // e.g. Destroy()
+ }
+ }
+}
+
void Browser::Shutdown() {
if (is_shutdown_)
return;
// Try to close all windows and quit the application.
void Quit();
+ // Exit the application immediately and set exit code.
+ void Exit(int code);
+
// Cleanup everything and shutdown the application gracefully.
void Shutdown();
app.on 'quit', ->
process.emit 'exit'
+# Map process.exit to app.exit, which quits gracefully.
+process.exit = app.exit
+
# Load the RPC server.
require './rpc-server'
correctly executed. It is possible that a window cancels the quitting by
returning `false` in the `beforeunload` event handler.
+### `app.exit(exitCode)`
+
+* `exitCode` Integer
+
+Exits immediately with `exitCode`.
+
+All windows will be closed immediately without asking user and the `before-quit`
+and `will-quit` events will not be emitted.
+
### `app.getAppPath()`
Returns the current application directory.