feat(update): 检查更新优先静态 latest.json,避免用户撞 GitHub API 限流

- 客户端优先下载 releases/latest/download/latest.json,再回退 REST API
- 成功结果写入磁盘缓存,限流/断网时可 stale 回退
- 静默检查增加节流;限流文案改为用户无需配置 Token
- CI 与 build-release 发版时生成 latest.json 清单
- 补充静态清单/缓存/节流单测与生成脚本测试
This commit is contained in:
Syngnat
2026-07-09 12:35:12 +08:00
parent 566339f09f
commit 3beab030f4
14 changed files with 873 additions and 11 deletions

View File

@@ -158,17 +158,19 @@ func (a *App) localizedUpdateError(err error) string {
}
func (a *App) CheckForUpdates() connection.QueryResult {
return a.checkForUpdates(true)
// 用户手动检查强制走网络静态清单优先API 回退)
return a.checkForUpdates(true, true)
}
func (a *App) CheckForUpdatesSilently() connection.QueryResult {
return a.checkForUpdates(false)
// 静默检查:允许节流,优先磁盘/短时缓存,避免启动刷爆网络
return a.checkForUpdates(false, false)
}
func (a *App) checkForUpdates(logFailure bool) connection.QueryResult {
func (a *App) checkForUpdates(logFailure bool, forceNetwork bool) connection.QueryResult {
a.ensurePersistedGlobalProxyRuntime()
channel := a.currentUpdateChannel()
info, err := fetchLatestUpdateInfo(channel)
info, err := fetchLatestUpdateInfoWithOptions(channel, forceNetwork)
if err != nil {
if logFailure {
updateLogCheckError(err)
@@ -456,10 +458,15 @@ func (a *App) downloadAndStageUpdate(info UpdateInfo) connection.QueryResult {
}
func fetchLatestUpdateInfo(channel updateChannel) (UpdateInfo, error) {
return fetchLatestUpdateInfoWithOptions(channel, true)
}
func fetchLatestUpdateInfoWithOptions(channel updateChannel, forceNetwork bool) (UpdateInfo, error) {
if channel != updateChannelDev {
channel = updateChannelLatest
}
release, err := fetchReleaseForChannel(channel)
// 优先静态 latest.json不占 api.github.com 配额)→ GitHub API → 磁盘缓存
release, err := fetchReleaseForChannelPreferringStatic(channel, forceNetwork)
if err != nil {
return UpdateInfo{}, err
}