确保只有一个实例在运行
This commit is contained in:
parent
950d589f0f
commit
8c937fc98b
19
src/main.ts
19
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) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user