Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2023-04-25 18:54:05 +08:00
commit 0384261c95
6 changed files with 63 additions and 36 deletions

View file

@ -182,7 +182,6 @@ func exportLog(c *gin.Context) {
} }
} }
var start = true // 是否是启动
func getConf(c *gin.Context) { func getConf(c *gin.Context) {
ret := gulu.Ret.NewResult() ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret) defer c.JSON(http.StatusOK, ret)
@ -200,21 +199,21 @@ func getConf(c *gin.Context) {
ret.Data = map[string]interface{}{ ret.Data = map[string]interface{}{
"conf": maskedConf, "conf": maskedConf,
"start": start, "start": !util.IsUILoaded,
} }
if start { if !util.IsUILoaded {
start = false go func() {
util.WaitForUILoaded()
if model.Conf.Editor.ReadOnly { if model.Conf.Editor.ReadOnly {
// 编辑器启用只读模式时启动后提示用户 https://github.com/siyuan-note/siyuan/issues/7700 // 编辑器启用只读模式时启动后提示用户 https://github.com/siyuan-note/siyuan/issues/7700
go func() { time.Sleep(time.Second * 3)
time.Sleep(time.Second * 7)
if model.Conf.Editor.ReadOnly { if model.Conf.Editor.ReadOnly {
util.PushMsg(model.Conf.Language(197), 7000) util.PushMsg(model.Conf.Language(197), 7000)
} }
}() }
} }()
} }
} }

View file

@ -478,10 +478,6 @@ func genTreeID(tree *parse.Tree) {
return return
} }
func ReloadUI() {
task.AppendTask(task.ReloadUI, util.ReloadUI)
}
func FullReindex() { func FullReindex() {
task.AppendTask(task.DatabaseIndexFull, fullReindex) task.AppendTask(task.DatabaseIndexFull, fullReindex)
task.AppendTask(task.DatabaseIndexRef, IndexRefs) task.AppendTask(task.DatabaseIndexRef, IndexRefs)

View file

@ -1053,7 +1053,6 @@ func bootSyncRepo() (err error) {
if 0 < len(fetchedFiles) { if 0 < len(fetchedFiles) {
go func() { go func() {
time.Sleep(7 * time.Second) // 等待一段时间后前端完成界面初始化后再同步
syncErr := syncRepo(false, false) syncErr := syncRepo(false, false)
if nil != err { if nil != err {
logging.LogErrorf("boot background sync repo failed: %s", syncErr) logging.LogErrorf("boot background sync repo failed: %s", syncErr)
@ -1238,33 +1237,42 @@ func processSyncMergeResult(exit, byHand bool, start time.Time, mergeResult *dej
return return
} }
incReindex(upserts, removes) if exit { // 退出时同步不用推送事件
if !exit { return
ReloadUI()
} }
upsertRootIDs, removeRootIDs := incReindex(upserts, removes)
elapsed := time.Since(start) elapsed := time.Since(start)
if !exit { go func() {
go func() { util.WaitForUILoaded()
time.Sleep(2 * time.Second)
util.PushStatusBar(fmt.Sprintf(Conf.Language(149), elapsed.Seconds()))
if 0 < len(mergeResult.Conflicts) { if util.ContainerAndroid == util.Container || util.ContainerIOS == util.Container {
syConflict := false // 移动端不推送差异详情
for _, file := range mergeResult.Conflicts { upsertRootIDs = []string{}
if strings.HasSuffix(file.Path, ".sy") { removeRootIDs = []string{}
syConflict = true }
break
}
}
if syConflict { util.BroadcastByType("main", "syncMergeResult", 0, "",
// 数据同步发生冲突时在界面上进行提醒 https://github.com/siyuan-note/siyuan/issues/7332 map[string]interface{}{"upsertRootIDs": upsertRootIDs, "removeRootIDs": removeRootIDs})
util.PushMsg(Conf.Language(108), 7000)
time.Sleep(2 * time.Second)
util.PushStatusBar(fmt.Sprintf(Conf.Language(149), elapsed.Seconds()))
if 0 < len(mergeResult.Conflicts) {
syConflict := false
for _, file := range mergeResult.Conflicts {
if strings.HasSuffix(file.Path, ".sy") {
syConflict = true
break
} }
} }
}()
} if syConflict {
// 数据同步发生冲突时在界面上进行提醒 https://github.com/siyuan-note/siyuan/issues/7332
util.PushMsg(Conf.Language(108), 7000)
}
}
}()
} }
func logSyncMergeResult(mergeResult *dejavu.MergeResult) { func logSyncMergeResult(mergeResult *dejavu.MergeResult) {

View file

@ -260,7 +260,7 @@ func checkSync(boot, exit, byHand bool) bool {
} }
// incReindex 增量重建索引。 // incReindex 增量重建索引。
func incReindex(upserts, removes []string) { func incReindex(upserts, removes []string) (upsertRootIDs, removeRootIDs []string) {
util.IncBootProgress(3, "Sync reindexing...") util.IncBootProgress(3, "Sync reindexing...")
msg := fmt.Sprintf(Conf.Language(35)) msg := fmt.Sprintf(Conf.Language(35))
util.PushStatusBar(msg) util.PushStatusBar(msg)
@ -274,6 +274,7 @@ func incReindex(upserts, removes []string) {
} }
id := strings.TrimSuffix(filepath.Base(removeFile), ".sy") id := strings.TrimSuffix(filepath.Base(removeFile), ".sy")
removeRootIDs = append(removeRootIDs, id)
block := treenode.GetBlockTree(id) block := treenode.GetBlockTree(id)
if nil != block { if nil != block {
msg = fmt.Sprintf(Conf.Language(39), block.RootID) msg = fmt.Sprintf(Conf.Language(39), block.RootID)
@ -316,7 +317,9 @@ func incReindex(upserts, removes []string) {
} }
treenode.IndexBlockTree(tree) treenode.IndexBlockTree(tree)
sql.UpsertTreeQueue(tree) sql.UpsertTreeQueue(tree)
upsertRootIDs = append(upsertRootIDs, tree.Root.ID)
} }
return
} }
func SetCloudSyncDir(name string) { func SetCloudSyncDir(name string) {

View file

@ -129,6 +129,8 @@ func Serve(fastMode bool) {
} }
}() }()
go util.HookUILoaded()
if err = http.Serve(ln, ginServer); nil != err { if err = http.Serve(ln, ginServer); nil != err {
if !fastMode { if !fastMode {
logging.LogErrorf("boot kernel failed: %s", err) logging.LogErrorf("boot kernel failed: %s", err)

View file

@ -40,6 +40,25 @@ import (
const DatabaseVer = "20220501" // 修改表结构的话需要修改这里 const DatabaseVer = "20220501" // 修改表结构的话需要修改这里
// IsUILoaded 是否已经加载了 UI。
var IsUILoaded = false
func WaitForUILoaded() {
for !IsUILoaded {
time.Sleep(200 * time.Millisecond)
}
}
func HookUILoaded() {
for !IsUILoaded {
if 0 < len(SessionsByType("main")) {
IsUILoaded = true
return
}
time.Sleep(200 * time.Millisecond)
}
}
// IsExiting 是否正在退出程序。 // IsExiting 是否正在退出程序。
var IsExiting = false var IsExiting = false