mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-01 13:11:48 +01:00
🎨 localStorage 支持在多界面实例间同步 https://github.com/siyuan-note/siyuan/issues/6965
This commit is contained in:
parent
3adb7d9ad0
commit
95bb18afe1
12 changed files with 49 additions and 55 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue