mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-05-19 12:17:29 +08:00
✨ feat: 应用单例模式
This commit is contained in:
@@ -47,6 +47,23 @@ function initialize() {
|
||||
initializeShortcuts(mainWindow);
|
||||
}
|
||||
|
||||
// 检查是否为第一个实例
|
||||
const isSingleInstance = app.requestSingleInstanceLock();
|
||||
|
||||
if (!isSingleInstance) {
|
||||
app.quit();
|
||||
} else {
|
||||
// 当第二个实例启动时,将焦点转移到第一个实例的窗口
|
||||
app.on('second-instance', () => {
|
||||
if (mainWindow) {
|
||||
if (mainWindow.isMinimized()) {
|
||||
mainWindow.restore();
|
||||
}
|
||||
mainWindow.show();
|
||||
mainWindow.focus();
|
||||
}
|
||||
});
|
||||
|
||||
// 应用程序准备就绪时的处理
|
||||
app.whenReady().then(() => {
|
||||
// 设置应用ID
|
||||
@@ -88,3 +105,4 @@ ipcMain.on('restart', () => {
|
||||
ipcMain.on('get-arch', (event) => {
|
||||
event.returnValue = process.arch;
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user