🎨 支持列出和切换最近打开的文档 https://github.com/siyuan-note/siyuan/issues/3293

This commit is contained in:
Liang Ding 2022-12-12 22:22:47 +08:00
parent ec8f27f5fe
commit d679bedd77
No known key found for this signature in database
GPG key ID: 136F30F901A2231D

View file

@ -17,14 +17,15 @@
package model
import (
"github.com/88250/lute/parse"
"os"
"path/filepath"
"sync"
"github.com/88250/gulu"
"github.com/88250/lute/parse"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
)
@ -127,7 +128,7 @@ func setRecentDocs(recentDocs []*RecentDoc) (err error) {
}
func getRecentDocs() (ret []*RecentDoc, err error) {
ret = []*RecentDoc{}
tmp := []*RecentDoc{}
dataPath := filepath.Join(util.DataDir, "storage/recent-doc.json")
if !gulu.File.IsExist(dataPath) {
return
@ -139,10 +140,22 @@ func getRecentDocs() (ret []*RecentDoc, err error) {
return
}
if err = gulu.JSON.UnmarshalJSON(data, &ret); nil != err {
if err = gulu.JSON.UnmarshalJSON(data, &tmp); nil != err {
logging.LogErrorf("unmarshal storage [recent-doc] failed: %s", err)
return
}
var notExists []string
for _, doc := range tmp {
if nil != treenode.GetBlockTree(doc.RootID) {
ret = append(ret, doc)
} else {
notExists = append(notExists, doc.RootID)
}
}
if 0 < len(notExists) {
setRecentDocs(ret)
}
return
}