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

This commit is contained in:
Liang Ding 2023-01-01 13:56:10 +08:00
parent 3a1382cb42
commit 853ba5be3a
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
5 changed files with 38 additions and 10 deletions

View file

@ -233,6 +233,8 @@ func PushEvent(event *Result) {
broadcastOtherApps(msg, event.AppId)
case PushModeBroadcastApp:
broadcastApp(msg, event.AppId)
case PushModeBroadcastMainExcludeSelfApp:
broadcastOtherAppMains(msg, event.AppId)
case PushModeNone:
}
}
@ -282,6 +284,26 @@ func broadcastOtherApps(msg []byte, excludeApp string) {
})
}
func broadcastOtherAppMains(msg []byte, excludeApp string) {
sessions.Range(func(key, value interface{}) bool {
appSessions := value.(*sync.Map)
appSessions.Range(func(key, value interface{}) bool {
session := value.(*melody.Session)
if app, _ := session.Get("app"); app == excludeApp {
return true
}
if t, ok := session.Get("type"); ok && "main" != t {
return true
}
session.Write(msg)
return true
})
return true
})
}
func broadcastApp(msg []byte, app string) {
sessions.Range(func(key, value interface{}) bool {
appSessions := value.(*sync.Map)