🎨 桌面端自动下载更新安装包 https://github.com/siyuan-note/siyuan/issues/5837

This commit is contained in:
Liang Ding 2022-09-08 09:55:29 +08:00
parent 8f6ffd4dcd
commit 313143304b
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
7 changed files with 83 additions and 20 deletions

View file

@ -18,8 +18,8 @@ package model
import (
"bytes"
"errors"
"os"
"os/exec"
"path/filepath"
"runtime"
"sort"
@ -345,7 +345,15 @@ func loadLangs() (ret []*conf.Lang) {
var exitLock = sync.Mutex{}
func Close(force bool) (err error) {
// Close 退出内核进程.
//
// force是否不执行同步过程而直接退出
// execInstallPkg是否执行新版本安装包
//
// 0默认按照设置项 System.DownloadInstallPkg 检查并推送提示
// 1执行安装
// 2不执行安装
func Close(force bool, execInstallPkg int) (exitCode int) {
exitLock.Lock()
defer exitLock.Unlock()
@ -355,7 +363,7 @@ func Close(force bool) (err error) {
if !force {
SyncData(false, true, false)
if 0 != ExitSyncSucc {
err = errors.New(Conf.Language(96))
exitCode = 1
return
}
}
@ -366,13 +374,35 @@ func Close(force bool) (err error) {
// return true
//})
newVerInstallPkgPath := ""
if Conf.System.DownloadInstallPkg && 0 == execInstallPkg {
newVerInstallPkgPath = GetNewVerInstallPkgPath()
if "" != newVerInstallPkgPath {
exitCode = 2
return
}
}
if 2 == execInstallPkg && "" != newVerInstallPkgPath { // 执行新版本安装
logging.LogInfof("install new version [%s]", newVerInstallPkgPath)
cmd := exec.Command(newVerInstallPkgPath)
util.CmdAttr(cmd)
data, cmdErr := cmd.CombinedOutput()
if nil != cmdErr {
logging.LogErrorf("exec install new version failed: %s", cmdErr)
return
}
logging.LogDebugf("exec install new version output [%s]", data)
}
Conf.Close()
sql.CloseDatabase()
util.WebSocketServer.Close()
clearWorkspaceTemp()
logging.LogInfof("exited kernel")
go func() {
time.Sleep(500 * time.Millisecond)
logging.LogInfof("exited kernel")
util.WebSocketServer.Close()
os.Exit(util.ExitCodeOk)
}()
return