diff --git a/kernel/api/storage.go b/kernel/api/storage.go index e8ea3e6ca..0066eed89 100644 --- a/kernel/api/storage.go +++ b/kernel/api/storage.go @@ -188,11 +188,16 @@ func setLocalStorage(c *gin.Context) { } val := arg["val"].(interface{}) - err := model.SetLocalStorage(val) if nil != err { ret.Code = -1 ret.Msg = err.Error() return } + + app := arg["app"].(string) + evt := util.NewCmdResult("transactions", 0, util.PushModeBroadcastMainExcludeSelfApp, util.PushModeBroadcastMainExcludeSelfApp) + evt.AppId = app + evt.Data = val + util.PushEvent(evt) } diff --git a/kernel/go.mod b/kernel/go.mod index f6d6f980a..31c512683 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -39,7 +39,7 @@ require ( github.com/patrickmn/go-cache v2.1.0+incompatible github.com/radovskyb/watcher v1.0.7 github.com/shirou/gopsutil/v3 v3.22.11 - github.com/siyuan-note/dejavu v0.0.0-20230101033600-8b9f3e6befc0 + github.com/siyuan-note/dejavu v0.0.0-20230101054002-870267a37485 github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da github.com/siyuan-note/filelock v0.0.0-20221117095924-e1947438a35e diff --git a/kernel/go.sum b/kernel/go.sum index fa8b038ae..b8d51bb0a 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -374,8 +374,8 @@ github.com/shurcooL/reactions v0.0.0-20181006231557-f2e0b4ca5b82/go.mod h1:TCR1l github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4= github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw= -github.com/siyuan-note/dejavu v0.0.0-20230101033600-8b9f3e6befc0 h1:iIpzMneefDIHZk3xyXuDSxgz4ZsIvXCgB37LwdpnpBA= -github.com/siyuan-note/dejavu v0.0.0-20230101033600-8b9f3e6befc0/go.mod h1:gTazhE8f5TuknSodwQukv7GHy+qR1crX5SCxARrTXZU= +github.com/siyuan-note/dejavu v0.0.0-20230101054002-870267a37485 h1:oqHz0bGugvtUc9sl6YEru8jSA1YNHhMnPcvHLF/RuyM= +github.com/siyuan-note/dejavu v0.0.0-20230101054002-870267a37485/go.mod h1:gTazhE8f5TuknSodwQukv7GHy+qR1crX5SCxARrTXZU= github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29LW+Fm0cHc0J1NO1cZqyJwljSWVmfOqVZgaE= github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw= github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da h1:/jNhl7LC+9BhkWvNxuJDdsNfA/2wvfuj9mqWx4CbV90= diff --git a/kernel/util/result.go b/kernel/util/result.go index 036525243..7ea9bf55d 100644 --- a/kernel/util/result.go +++ b/kernel/util/result.go @@ -24,12 +24,13 @@ import ( type PushMode int const ( - PushModeBroadcast PushMode = 0 // 所有应用所有会话广播 - PushModeSingleSelf PushMode = 1 // 自我应用会话单播 - PushModeBroadcastExcludeSelf PushMode = 2 // 非自我会话广播 - PushModeBroadcastExcludeSelfApp PushMode = 4 // 非自我应用所有会话广播 - PushModeBroadcastApp PushMode = 5 // 单个应用内所有会话广播 - PushModeNone PushMode = 10 // 不进行 reload + PushModeBroadcast PushMode = 0 // 所有应用所有会话广播 + PushModeSingleSelf PushMode = 1 // 自我应用会话单播 + PushModeBroadcastExcludeSelf PushMode = 2 // 非自我会话广播 + PushModeBroadcastExcludeSelfApp PushMode = 4 // 非自我应用所有会话广播 + PushModeBroadcastApp PushMode = 5 // 单个应用内所有会话广播 + PushModeBroadcastMainExcludeSelfApp PushMode = 6 // 非自我应用主会话广播 + PushModeNone PushMode = 10 // 不进行 reload ) type Result struct { diff --git a/kernel/util/websocket.go b/kernel/util/websocket.go index 76c25fb65..6e9b8a0dd 100644 --- a/kernel/util/websocket.go +++ b/kernel/util/websocket.go @@ -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)