MCPcopy Index your code
hub / github.com/ChatLab/ChatLab / checkUpdate

Function checkUpdate

apps/desktop/main/update.ts:114–279  ·  view source on GitHub ↗
(win)

Source from the content-addressed store, hash-verified

112// 标记是否为手动检查更新(手动检查时即使是预发布版本也显示弹窗)
113let isManualCheck = false
114const 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

Callers 2

mainAppEventsMethod · 0.90
update.test.tsFile · 0.85

Calls 14

tFunction · 0.90
closeWorkerAsyncFunction · 0.90
configureUpdateProxyFunction · 0.85
isPreReleaseVersionFunction · 0.85
startDownloadUpdateFunction · 0.85
setTimeoutFunction · 0.85
isNetworkErrorFunction · 0.85
switchToGitHubFunction · 0.85
resetToDefaultSourceFunction · 0.85
onMethod · 0.80
quitAndInstallMethod · 0.80
checkForUpdatesMethod · 0.80

Tested by

no test coverage detected