mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-23 13:59:09 +02:00
Tighten verbose comments in Wails UI Go code
Shorten over-long godoc/inline comments across the client/ui tray and services code: drop narrative restatement, legacy-Fyne tangents, and text already evident from signatures and names. Keep only the non-obvious why (concurrency/lock ordering, platform quirks, ordering constraints, the profile-switch state table). No code changes.
This commit is contained in:
+15
-44
@@ -1,11 +1,8 @@
|
||||
//go:build !android && !ios && !freebsd && !js
|
||||
|
||||
// Package updater carries the auto-update domain: the typed State the UI
|
||||
// renders, the daemon-SystemEvent metadata schema, and the Holder that
|
||||
// caches the latest state and broadcasts changes. Mirrors the layout of
|
||||
// client/ui/i18n and client/ui/preferences — no Wails dependency, just an
|
||||
// optional Emitter interface so callers can pass either the Wails event
|
||||
// processor or a fake in tests.
|
||||
// Package updater holds the auto-update domain: the typed State, the
|
||||
// daemon-SystemEvent metadata schema, and the Holder that caches the latest
|
||||
// state and broadcasts changes. No Wails dependency.
|
||||
package updater
|
||||
|
||||
import (
|
||||
@@ -16,25 +13,12 @@ import (
|
||||
"github.com/netbirdio/netbird/client/proto"
|
||||
)
|
||||
|
||||
// EventStateChanged is the single Wails event the frontend and tray
|
||||
// subscribe to. The payload is the full State snapshot, so consumers
|
||||
// never need to combine multiple events to know what to render.
|
||||
// EventStateChanged carries the full State snapshot as payload.
|
||||
const EventStateChanged = "netbird:update:state"
|
||||
|
||||
// State is the typed snapshot of the daemon's update situation, covering
|
||||
// the three branches the UI cares about:
|
||||
//
|
||||
// - Disabled / opt-in: Available=true, Enforced=false, Installing=false.
|
||||
// Tray shows "Download latest", frontend shows a "Get installer" hint
|
||||
// pointing at GitHub.
|
||||
// - Enforced, user-driven: Available=true, Enforced=true, Installing=false.
|
||||
// Tray shows "Install version X", frontend shows the install banner.
|
||||
// - Forced, daemon already installing: Available=true, Enforced=true,
|
||||
// Installing=true. Both surfaces show the install-in-progress UI.
|
||||
//
|
||||
// Installing is driven only by the daemon's progress_window:show event;
|
||||
// a UI-side Update.Trigger() does not flip it. The frontend tracks its own
|
||||
// "Trigger() in flight" state for the enforced flow.
|
||||
// State is the typed snapshot of the daemon's update situation. Installing is
|
||||
// driven only by the daemon's progress_window:show event; a UI-side
|
||||
// Update.Trigger() does not flip it.
|
||||
type State struct {
|
||||
Available bool `json:"available"`
|
||||
Version string `json:"version"`
|
||||
@@ -42,18 +26,13 @@ type State struct {
|
||||
Installing bool `json:"installing"`
|
||||
}
|
||||
|
||||
// Emitter is the dependency Holder needs to broadcast changes. The Wails
|
||||
// app.Event processor satisfies this; tests pass nil or a fake. Same shape
|
||||
// the preferences package uses, intentionally — both are "broadcast to the
|
||||
// frontend" hooks with no other contract.
|
||||
// Emitter is the broadcast dependency Holder needs; the Wails app.Event
|
||||
// processor satisfies it.
|
||||
type Emitter interface {
|
||||
Emit(name string, data ...any) bool
|
||||
}
|
||||
|
||||
// Holder caches the latest update State and broadcasts changes. Fed by
|
||||
// services.DaemonFeed, which forwards every daemon SystemEvent here via
|
||||
// OnSystemEvent. The state is read by the Wails-bound services.Update
|
||||
// facade (Get) and pushed to subscribers via the Emitter.
|
||||
// Holder caches the latest update State and broadcasts changes.
|
||||
type Holder struct {
|
||||
emitter Emitter
|
||||
|
||||
@@ -61,29 +40,21 @@ type Holder struct {
|
||||
state State
|
||||
}
|
||||
|
||||
// NewHolder constructs an empty-state Holder. The emitter is optional —
|
||||
// pass nil in tests to skip the broadcast.
|
||||
// NewHolder constructs an empty-state Holder. A nil emitter skips the broadcast.
|
||||
func NewHolder(emitter Emitter) *Holder {
|
||||
return &Holder{emitter: emitter}
|
||||
}
|
||||
|
||||
// Get returns a copy of the cached State. Used by the Wails facade so the
|
||||
// frontend can pull the current value on mount before its push subscription
|
||||
// has anything to deliver.
|
||||
// Get returns a copy of the cached State.
|
||||
func (h *Holder) Get() State {
|
||||
h.mu.Lock()
|
||||
defer h.mu.Unlock()
|
||||
return h.state
|
||||
}
|
||||
|
||||
// OnSystemEvent inspects the daemon's SystemEvent metadata for the three
|
||||
// update-related keys (new_version_available, enforced, progress_window
|
||||
// plus version) and folds the result into the cached state. Emits
|
||||
// EventStateChanged only when the state actually changed, so subscribers
|
||||
// do not see redundant pushes when the daemon repeats a snapshot.
|
||||
//
|
||||
// The metadata schema is owned here and nowhere else — neither Peers nor
|
||||
// the tray nor the frontend reaches into ev.Metadata directly.
|
||||
// OnSystemEvent folds update-related metadata into the cached state, emitting
|
||||
// EventStateChanged only on an actual change so repeated daemon snapshots
|
||||
// don't produce redundant pushes.
|
||||
func (h *Holder) OnSystemEvent(ev *proto.SystemEvent) {
|
||||
md := ev.GetMetadata()
|
||||
if len(md) == 0 {
|
||||
|
||||
Reference in New Issue
Block a user