From 03b19f2539fede4c1f3f5ef63de589bb2b2fde53 Mon Sep 17 00:00:00 2001 From: Marcelo van Kampen Date: Sat, 8 Jan 2022 19:55:52 -0300 Subject: [PATCH] set app window to be single instance --- src/main.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main.js b/src/main.js index 765c159..c19ab89 100644 --- a/src/main.js +++ b/src/main.js @@ -37,6 +37,19 @@ isDev = (isDev) || process.env.DEBUG_SCRATCHJR; const { app, dialog, BrowserWindow, BrowserView, ipcMain, Menu } = require('electron'); +var myWindow = null; + +var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) { + // Someone tried to run a second instance, we should focus our window. + if (myWindow) { + if (myWindow.isMinimized()) myWindow.restore(); + myWindow.focus(); + } +}); + +if (shouldQuit) { + app.quit(); +} /* eslint-enable import/extensions */ // --> ON