From 40257cf93e153a84a94f888aea3225788fbb9d3a Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Mon, 12 Nov 2018 00:26:03 +0900 Subject: [PATCH] Migrate to new makeSingleInstance method --- src/main.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main.js b/src/main.js index 93345a3d..52659c54 100644 --- a/src/main.js +++ b/src/main.js @@ -177,13 +177,18 @@ const trayImages = (() => { })(); // If there is already an instance, activate the window in the existing instace and quit this one -if (app.makeSingleInstance((commandLine/*, workingDirectory*/) => { +const gotTheLock = app.requestSingleInstanceLock(); +if (!gotTheLock) { + app.exit(); + global.willAppQuit = true; +} +app.on('second-instance', (event, secondArgv) => { // Protocol handler for win32 // argv: An array of the second instance’s (command line / deep linked) arguments if (process.platform === 'win32') { // Keep only command line / deep linked arguments - if (Array.isArray(commandLine.slice(1)) && commandLine.slice(1).length > 0) { - setDeeplinkingUrl(commandLine.slice(1)[0]); + if (Array.isArray(secondArgv.slice(1)) && secondArgv.slice(1).length > 0) { + setDeeplinkingUrl(secondArgv.slice(1)[0]); mainWindow.webContents.send('protocol-deeplink', deeplinkingUrl); } } @@ -196,9 +201,7 @@ if (app.makeSingleInstance((commandLine/*, workingDirectory*/) => { mainWindow.show(); } } -})) { - app.exit(); -} +}); function shouldShowTrayIcon() { if (process.platform === 'win32') {