diff --git a/src/main/index.ts b/src/main/index.ts index d832da2..4167511 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -2,6 +2,16 @@ import path from 'path' import { app, BrowserWindow } from 'electron' import { register } from './communication' +/** + * Main Process some code reference https://github.com/cawa-93/vite-electron-builder + */ +app.disableHardwareAcceleration() + +if (!app.requestSingleInstanceLock()) { + app.quit() + process.exit(0) +} + let win: BrowserWindow | null = null function bootstrap() { @@ -27,5 +37,26 @@ app.whenReady().then(bootstrap) app.on('window-all-closed', () => { win = null - app.quit() + if (process.platform !== 'darwin') { + app.quit() + } }) + +app.on('second-instance', () => { + if (win) { + // someone tried to run a second instance, we should focus our window. + if (win.isMinimized()) win.restore() + win.focus() + } +}) + +// auto update +if (app.isPackaged) { + app.whenReady() + .then(() => import('electron-updater')) + .then(({ autoUpdater }) => autoUpdater.checkForUpdatesAndNotify()) + .catch((e) => + // maybe you need to record some log files. + console.error('Failed check update:', e) + ) +}