From b176bd756c5abab0dc524c954d4479116545b3d9 Mon Sep 17 00:00:00 2001 From: lilia Date: Thu, 30 Mar 2017 16:33:39 -0700 Subject: [PATCH] Ensure app is single-instance Remove some comments. // FREEBIE --- main.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 6108de7b4..76d6da7bc 100644 --- a/main.js +++ b/main.js @@ -1,9 +1,6 @@ const electron = require('electron') -// Module to control application life. const app = electron.app -// Module to create native browser window. const BrowserWindow = electron.BrowserWindow - const path = require('path') const url = require('url') const autoUpdater = require('electron-updater').autoUpdater @@ -11,6 +8,20 @@ const autoUpdaterInterval = 60 * 60 * 1000; app.setAppUserModelId('org.whispersystems.signal-desktop') +var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) { + // Someone tried to run a second instance, we should focus our window + if (mainWindow) { + if (mainWindow.isMinimized()) mainWindow.restore(); + mainWindow.focus(); + } + return true; +}); + +if (shouldQuit) { + app.quit(); + return; +} + // Keep a global reference of the window object, if you don't, the window will // be closed automatically when the JavaScript object is garbage collected. let mainWindow