Documentation
¶
Overview ¶
Package preferences holds user-scope UI state, independent of the daemon profile and shared across all profiles. The Store persists to JSON under os.UserConfigDir() and broadcasts changes to in-process subscribers plus an optional emitter.
Index ¶
- Constants
- Variables
- type Emitter
- type LanguageValidator
- type Store
- func (s *Store) ExistedAtLoad() bool
- func (s *Store) Get() UIPreferences
- func (s *Store) SetAutostartInitialized(done bool) error
- func (s *Store) SetLanguage(lang i18n.LanguageCode) error
- func (s *Store) SetOnboardingCompleted(done bool) error
- func (s *Store) SetViewMode(mode ViewMode) error
- func (s *Store) Subscribe() (<-chan UIPreferences, func())
- type UIPreferences
- type ViewMode
Constants ¶
const DefaultViewMode = ViewModeDefault
DefaultViewMode applies when no file exists or its view-mode is empty.
const EventPreferencesChanged = "netbird:preferences:changed"
EventPreferencesChanged fires on every persisted update, payload UIPreferences.
Variables ¶
var ErrUnsupportedViewMode = errors.New("unsupported view mode")
Functions ¶
This section is empty.
Types ¶
type Emitter ¶
Emitter broadcasts changes to the frontend. Wails' *application.EventProcessor satisfies it; tests pass nil or a fake.
type LanguageValidator ¶
type LanguageValidator interface {
HasLanguage(code i18n.LanguageCode) bool
}
LanguageValidator rejects SetLanguage inputs with no shipped bundle. *i18n.Bundle satisfies it.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the user-scope UI preferences store.
func NewStore ¶
func NewStore(validator LanguageValidator, emitter Emitter) (*Store, error)
NewStore loads preferences from disk, falling back to defaults. A nil validator skips SetLanguage validation; a nil emitter skips broadcasting.
func (*Store) ExistedAtLoad ¶
ExistedAtLoad reports whether the backing preferences file was present on disk when the store loaded. It distinguishes a user who ran a prior GUI version from a brand-new OS user with no preferences yet.
func (*Store) Get ¶
func (s *Store) Get() UIPreferences
Get returns a copy of the current preferences.
func (*Store) SetAutostartInitialized ¶
SetAutostartInitialized persists the one-time autostart decision marker. No-op if unchanged.
func (*Store) SetLanguage ¶
func (s *Store) SetLanguage(lang i18n.LanguageCode) error
SetLanguage validates, persists, and broadcasts. No-op if unchanged.
func (*Store) SetOnboardingCompleted ¶
SetOnboardingCompleted persists the welcome-window dismissal. No-op if unchanged.
func (*Store) SetViewMode ¶
SetViewMode validates, persists, and broadcasts. No-op if unchanged.
func (*Store) Subscribe ¶
func (s *Store) Subscribe() (<-chan UIPreferences, func())
Subscribe returns a channel of persisted changes and an unsubscribe func. The unsubscribe func closes the channel; callers must not close it themselves.
type UIPreferences ¶
type UIPreferences struct {
Language i18n.LanguageCode `json:"language"`
ViewMode ViewMode `json:"viewMode"`
OnboardingCompleted bool `json:"onboardingCompleted"`
// AutostartInitialized records that the one-time autostart default
// decision has run for this OS user. It only ever transitions to true
// and is never reset, so the default-on flow runs at most once, ever.
AutostartInitialized bool `json:"autostartInitialized"`
}
UIPreferences is rewritten in full on every change; there are no partial updates.