mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-07 05:59:06 +02:00
[client] Dispatch status snapshots only to visible windows
This commit is contained in:
@@ -103,6 +103,18 @@ func main() {
|
|||||||
updaterHolder := updater.NewHolder(app.Event)
|
updaterHolder := updater.NewHolder(app.Event)
|
||||||
update := services.NewUpdate(conn, updaterHolder)
|
update := services.NewUpdate(conn, updaterHolder)
|
||||||
daemonFeed := services.NewDaemonFeed(conn, app.Event, updaterHolder, debugLog)
|
daemonFeed := services.NewDaemonFeed(conn, app.Event, updaterHolder, debugLog)
|
||||||
|
// Status snapshots go only to visible windows — a snapshot is full state,
|
||||||
|
// so a hidden webview loses nothing by being skipped; it gets the cached
|
||||||
|
// one on show (SetShowReplay below). Every other event stays on the bus.
|
||||||
|
daemonFeed.SetWindowDispatcher(func(st services.Status) {
|
||||||
|
ev := &application.CustomEvent{Name: services.EventStatusSnapshot, Data: st}
|
||||||
|
for _, w := range app.Window.GetAll() {
|
||||||
|
if w == nil || !w.IsVisible() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
w.DispatchWailsEvent(ev)
|
||||||
|
}
|
||||||
|
})
|
||||||
notifier := notifications.New()
|
notifier := notifications.New()
|
||||||
compat := services.NewCompat(conn)
|
compat := services.NewCompat(conn)
|
||||||
// macOS shows no toast until permission is requested. Run it after
|
// macOS shows no toast until permission is requested. Run it after
|
||||||
|
|||||||
@@ -171,9 +171,10 @@ type DaemonFeed struct {
|
|||||||
// statusSubs are Go-side snapshot consumers (the tray), fed directly so
|
// statusSubs are Go-side snapshot consumers (the tray), fed directly so
|
||||||
// they don't ride the window event bus. Callbacks run synchronously on
|
// they don't ride the window event bus. Callbacks run synchronously on
|
||||||
// the stream goroutine, so pushes arrive in order.
|
// the stream goroutine, so pushes arrive in order.
|
||||||
statusSubsMu sync.Mutex
|
statusSubsMu sync.Mutex
|
||||||
statusSubs []func(Status)
|
statusSubs []func(Status)
|
||||||
lastStatus *Status
|
lastStatus *Status
|
||||||
|
windowDispatcher func(Status)
|
||||||
|
|
||||||
switchMu sync.Mutex
|
switchMu sync.Mutex
|
||||||
switchInProgress bool
|
switchInProgress bool
|
||||||
@@ -204,16 +205,31 @@ func (s *DaemonFeed) OnStatus(cb func(Status)) {
|
|||||||
s.statusSubsMu.Unlock()
|
s.statusSubsMu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetWindowDispatcher installs the frontend push path: it receives every
|
||||||
|
// snapshot and decides which webview windows get it (visible ones). While
|
||||||
|
// unset, pushStatus falls back to the event-bus broadcast.
|
||||||
|
func (s *DaemonFeed) SetWindowDispatcher(fn func(Status)) {
|
||||||
|
s.statusSubsMu.Lock()
|
||||||
|
s.windowDispatcher = fn
|
||||||
|
s.statusSubsMu.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
// pushStatus delivers a snapshot to the Go-side subscribers and the frontend,
|
// pushStatus delivers a snapshot to the Go-side subscribers and the frontend,
|
||||||
// and caches it for LastStatus replays.
|
// and caches it for LastStatus replays. Hidden windows are skipped by the
|
||||||
|
// window dispatcher; they catch up via the show replay (WindowManager).
|
||||||
func (s *DaemonFeed) pushStatus(st Status) {
|
func (s *DaemonFeed) pushStatus(st Status) {
|
||||||
s.statusSubsMu.Lock()
|
s.statusSubsMu.Lock()
|
||||||
s.lastStatus = &st
|
s.lastStatus = &st
|
||||||
subs := slices.Clone(s.statusSubs)
|
subs := slices.Clone(s.statusSubs)
|
||||||
|
dispatch := s.windowDispatcher
|
||||||
s.statusSubsMu.Unlock()
|
s.statusSubsMu.Unlock()
|
||||||
for _, cb := range subs {
|
for _, cb := range subs {
|
||||||
cb(st)
|
cb(st)
|
||||||
}
|
}
|
||||||
|
if dispatch != nil {
|
||||||
|
dispatch(st)
|
||||||
|
return
|
||||||
|
}
|
||||||
s.emitter.Emit(EventStatusSnapshot, st)
|
s.emitter.Emit(EventStatusSnapshot, st)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user