()
| 8 | * @returns 如果当前实例获得了锁,返回 true;否则返回 false |
| 9 | */ |
| 10 | export const initSingleLock = (): boolean => { |
| 11 | const gotTheLock = app.requestSingleInstanceLock(); |
| 12 | // 如果未获得锁,退出当前实例 |
| 13 | if (!gotTheLock) { |
| 14 | app.quit(); |
| 15 | systemLog.warn("❌ 已有一个实例正在运行"); |
| 16 | return false; |
| 17 | } |
| 18 | // 当第二个实例启动时触发 |
| 19 | else { |
| 20 | app.on("second-instance", (_, commandLine) => { |
| 21 | if (!processProtocolFromCommand(commandLine)) { |
| 22 | systemLog.warn("❌ 第二个实例将要启动"); |
| 23 | } else { |
| 24 | systemLog.info("🚀 第二个实例将要启动,通过 Custom Protocol"); |
| 25 | } |
| 26 | mainWindow.getWin()?.show(); |
| 27 | }); |
| 28 | } |
| 29 | return true; |
| 30 | }; |
no test coverage detected