🛴 只能启动一个实例

This commit is contained in:
hunlongyu
2020-05-07 23:17:37 +08:00
parent 5c28cf19ed
commit bd85987e72
2 changed files with 21 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "zy",
"version": "0.9.27",
"version": "0.9.28",
"private": true,
"author": {
"name": "Hunlongyu",

View File

@@ -114,12 +114,26 @@ ipcMain.on('miniOpacity', (e, arg) => {
mini.setOpacity(arg)
})
app.on('ready', async () => {
if (!process.env.WEBPACK_DEV_SERVER_URL) {
createProtocol('app')
}
createWindow()
})
const gotTheLock = app.requestSingleInstanceLock()
if (!gotTheLock) {
app.quit()
} else {
app.on('second-instance', (event, commandLine, workingDirectory) => {
// 当运行第二个实例时,将会聚焦到win这个窗口
if (win) {
if (win.isMinimized()) win.restore()
win.focus()
}
})
// 创建 win, 加载应用的其余部分, etc...
app.on('ready', () => {
if (!process.env.WEBPACK_DEV_SERVER_URL) {
createProtocol('app')
}
createWindow()
})
}
// Exit cleanly on request from parent process in development mode.
if (isDevelopment) {