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) => {