()
| 50 | } |
| 51 | |
| 52 | export function setupIpcHandlers(): void { |
| 53 | // 更新相关的IPC处理程序 |
| 54 | ipcMain.handle('check-for-updates', async () => { |
| 55 | try { |
| 56 | console.log('IPC: 开始检查更新') |
| 57 | |
| 58 | // 在开发环境中,如果没有强制配置,给出明确的提示 |
| 59 | if (is.dev && !autoUpdater.forceDevUpdateConfig) { |
| 60 | console.log('开发环境中跳过更新检查,需要设置 forceDevUpdateConfig') |
| 61 | throw new Error('开发环境中的更新检查已被跳过') |
| 62 | } |
| 63 | |
| 64 | const result = await autoUpdater.checkForUpdates() |
| 65 | console.log('IPC: 更新检查完成', result) |
| 66 | return result |
| 67 | } catch (error) { |
| 68 | console.error('IPC: Check for updates error:', error) |
| 69 | // 确保错误被正确传递到渲染进程 |
| 70 | throw error |
| 71 | } |
| 72 | }) |
| 73 | |
| 74 | ipcMain.handle('download-update', async () => { |
| 75 | try { |
| 76 | console.log('IPC: 开始下载更新') |
| 77 | const result = await autoUpdater.downloadUpdate() |
| 78 | console.log('IPC: 更新下载开始', result) |
| 79 | return result |
| 80 | } catch (error) { |
| 81 | console.error('IPC: Download update error:', error) |
| 82 | throw error |
| 83 | } |
| 84 | }) |
| 85 | |
| 86 | ipcMain.handle('quit-and-install', () => { |
| 87 | console.log('IPC: 退出并安装更新') |
| 88 | autoUpdater.quitAndInstall() |
| 89 | }) |
| 90 | |
| 91 | ipcMain.handle('get-app-version', () => { |
| 92 | const version = app.getVersion() |
| 93 | console.log('IPC: 获取应用版本', version) |
| 94 | return version |
| 95 | }) |
| 96 | |
| 97 | // IPC test |
| 98 | ipcMain.on('ping', () => console.log('pong')) |
| 99 | |
| 100 | // 窗口控制IPC处理程序 |
| 101 | ipcMain.handle('window-minimize', (event) => { |
| 102 | const window = BrowserWindow.fromWebContents(event.sender) |
| 103 | if (window) window.minimize() |
| 104 | }) |
| 105 | |
| 106 | ipcMain.handle('window-maximize', (event) => { |
| 107 | const window = BrowserWindow.fromWebContents(event.sender) |
| 108 | if (window) { |
| 109 | if (window.isMaximized()) { |
no test coverage detected