From 569b3aed5bb1513d329971e409e4f39f563566e1 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 16 Jan 2019 10:49:09 +0100 Subject: [PATCH 1/2] MOBILE-2829 electron: Use requestSingleInstanceLock function --- desktop/electron.js | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/desktop/electron.js b/desktop/electron.js index d4a7bdbfa..c7f1359a9 100644 --- a/desktop/electron.js +++ b/desktop/electron.js @@ -70,6 +70,24 @@ function createWindow() { mainWindow.webContents.setUserAgent(mainWindow.webContents.getUserAgent() + ' ' + userAgent); } +// Make sure that only a single instance of the app is running. +var gotTheLock = app.requestSingleInstanceLock(); + +if (!gotTheLock) { + // It's not the main instance of the app, kill it. + app.exit(); + return; +} + +app.on('second-instance', (event, commandLine, workingDirectory) => { + // Another instance was launched. If it was launched with a URL, it should be in the second param. + if (commandLine && commandLine[1]) { + appLaunched(commandLine[1]); + } else { + focusApp(); + } +}); + // This method will be called when Electron has finished initialization and is ready to create browser windows. // Some APIs can only be used after this event occurs. app.on('ready', function() { @@ -122,23 +140,6 @@ fs.readFile(path.join(__dirname, 'config.json'), 'utf8', (err, data) => { } }); -// Make sure that only a single instance of the app is running. -var shouldQuit = app.makeSingleInstance((argv, workingDirectory) => { - // Another instance was launched. If it was launched with a URL, it should be in the second param. - if (argv && argv[1]) { - appLaunched(argv[1]); - } else { - focusApp(); - } -}); - -// For some reason, shouldQuit is always true in signed Mac apps so we should ingore it. -if (shouldQuit && os.platform().indexOf('darwin') == -1) { - // It's not the main instance of the app, kill it. - app.exit(); - return; -} - // Listen for open-url events (Mac OS only). app.on('open-url', (event, url) => { event.preventDefault(); From cef8cfabd30a7b110ca49f28486eedae9d9f7d4e Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 16 Jan 2019 12:31:18 +0100 Subject: [PATCH 2/2] MOBILE-2829 desktop: Update electron version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c5361461b..6116e057b 100644 --- a/package.json +++ b/package.json @@ -206,7 +206,7 @@ } ], "compression": "maximum", - "electronVersion": "2.0.4", + "electronVersion": "4.0.1", "mac": { "category": "public.app-category.education", "icon": "resources/desktop/icon.icns",