preferences

package
v0.75.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: BSD-3-Clause Imports: 9 Imported by: 0

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

View Source
const DefaultViewMode = ViewModeDefault

DefaultViewMode applies when no file exists or its view-mode is empty.

View Source
const EventPreferencesChanged = "netbird:preferences:changed"

EventPreferencesChanged fires on every persisted update, payload UIPreferences.

Variables

View Source
var ErrUnsupportedViewMode = errors.New("unsupported view mode")

Functions

This section is empty.

Types

type Emitter

type Emitter interface {
	Emit(name string, data ...any) bool
}

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

func (s *Store) ExistedAtLoad() bool

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

func (s *Store) SetAutostartInitialized(done bool) error

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

func (s *Store) SetOnboardingCompleted(done bool) error

SetOnboardingCompleted persists the welcome-window dismissal. No-op if unchanged.

func (*Store) SetViewMode

func (s *Store) SetViewMode(mode ViewMode) error

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.

type ViewMode

type ViewMode string

ViewMode is the preferred Main-window layout: "default" (compact, 380-wide) or "advanced" (900-wide).

const (
	ViewModeDefault  ViewMode = "default"
	ViewModeAdvanced ViewMode = "advanced"
)

func (ViewMode) IsValid

func (v ViewMode) IsValid() bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL