()
| 113 | } |
| 114 | // 应用程序事件 |
| 115 | handleAppEvents() { |
| 116 | // 窗口被关闭时 |
| 117 | app.on("window-all-closed", () => { |
| 118 | if (!isMac) app.quit(); |
| 119 | this.mainWindow = null; |
| 120 | this.loadWindow = null; |
| 121 | }); |
| 122 | |
| 123 | // 应用被激活 |
| 124 | app.on("activate", () => { |
| 125 | const allWindows = BrowserWindow.getAllWindows(); |
| 126 | if (allWindows.length) { |
| 127 | allWindows[0].focus(); |
| 128 | } |
| 129 | }); |
| 130 | |
| 131 | // 自定义协议 |
| 132 | app.on("open-url", (_, url) => { |
| 133 | processLog.log("🔗 Received custom protocol URL:", url); |
| 134 | trySendCustomProtocol(url); |
| 135 | }); |
| 136 | |
| 137 | // 退出前 |
| 138 | app.on("before-quit", (event) => { |
| 139 | if (this.isQuit) return; |
| 140 | event.preventDefault(); |
| 141 | this.isQuit = true; |
| 142 | setAppQuitting(); |
| 143 | (async () => { |
| 144 | // 注销全部快捷键 |
| 145 | unregisterShortcuts(); |
| 146 | // 清理媒体集成资源 |
| 147 | shutdownMedia(); |
| 148 | // 关闭任务栏歌词窗口(停止原生 watcher / service) |
| 149 | closeTaskbarLyricWindow(); |
| 150 | // 停止 MPV 服务 |
| 151 | const mpvService = MpvService.getInstance(); |
| 152 | try { |
| 153 | await mpvService.stop(); |
| 154 | processLog.info("MPV 进程已停止"); |
| 155 | } catch (err) { |
| 156 | processLog.error("停止 MPV 进程失败", err); |
| 157 | } finally { |
| 158 | mpvService.terminate(); |
| 159 | processLog.info("MPV 进程已终止"); |
| 160 | } |
| 161 | processLog.info("全部服务已停止,退出应用..."); |
| 162 | app.exit(0); |
| 163 | })(); |
| 164 | }); |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | export default new MainProcess(); |
no test coverage detected