()
| 390 | |
| 391 | // 主窗口事件 |
| 392 | mainWindowEvents() { |
| 393 | if (!this.mainWindow) { |
| 394 | return |
| 395 | } |
| 396 | this.mainWindow.webContents.on('did-finish-load', () => { |
| 397 | setTimeout(() => { |
| 398 | if (this.mainWindow) { |
| 399 | this.mainWindow.webContents.send('app-started') |
| 400 | } |
| 401 | }, 500) |
| 402 | }) |
| 403 | |
| 404 | this.mainWindow.on('maximize', () => { |
| 405 | this.mainWindow?.webContents.send('windowState', true) |
| 406 | }) |
| 407 | |
| 408 | this.mainWindow.on('unmaximize', () => { |
| 409 | this.mainWindow?.webContents.send('windowState', false) |
| 410 | }) |
| 411 | |
| 412 | // 窗口关闭 |
| 413 | this.mainWindow.on('close', (event) => { |
| 414 | if (platform.isMacOS) { |
| 415 | // macOS: 只有明确退出时才真正关闭,否则只隐藏窗口(符合 macOS 用户习惯) |
| 416 | if (!appWithQuitFlag.isQuiting) { |
| 417 | event.preventDefault() |
| 418 | this.mainWindow?.hide() |
| 419 | } |
| 420 | } |
| 421 | // Windows/Linux: 不阻止关闭,正常触发 window-all-closed → app.quit() → cleanup() |
| 422 | }) |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | // 捕获未捕获的异常与未处理的 Promise 拒绝,落盘到 logs/app.log 便于排查 |
no test coverage detected