Przeglądaj źródła

:art: localStorage 支持在多界面实例间同步 https://github.com/siyuan-note/siyuan/issues/6965

Liang Ding 2 lat temu
rodzic
commit
ba7f04c483
1 zmienionych plików z 24 dodań i 14 usunięć
  1. 24 14
      kernel/api/storage.go

+ 24 - 14
kernel/api/storage.go

@@ -136,13 +136,18 @@ func removeLocalStorageVal(c *gin.Context) {
 	}
 	}
 
 
 	key := arg["key"].(string)
 	key := arg["key"].(string)
-
 	err := model.RemoveLocalStorageVal(key)
 	err := model.RemoveLocalStorageVal(key)
 	if nil != err {
 	if nil != err {
 		ret.Code = -1
 		ret.Code = -1
 		ret.Msg = err.Error()
 		ret.Msg = err.Error()
 		return
 		return
 	}
 	}
+
+	app := arg["app"].(string)
+	evt := util.NewCmdResult("removeLocalStorageVal", 0, util.PushModeBroadcastMainExcludeSelfApp)
+	evt.AppId = app
+	evt.Data = map[string]interface{}{"key": key}
+	util.PushEvent(evt)
 }
 }
 
 
 func setLocalStorageVal(c *gin.Context) {
 func setLocalStorageVal(c *gin.Context) {
@@ -156,26 +161,18 @@ func setLocalStorageVal(c *gin.Context) {
 
 
 	key := arg["key"].(string)
 	key := arg["key"].(string)
 	val := arg["val"].(interface{})
 	val := arg["val"].(interface{})
-
 	err := model.SetLocalStorageVal(key, val)
 	err := model.SetLocalStorageVal(key, val)
 	if nil != err {
 	if nil != err {
 		ret.Code = -1
 		ret.Code = -1
 		ret.Msg = err.Error()
 		ret.Msg = err.Error()
 		return
 		return
 	}
 	}
-}
 
 
-func getLocalStorage(c *gin.Context) {
-	ret := gulu.Ret.NewResult()
-	defer c.JSON(http.StatusOK, ret)
-
-	data, err := model.GetLocalStorage()
-	if nil != err {
-		ret.Code = -1
-		ret.Msg = err.Error()
-		return
-	}
-	ret.Data = data
+	app := arg["app"].(string)
+	evt := util.NewCmdResult("setLocalStorageVal", 0, util.PushModeBroadcastMainExcludeSelfApp)
+	evt.AppId = app
+	evt.Data = map[string]interface{}{"key": key, "val": val}
+	util.PushEvent(evt)
 }
 }
 
 
 func setLocalStorage(c *gin.Context) {
 func setLocalStorage(c *gin.Context) {
@@ -201,3 +198,16 @@ func setLocalStorage(c *gin.Context) {
 	evt.Data = val
 	evt.Data = val
 	util.PushEvent(evt)
 	util.PushEvent(evt)
 }
 }
+
+func getLocalStorage(c *gin.Context) {
+	ret := gulu.Ret.NewResult()
+	defer c.JSON(http.StatusOK, ret)
+
+	data, err := model.GetLocalStorage()
+	if nil != err {
+		ret.Code = -1
+		ret.Msg = err.Error()
+		return
+	}
+	ret.Data = data
+}