From 92296bb2dc94028d380b8285210436853b555ad4 Mon Sep 17 00:00:00 2001 From: Waley Date: Tue, 27 Oct 2015 17:10:54 -0400 Subject: [PATCH] makes the app a single instance application --- src/electron/window-manager.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/electron/window-manager.js b/src/electron/window-manager.js index 53036db1cb5..df4556c6f38 100644 --- a/src/electron/window-manager.js +++ b/src/electron/window-manager.js @@ -23,7 +23,7 @@ var RESOURCES = path.resolve(__dirname, '../../'); var DEFAULT_URL = 'file://' + path.join(RESOURCES, 'index.html#connect'); /** - * We want want the Connect dialog window to be special + * We want the Connect dialog window to be special * and for there to ever only be one instance of it * so we'll use scope to essentially make it a Singleton. */ @@ -62,6 +62,23 @@ module.exports.create = function(opts) { 'direct-write': true } }); + + // makes the application a single instance application + // see "app.makeSingleInstance" in https://github.com/atom/electron/blob/master/docs/api/app.md + var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) { + // Someone tried to run a second instance, we should focus our window + if (_window) { + if (_window.isMinimized()) _window.restore(); + _window.focus(); + } + return true; + }); + + if (shouldQuit) { + app.quit(); + return; + } + attachMenu(_window); _window.loadUrl(opts.url);