(win)
| 112 | // 标记是否为手动检查更新(手动检查时即使是预发布版本也显示弹窗) |
| 113 | let isManualCheck = false |
| 114 | const checkUpdate = (win) => { |
| 115 | // 配置代理 |
| 116 | configureUpdateProxy() |
| 117 | |
| 118 | autoUpdater.autoDownload = false // 自动下载 |
| 119 | autoUpdater.autoInstallOnAppQuit = false // 关闭退出自动安装,必须显式确认安装 |
| 120 | |
| 121 | // 开发模式下模拟更新检测(需要创建 dev-app-update.yml 文件) |
| 122 | // 取消下面的注释来启用开发模式更新测试 |
| 123 | // if (!app.isPackaged) { |
| 124 | // Object.defineProperty(app, 'isPackaged', { |
| 125 | // get() { |
| 126 | // return true |
| 127 | // }, |
| 128 | // }) |
| 129 | // } |
| 130 | |
| 131 | let showUpdateMessageBox = false |
| 132 | let isDownloadingUpdate = false |
| 133 | |
| 134 | // 自动检查走静默下载;手动检查仍由用户确认后再下载。 |
| 135 | const startDownloadUpdate = (): void => { |
| 136 | if (isDownloadingUpdate) return |
| 137 | isDownloadingUpdate = true |
| 138 | autoUpdater |
| 139 | .downloadUpdate() |
| 140 | .then(() => { |
| 141 | console.log('wait for post download operation') |
| 142 | }) |
| 143 | .catch((downloadError) => { |
| 144 | // 下载失败记录到日志,不显示给用户 |
| 145 | logger.error(`[Update] Download update failed: ${downloadError}`) |
| 146 | }) |
| 147 | .finally(() => { |
| 148 | isDownloadingUpdate = false |
| 149 | }) |
| 150 | } |
| 151 | |
| 152 | autoUpdater.on('update-available', (info) => { |
| 153 | // win.webContents.send('show-message', 'electron:发现新版本') |
| 154 | if (showUpdateMessageBox) return |
| 155 | |
| 156 | // 检查是否为预发布版本 |
| 157 | const isPreRelease = isPreReleaseVersion(info.version) |
| 158 | |
| 159 | // 预发布版本仅在手动检查时显示更新弹窗 |
| 160 | if (isPreRelease && !isManualCheck) { |
| 161 | console.log(`[Update] Pre-release version found: ${info.version}, skipping auto-update prompt`) |
| 162 | logger.info( |
| 163 | `[Update] Pre-release version found: ${info.version}, skipping auto-update prompt (manual check required)` |
| 164 | ) |
| 165 | return |
| 166 | } |
| 167 | |
| 168 | if (!isManualCheck) { |
| 169 | logger.info(`[Update] New version ${info.version} found, downloading silently`) |
| 170 | startDownloadUpdate() |
| 171 | return |
no test coverage detected