From 7e9e43fa6ac749d965132c64c34062a94651f8b4 Mon Sep 17 00:00:00 2001 From: smartfridge <37928912+smartfrigde@users.noreply.github.com> Date: Sun, 25 Sep 2022 20:31:29 +0200 Subject: [PATCH] Add single-instance --- src/window.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/window.ts b/src/window.ts index b2a24df..c89c8df 100644 --- a/src/window.ts +++ b/src/window.ts @@ -54,7 +54,19 @@ async function doAfterDefiningTheWindow() { } mainWindow.webContents.userAgent = `Mozilla/5.0 (X11; ${osType} ${os.arch()}) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36`; //fake useragent for screenshare to work } + const gotTheLock = app.requestSingleInstanceLock() + if (!gotTheLock) { + app.quit() + } else { + app.on('second-instance', (event, commandLine, workingDirectory) => { + // i love stack overflow + if (mainWindow) { + mainWindow.restore() + mainWindow.focus() + } + }) + } mainWindow.webContents.setWindowOpenHandler(({url}) => { if (url.startsWith("https:" || url.startsWith("http:") || url.startsWith("mailto:"))) { shell.openExternal(url);