🎨 Partially refresh the interface after data synchronization https://github.com/siyuan-note/siyuan/issues/8098

This commit is contained in:
Liang Ding 2023-04-25 15:34:46 +08:00
parent e0e40dbad2
commit bd2e2c78bc
No known key found for this signature in database
GPG Key ID: 136F30F901A2231D
4 changed files with 33 additions and 11 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

@ -1053,7 +1053,8 @@ func bootSyncRepo() (err error) {
if 0 < len(fetchedFiles) { if 0 < len(fetchedFiles) {
go func() { go func() {
time.Sleep(7 * time.Second) // 等待一段时间后前端完成界面初始化后再同步 util.WaitForUILoaded() // 等待一段时间后前端完成界面初始化后再同步,因为需要推送消息
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)

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,26 @@ import (
const DatabaseVer = "20220501" // 修改表结构的话需要修改这里 const DatabaseVer = "20220501" // 修改表结构的话需要修改这里
// IsUILoaded 是否已经加载了 UI。
var IsUILoaded = false
func WaitForUILoaded() {
for !IsUILoaded {
logging.LogInfof("waiting for UI loading...")
time.Sleep(time.Second)
}
}
func HookUILoaded() {
for !IsUILoaded {
if 0 < len(SessionsByType("main")) {
IsUILoaded = true
return
}
time.Sleep(time.Second)
}
}
// IsExiting 是否正在退出程序。 // IsExiting 是否正在退出程序。
var IsExiting = false var IsExiting = false