Переглянути джерело

:art: Improve the mouse hove data sync button information on the desktop and browser https://github.com/siyuan-note/siyuan/issues/8521

Daniel 2 роки тому
батько
коміт
b53d210258
3 змінених файлів з 23 додано та 0 видалено
  1. 1 0
      kernel/api/router.go
  2. 16 0
      kernel/api/sync.go
  3. 6 0
      kernel/model/sync.go

+ 1 - 0
kernel/api/router.go

@@ -209,6 +209,7 @@ func ServeAPI(ginServer *gin.Engine) {
 	ginServer.Handle("POST", "/api/sync/performSync", model.CheckAuth, model.CheckReadonly, performSync)
 	ginServer.Handle("POST", "/api/sync/performBootSync", model.CheckAuth, model.CheckReadonly, performBootSync)
 	ginServer.Handle("POST", "/api/sync/getBootSync", model.CheckAuth, getBootSync)
+	ginServer.Handle("POST", "/api/sync/getSyncInfo", model.CheckAuth, getSyncInfo)
 
 	ginServer.Handle("POST", "/api/inbox/getShorthands", model.CheckAuth, getShorthands)
 	ginServer.Handle("POST", "/api/inbox/getShorthand", model.CheckAuth, getShorthand)

+ 16 - 0
kernel/api/sync.go

@@ -26,6 +26,22 @@ import (
 	"github.com/siyuan-note/siyuan/kernel/util"
 )
 
+func getSyncInfo(c *gin.Context) {
+	ret := gulu.Ret.NewResult()
+	defer c.JSON(http.StatusOK, ret)
+
+	if !model.Conf.Sync.Enabled {
+		ret.Msg = model.Conf.Language(53)
+		return
+	}
+
+	ret.Data = map[string]interface{}{
+		"synced":  model.Conf.Sync.Synced,
+		"stat":    model.Conf.Sync.Stat,
+		"kernels": model.GetOnlineKernels(),
+	}
+}
+
 func getBootSync(c *gin.Context) {
 	ret := gulu.Ret.NewResult()
 	defer c.JSON(http.StatusOK, ret)

+ 6 - 0
kernel/model/sync.go

@@ -653,6 +653,12 @@ var (
 	onlineKernelsLock = sync.Mutex{}
 )
 
+func GetOnlineKernels() []*OnlineKernel {
+	onlineKernelsLock.Lock()
+	defer onlineKernelsLock.Unlock()
+	return onlineKernels
+}
+
 var closedSyncWebSocket = false
 
 func closeSyncWebSocket() {