🎨 自动下载更新包时在状态栏显示下载进度 Fix https://github.com/siyuan-note/siyuan/issues/6763

This commit is contained in:
Liang Ding 2022-12-02 11:27:41 +08:00
parent 457e96929c
commit 47063f4afc
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
7 changed files with 16 additions and 15 deletions

View file

@ -138,12 +138,12 @@ func getUpdatePkg() (downloadPkgURLs []string, checksum string, err error) {
}
pkg := "siyuan-" + ver + "-" + suffix
url := "https://github.com/siyuan-note/siyuan/releases/download/v" + ver + "/" + pkg
downloadPkgURLs = append(downloadPkgURLs, url)
url = "https://ghproxy.com/" + url
downloadPkgURLs = append(downloadPkgURLs, url)
url = "https://release.b3log.org/siyuan/" + pkg
downloadPkgURLs = append(downloadPkgURLs, url)
b3logURL := "https://release.b3log.org/siyuan/" + pkg
downloadPkgURLs = append(downloadPkgURLs, b3logURL)
githubURL := "https://github.com/siyuan-note/siyuan/releases/download/v" + ver + "/" + pkg
ghproxyURL := "https://ghproxy.com/" + githubURL
downloadPkgURLs = append(downloadPkgURLs, ghproxyURL)
downloadPkgURLs = append(downloadPkgURLs, githubURL)
checksums := result["checksums"].(map[string]interface{})
checksum = checksums[pkg].(string)
@ -173,9 +173,11 @@ func downloadInstallPkg(pkgURL, checksum string) (err error) {
logging.LogInfof("downloading install package [%s]", pkgURL)
client := req.C().SetTLSHandshakeTimeout(7 * time.Second).SetTimeout(10 * time.Minute)
callback := func(info req.DownloadInfo) {
//logging.LogDebugf("downloading install package [%s %.2f%%]", pkgURL, float64(info.DownloadedSize)/float64(info.Response.ContentLength)*100.0)
progress := fmt.Sprintf("%.2f%%", float64(info.DownloadedSize)/float64(info.Response.ContentLength)*100.0)
// logging.LogDebugf("downloading install package [%s %s]", pkgURL, progress)
util.PushStatusBar(fmt.Sprintf(Conf.Language(133), progress))
}
_, err = client.R().SetOutputFile(savePath).SetDownloadCallback(callback).Get(pkgURL)
_, err = client.R().SetOutputFile(savePath).SetDownloadCallbackWithInterval(callback, 1*time.Second).Get(pkgURL)
if nil != err {
logging.LogErrorf("download install package [%s] failed: %s", pkgURL, err)
return
@ -187,6 +189,7 @@ func downloadInstallPkg(pkgURL, checksum string) (err error) {
return
}
logging.LogInfof("downloaded install package [%s] to [%s]", pkgURL, savePath)
util.PushStatusBar(Conf.Language(62))
return
}