From 8c937fc98bd2d72be8502891450b27c51defacf4 Mon Sep 17 00:00:00 2001 From: Allen Date: Wed, 30 Apr 2025 23:12:02 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A1=AE=E4=BF=9D=E5=8F=AA=E6=9C=89=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E5=AE=9E=E4=BE=8B=E5=9C=A8=E8=BF=90=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main.ts b/src/main.ts index a943908..8092649 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,9 +5,26 @@ import * as http from 'http'; import * as https from 'https'; import { URL } from 'url'; +// 确保只有一个实例在运行 +const gotTheLock = app.requestSingleInstanceLock(); + +if (!gotTheLock) { + app.exit(0); // 使用 exit 而不是 quit,确保立即退出 +} else { + app.on('second-instance', (event, commandLine, workingDirectory) => { + // 当运行第二个实例时,我们应该聚焦到主窗口 + const win = BrowserWindow.getAllWindows()[0]; + if (win) { + win.show(); // 确保窗口显示 + if (win.isMinimized()) win.restore(); + win.focus(); + } + }); +} + // Handle creating/removing shortcuts on Windows when installing/uninstalling. if (started) { - app.quit(); + app.exit(0); // 使用 exit 而不是 quit,确保立即退出 } ipcMain.handle('check-url-available', async (event, rawUrl: string) => {