From 663adc9935527f1ac5700566cca5f3034f2e2240 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7?= <308487730@qq.com> Date: Tue, 9 Nov 2021 11:12:32 +0800 Subject: [PATCH] feat: imporve main --- src/main/index.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/index.ts b/src/main/index.ts index d150a54..df1a85c 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,6 +1,13 @@ import { join } from 'path' import { app, BrowserWindow } from 'electron' +app.disableHardwareAcceleration() + +if (!app.requestSingleInstanceLock()) { + app.quit() + process.exit(0) +} + let win: BrowserWindow | null = null async function mainWin() { @@ -23,7 +30,18 @@ async function mainWin() { } app.whenReady().then(mainWin) + 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() + } })