only allow single instance of app (#68)

This commit is contained in:
Lynn authored and GitHub committed 2017-04-28 09:00:16 -07:00
1 parent 5d3377ec02
commit f8037ffd66
1 file changed
+17 -2
+17 -2
View File
@@ -8,7 +8,6 @@ const squirrelStartup = require('electron-squirrel-startup');
const { getConfigField } = require('./config.js');
const { isMac, isDevEnv } = require('./utils/misc.js');
// exit early for squirrel installer
if (squirrelStartup) {
return;
@@ -19,9 +18,25 @@ require('./mainApiMgr.js');
// monitor memory of main process
require('./memoryMonitor.js');
const windowMgr = require('./windowMgr.js');
// only allow a single instance of app.
const shouldQuit = app.makeSingleInstance(() => {
// Someone tried to run a second instance, we should focus our window.
let mainWin = windowMgr.getMainWindow();
if (mainWin) {
if (mainWin.isMinimized()) {
mainWin.restore();
}
mainWin.focus();
}
});
// quit if another instance is already running
if (shouldQuit) {
app.quit();
}
/**
* This method will be called when Electron has finished
* initialization and is ready to create browser windows.