Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

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

Liang Dingbd2e2c78bce8
diff --git a/kernel/api/system.go b/kernel/api/system.go
index 67a8a6691a..03adb8363e 100644
--- a/kernel/api/system.go
+++ b/kernel/api/system.go
@@ -182,7 +182,6 @@ func exportLog(c *gin.Context) {
}
}
-var start = true // 是否是启动
func getConf(c *gin.Context) {
ret := gulu.Ret.NewResult()
defer c.JSON(http.StatusOK, ret)
@@ -200,21 +199,21 @@ func getConf(c *gin.Context) {
ret.Data = map[string]interface{}{
"conf": maskedConf,
- "start": start,
+ "start": !util.IsUILoaded,
}
- if start {
- start = false
+ if !util.IsUILoaded {
+ go func() {
+ util.WaitForUILoaded()
- if model.Conf.Editor.ReadOnly {
- // 编辑器启用只读模式时启动后提示用户 https://github.com/siyuan-note/siyuan/issues/7700
- go func() {
- time.Sleep(time.Second * 7)
+ if model.Conf.Editor.ReadOnly {
+ // 编辑器启用只读模式时启动后提示用户 https://github.com/siyuan-note/siyuan/issues/7700
+ time.Sleep(time.Second * 3)
if model.Conf.Editor.ReadOnly {
util.PushMsg(model.Conf.Language(197), 7000)
}
- }()
- }
+ }
+ }()
}
}
diff --git a/kernel/model/repository.go b/kernel/model/repository.go
index 59db74a265..552bc6d576 100644
--- a/kernel/model/repository.go
+++ b/kernel/model/repository.go
@@ -1053,7 +1053,8 @@ func bootSyncRepo() (err error) {
if 0 < len(fetchedFiles) {
go func() {
- time.Sleep(7 * time.Second) // 等待一段时间后前端完成界面初始化后再同步
+ util.WaitForUILoaded() // 等待一段时间后前端完成界面初始化后再同步,因为需要推送消息
+
syncErr := syncRepo(false, false)
if nil != err {
logging.LogErrorf("boot background sync repo failed: %s", syncErr)
diff --git a/kernel/server/serve.go b/kernel/server/serve.go
index d27b596e6f..69ce7833a8 100644
--- a/kernel/server/serve.go
+++ b/kernel/server/serve.go
@@ -129,6 +129,8 @@ func Serve(fastMode bool) {
}
}()
+ go util.HookUILoaded()
+
if err = http.Serve(ln, ginServer); nil != err {
if !fastMode {
logging.LogErrorf("boot kernel failed: %s", err)
diff --git a/kernel/util/runtime.go b/kernel/util/runtime.go
index d6272adfd0..ceea0cbd0c 100644
--- a/kernel/util/runtime.go
+++ b/kernel/util/runtime.go
@@ -40,6 +40,26 @@ import (
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 是否正在退出程序。
var IsExiting = false