diff --git a/electron/index.cjs b/electron/index.cjs index 9374fb8..c1e6949 100644 --- a/electron/index.cjs +++ b/electron/index.cjs @@ -1,8 +1,10 @@ const path = require('path'); -const { app, BrowserWindow, Tray, Menu } = require('electron'); +const {dialog, app, BrowserWindow, Tray, Menu } = require('electron'); const isDev = require('electron-is-dev'); const { autoUpdater } = require('electron-updater'); +let win = null; +const instanceLock = app.requestSingleInstanceLock(); if (require('electron-squirrel-startup')) app.quit(); @@ -17,7 +19,7 @@ function createWindow() { } autoUpdater.checkForUpdatesAndNotify(); - const win = new BrowserWindow({ + win = new BrowserWindow({ autoHideMenuBar: true, show: false, icon: iconPath, @@ -73,20 +75,35 @@ const createTray = (window) => { return tray; }; -app.whenReady().then(createWindow); - app.on('window-all-closed', () => { if (process.platform !== 'darwin') { app.quit(); } }); -app.on('activate', () => { - if (BrowserWindow.getAllWindows().length === 0) { - createWindow(); - } +process.on('uncaughtException', (error) => { + // Perform any necessary cleanup tasks here + dialog.showErrorBox('An error occurred', error.stack); + + // Exit the app + process.exit(1); }); +if (!instanceLock) { + app.quit() +} else { + app.on('second-instance', (event, commandLine, workingDirectory) => { + if (win) { + if (win.isMinimized()) win.restore() + win.focus() + } + }) + + app.whenReady().then(() => { + win = createWindow() + }) +} + const createServer = () => { // Dependencies const http = require('http');