🎨 The User Guide is no longer opened repeatedly when multiple windows exist https://github.com/siyuan-note/siyuan/issues/11588

This commit is contained in:
Daniel 2024-05-31 10:47:01 +08:00
parent 564c578369
commit 7b4d297ade
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
3 changed files with 51 additions and 23 deletions

View file

@ -32,6 +32,26 @@ var (
sessions = sync.Map{} // {appId, {sessionId, session}}
)
func BroadcastByTypeAndApp(typ, app, cmd string, code int, msg string, data interface{}) {
appSessions, ok := sessions.Load(app)
if !ok {
return
}
appSessions.(*sync.Map).Range(func(key, value interface{}) bool {
session := value.(*melody.Session)
if t, ok := session.Get("type"); ok && typ == t {
event := NewResult()
event.Cmd = cmd
event.Code = code
event.Msg = msg
event.Data = data
session.Write(event.Bytes())
}
return true
})
}
// BroadcastByType 广播所有实例上 typ 类型的会话。
func BroadcastByType(typ, cmd string, code int, msg string, data interface{}) {
typeSessions := SessionsByType(typ)