* 自动检查并下载更新
()
| 116 | * 自动检查并下载更新 |
| 117 | */ |
| 118 | private async autoCheckAndDownload(): Promise<void> { |
| 119 | try { |
| 120 | console.log('[Updater] 开始自动检查更新...') |
| 121 | |
| 122 | // 如果已经下载过更新,不再重复下载 |
| 123 | if (this.downloadedUpdateInfo) { |
| 124 | console.log('[Updater] 已有下载的更新,跳过检查') |
| 125 | return |
| 126 | } |
| 127 | |
| 128 | const result = await this.checkUpdate() |
| 129 | |
| 130 | if (result.hasUpdate && result.updateInfo) { |
| 131 | console.log('[Updater] 发现新版本,开始自动下载...', result.updateInfo) |
| 132 | |
| 133 | // 通知渲染进程开始下载 |
| 134 | this.mainWindow?.webContents.send('update-download-start', { |
| 135 | version: result.updateInfo.version |
| 136 | }) |
| 137 | |
| 138 | // 执行下载 |
| 139 | const downloadResult = await this.downloadAndExtractUpdate(result.updateInfo) |
| 140 | |
| 141 | if (downloadResult.success) { |
| 142 | this.downloadedUpdateInfo = result.updateInfo |
| 143 | this.downloadedUpdatePath = downloadResult.extractPath |
| 144 | |
| 145 | // 通知渲染进程下载完成 |
| 146 | this.mainWindow?.webContents.send('update-downloaded', { |
| 147 | version: result.updateInfo.version, |
| 148 | changelog: result.updateInfo.changelog |
| 149 | }) |
| 150 | |
| 151 | console.log('[Updater] 更新下载完成,等待用户安装') |
| 152 | |
| 153 | // 弹出更新窗口 |
| 154 | this.createUpdateWindow() |
| 155 | } else { |
| 156 | console.error('[Updater] 更新下载失败:', downloadResult.error) |
| 157 | this.mainWindow?.webContents.send('update-download-failed', { |
| 158 | error: downloadResult.error instanceof Error ? downloadResult.error.message : '下载失败' |
| 159 | }) |
| 160 | } |
| 161 | } |
| 162 | } catch (error) { |
| 163 | console.error('[Updater] 自动检查更新失败:', error) |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * 获取下载状态 |
no test coverage detected