preferences

package
v0.83.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: BSD-3-Clause Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 DefaultTheme = ThemeSystem

DefaultTheme applies when no file exists or its theme is empty/unknown.

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 ErrUnsupportedTheme = errors.New("unsupported theme")
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) SetKeepConnectedOnQuit added in v0.76.2

func (s *Store) SetKeepConnectedOnQuit(keep bool) error

SetKeepConnectedOnQuit persists the disconnect-on-quit opt-out. 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) SetTheme added in v0.79.0

func (s *Store) SetTheme(theme Theme) error

SetTheme validates, persists, and broadcasts. 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 Theme added in v0.79.0

type Theme string

Theme is the preferred UI appearance: follow the OS ("system") or force "light"/"dark".

const (
	ThemeSystem Theme = "system"
	ThemeLight  Theme = "light"
	ThemeDark   Theme = "dark"
)

func (Theme) IsValid added in v0.79.0

func (t Theme) IsValid() bool

type UIPreferences

type UIPreferences struct {
	Language            i18n.LanguageCode `json:"language"`
	ViewMode            ViewMode          `json:"viewMode"`
	Theme               Theme             `json:"theme"`
	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"`
	// KeepConnectedOnQuit leaves the daemon connected when the GUI quits.
	// Its false zero value preserves the historical disconnect-on-quit
	// behaviour for preference files written before the field existed.
	KeepConnectedOnQuit bool `json:"keepConnectedOnQuit"`
}

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