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

This commit is contained in:
Liang Ding 2023-01-01 14:09:36 +08:00
parent 3adb7d9ad0
commit 95bb18afe1
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
12 changed files with 49 additions and 55 deletions

View file

@ -24,45 +24,41 @@ import (
type PushMode int
const (
PushModeBroadcast PushMode = 0 // 所有应用所有会话广播
PushModeSingleSelf PushMode = 1 // 自我应用会话单播
PushModeBroadcastExcludeSelf PushMode = 2 // 非自我会话广播
PushModeBroadcastExcludeSelfApp PushMode = 4 // 非自我应用所有会话广播
PushModeBroadcastApp PushMode = 5 // 单个应用内所有会话广播
PushModeBroadcastMainExcludeSelfApp PushMode = 6 // 非自我应用主会话广播
PushModeNone PushMode = 10 // 不进行 reload
PushModeBroadcast PushMode = 0 // 所有应用所有会话广播
PushModeSingleSelf PushMode = 1 // 自我应用会话单播
PushModeBroadcastExcludeSelf PushMode = 2 // 非自我会话广播
PushModeBroadcastExcludeSelfApp PushMode = 4 // 非自我应用所有会话广播
PushModeBroadcastApp PushMode = 5 // 单个应用内所有会话广播
PushModeBroadcastMainExcludeSelfApp PushMode = 6 // 非自我应用主会话广播
)
type Result struct {
Cmd string `json:"cmd"`
ReqId float64 `json:"reqId"`
AppId string `json:"app"`
SessionId string `json:"sid"`
PushMode PushMode `json:"pushMode"`
ReloadPushMode PushMode `json:"reloadPushMode"`
Callback interface{} `json:"callback"`
Code int `json:"code"`
Msg string `json:"msg"`
Data interface{} `json:"data"`
Cmd string `json:"cmd"`
ReqId float64 `json:"reqId"`
AppId string `json:"app"`
SessionId string `json:"sid"`
PushMode PushMode `json:"pushMode"`
Callback interface{} `json:"callback"`
Code int `json:"code"`
Msg string `json:"msg"`
Data interface{} `json:"data"`
}
func NewResult() *Result {
return &Result{Cmd: "",
ReqId: 0,
PushMode: 0,
ReloadPushMode: 0,
Callback: "",
Code: 0,
Msg: "",
Data: nil}
ReqId: 0,
PushMode: 0,
Callback: "",
Code: 0,
Msg: "",
Data: nil}
}
func NewCmdResult(cmdName string, cmdId float64, pushMode, reloadPushMode PushMode) *Result {
func NewCmdResult(cmdName string, cmdId float64, pushMode PushMode) *Result {
ret := NewResult()
ret.Cmd = cmdName
ret.ReqId = cmdId
ret.PushMode = pushMode
ret.ReloadPushMode = reloadPushMode
return ret
}

View file

@ -121,7 +121,7 @@ func ClosePushChan(id string) {
}
func ReloadUI() {
evt := NewCmdResult("reloadui", 0, PushModeBroadcast, 0)
evt := NewCmdResult("reloadui", 0, PushModeBroadcast)
PushEvent(evt)
}
@ -208,7 +208,7 @@ func PushClearProgress() {
}
func PushDownloadProgress(id string, percent float32) {
evt := NewCmdResult("downloadProgress", 0, PushModeBroadcast, 0)
evt := NewCmdResult("downloadProgress", 0, PushModeBroadcast)
evt.Data = map[string]interface{}{
"id": id,
"percent": percent,
@ -219,9 +219,6 @@ func PushDownloadProgress(id string, percent float32) {
func PushEvent(event *Result) {
msg := event.Bytes()
mode := event.PushMode
if "reload" == event.Cmd {
mode = event.ReloadPushMode
}
switch mode {
case PushModeBroadcast:
Broadcast(msg)
@ -235,7 +232,6 @@ func PushEvent(event *Result) {
broadcastApp(msg, event.AppId)
case PushModeBroadcastMainExcludeSelfApp:
broadcastOtherAppMains(msg, event.AppId)
case PushModeNone:
}
}