diff --git a/index.js b/index.js index 8f2a6bcb..d4ce9d0e 100644 --- a/index.js +++ b/index.js @@ -26,6 +26,22 @@ unhandled({ process.env.NODE_OPTIONS = ""; const app = electron.app; +// Prevent window being garbage collected +let mainWindow; +autoUpdater.autoDownload = false; + +if(config.get("options.singleInstanceLock")){ + const gotTheLock = app.requestSingleInstanceLock(); + if (!gotTheLock) app.quit(); + + app.on('second-instance', () => { + if (!mainWindow) return; + if (mainWindow.isMinimized()) mainWindow.restore(); + if (!mainWindow.isVisible()) mainWindow.show(); + mainWindow.focus(); + }); +} + app.commandLine.appendSwitch( "js-flags", // WebAssembly flags @@ -54,10 +70,6 @@ require("electron-debug")({ showDevTools: false //disable automatic devTools on new window }); -// Prevent window being garbage collected -let mainWindow; -autoUpdater.autoDownload = false; - let icon = "assets/youtube-music.png"; if (process.platform == "win32") { icon = "assets/generated/icon.ico"; diff --git a/menu.js b/menu.js index 394f05c7..d630db6b 100644 --- a/menu.js +++ b/menu.js @@ -87,6 +87,19 @@ const mainMenuTemplate = (win) => { config.setMenuOption("options.removeUpgradeButton", item.checked); }, }, + { + label: "Single instance lock", + type: "checkbox", + checked: config.get("options.singleInstanceLock"), + click: (item) => { + config.set("options.singleInstanceLock", item.checked); + if (item.checked && !app.hasSingleInstanceLock()) { + app.requestSingleInstanceLock(); + } else if (!item.checked && app.hasSingleInstanceLock()) { + app.releaseSingleInstanceLock(); + } + }, + }, ...(is.windows() || is.linux() ? [ { @@ -166,14 +179,14 @@ const mainMenuTemplate = (win) => { { label: "Advanced options", submenu: [ - { - label: "Proxy", - type: "checkbox", - checked: !!config.get("options.proxy"), - click: (item) => { - setProxy(item, win); - }, - }, + { + label: "Proxy", + type: "checkbox", + checked: !!config.get("options.proxy"), + click: (item) => { + setProxy(item, win); + }, + }, { label: "Disable hardware acceleration", type: "checkbox",