diff --git a/src/main/index.ts b/src/main/index.ts index 868fd372..c2c0f7d2 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -7,6 +7,11 @@ import { registerZoomShortcut } from './shortcut' import { updateUserDataPath } from './utils/upgrade' import { createMainWindow } from './window' +// Check for single instance lock +if (!app.requestSingleInstanceLock()) { + app.quit() +} + // 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. @@ -42,6 +47,15 @@ app.whenReady().then(async () => { } }) +// Listen for second instance +app.on('second-instance', () => { + const mainWindow = BrowserWindow.getAllWindows()[0] + if (mainWindow) { + mainWindow.isMinimized() && mainWindow.restore() + mainWindow.focus() + } +}) + // Quit when all windows are closed, except on macOS. There, it's common // for applications and their menu bar to stay active until the user quits // explicitly with Cmd + Q.