🐛 更新版本后自动打开最新版的用户指南重复 https://github.com/siyuan-note/siyuan/issues/7517

This commit is contained in:
Liang Ding 2023-03-07 14:50:21 +08:00
parent dd5336b9b1
commit 76aef4689b
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
8 changed files with 66 additions and 6 deletions

View file

@ -19,6 +19,7 @@ package model
import (
"bytes"
"fmt"
"github.com/siyuan-note/siyuan/kernel/task"
"os"
"path/filepath"
"runtime"
@ -219,9 +220,10 @@ func InitConf() {
} else {
logging.LogInfof("downgraded from version [%s] to [%s]", Conf.System.KernelVersion, util.Ver)
}
Conf.OpenHelp = Conf.System.KernelVersion != util.Ver
Conf.System.KernelVersion = util.Ver
Conf.System.IsInsider = util.IsInsider
task.AppendTask(task.UpgradeUserGuide, upgradeUserGuide)
}
if nil == Conf.System.NetworkProxy {
Conf.System.NetworkProxy = &conf.NetworkProxy{}
@ -779,3 +781,52 @@ func clearWorkspaceTemp() {
logging.LogInfof("cleared workspace temp")
}
func upgradeUserGuide() {
dirs, err := os.ReadDir(util.DataDir)
if nil != err {
logging.LogErrorf("read dir [%s] failed: %s", util.DataDir, err)
return
}
for _, dir := range dirs {
if !IsUserGuide(dir.Name()) {
continue
}
boxID := dir.Name()
boxDirPath := filepath.Join(util.DataDir, boxID)
boxConf := conf.NewBoxConf()
boxConfPath := filepath.Join(boxDirPath, ".siyuan", "conf.json")
if !gulu.File.IsExist(boxConfPath) {
logging.LogWarnf("found a corrupted box [%s]", boxDirPath)
continue
}
data, readErr := filelock.ReadFile(boxConfPath)
if nil != readErr {
logging.LogErrorf("read box conf [%s] failed: %s", boxConfPath, readErr)
continue
}
if readErr = gulu.JSON.UnmarshalJSON(data, boxConf); nil != readErr {
logging.LogErrorf("parse box conf [%s] failed: %s", boxConfPath, readErr)
continue
}
if boxConf.Closed {
continue
}
unindex(boxID)
if err = filelock.Remove(boxDirPath); nil != err {
return
}
p := filepath.Join(util.WorkingDir, "guide", boxID)
if err = filelock.Copy(p, boxDirPath); nil != err {
return
}
index(boxID)
}
}

View file

@ -93,6 +93,7 @@ const (
HistoryDatabaseIndexCommit = "task.history.database.index.commit" // 历史数据库索引提交
DatabaseIndexEmbedBlock = "task.database.index.embedBlock" // 数据库索引嵌入块
ReloadUI = "task.reload.ui" // 重载 UI
UpgradeUserGuide = "task.upgrade.userGuide" // 升级用户指南文档笔记本
)
// uniqueActions 描述了唯一的任务,即队列中只能存在一个在执行的任务。

View file

@ -194,6 +194,9 @@ func SizeOfDirectory(path string) (size int64, err error) {
func DataSize() (dataSize, assetsSize int64) {
filepath.Walk(DataDir, func(path string, info os.FileInfo, err error) error {
if nil != err {
if os.IsNotExist(err) {
return nil
}
logging.LogErrorf("size of data failed: %s", err)
return io.EOF
}