config

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package config provides configuration management backed by SQLite.

The Manager reads and writes UI preferences (colours, locale, display config) using the shared store.DB. On first run it imports any existing config.yaml so users upgrading from a YAML-based installation don't lose their settings.

Index

Constants

View Source
const (
	DefaultBackgroundColor = "#000000"
	DefaultBackgroundImage = "background.png"
	DefaultTextColor       = "#FFFFFF"
	DefaultFontFamily      = "GoRegular"
	DefaultFontSize        = 11.0
	DefaultTimeFontSize    = 14.0
	DefaultLayout          = "dashboard"
	DefaultDateFormat      = "MM/DD/YYYY"
)

Default configuration values.

Variables

View Source
var (
	ErrInvalidColor = errors.New("invalid color: must be hex color (e.g. #FFFFFF)")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	// openapi:description Background color in hex format
	// openapi:example #000000
	BackgroundColor string `mapstructure:"background_color" json:"background_color"`
	// openapi:description Background image filename
	// openapi:example background.png
	BackgroundImage string `mapstructure:"background_image" json:"background_image"`
	// openapi:description Text color in hex format
	// openapi:example #FFFFFF
	TextColor string `mapstructure:"text_color" json:"text_color"`
	// openapi:description List of custom image paths
	ImagePaths []string `mapstructure:"image_paths" json:"image_paths"`
	// openapi:description Display-specific configuration
	Display DisplayConfig `mapstructure:"display" json:"display"`
}

Config holds the application configuration (UI settings only). Module-specific configs are managed per-zone via zone config system. openapi:schema Config

func (*Config) GetBackgroundColor

func (c *Config) GetBackgroundColor() (color.Color, error)

GetBackgroundColor parses and returns the background color.

func (*Config) GetTextColor

func (c *Config) GetTextColor() (color.Color, error)

GetTextColor parses and returns the text color.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the configuration is valid.

type DisplayConfig

type DisplayConfig struct {
	// openapi:description Font family name
	// openapi:example GoRegular
	FontFamily string `mapstructure:"font_family" json:"font_family"`
	// openapi:description Base font size in points
	// openapi:example 11.0
	FontSize float64 `mapstructure:"font_size" json:"font_size"`
	// openapi:description Time display font size in points
	// openapi:example 14.0
	TimeFontSize float64 `mapstructure:"time_font_size" json:"time_font_size"`
	// openapi:description Layout style
	// openapi:enum dashboard minimalist compact balanced
	// openapi:example dashboard
	Layout string `mapstructure:"layout" json:"layout"`
	// openapi:description Date format string
	// openapi:example MM/DD/YYYY
	DateFormat string `mapstructure:"date_format" json:"date_format"`
}

DisplayConfig holds display-specific configuration. openapi:schema DisplayConfig

type Manager

type Manager struct {
	IsFirstRun bool // true when the DB was freshly created on this launch
	// contains filtered or unexported fields
}

Manager handles configuration loading, validation, and watching. The zero value is invalid — use NewManager.

func NewManager

func NewManager(s *store.DB, logger *slog.Logger) (*Manager, error)

NewManager creates a Manager backed by the given store. It loads the current config from the store (applying defaults for any missing keys) and marks IsFirstRun if the store was newly created.

func NewManagerFromPath

func NewManagerFromPath(path string, logger *slog.Logger) (*Manager, error)

NewManagerFromPath is a convenience constructor that opens its own store at the given path (or the default path when empty). Callers that already have a *store.DB should use NewManager instead.

func (*Manager) Get

func (m *Manager) Get() Config

Get returns a copy of the current configuration (thread-safe).

func (*Manager) ImportFromYAML

func (m *Manager) ImportFromYAML(yamlPath string, logger *slog.Logger) error

ImportFromYAML imports settings from a legacy config.yaml file into the store. Called once on first run. Silently succeeds if the YAML file doesn't exist (fresh install, not an upgrade).

func (*Manager) Update

func (m *Manager) Update(cfg Config) error

Update atomically validates, persists, and broadcasts new configuration.

func (*Manager) Watch

func (m *Manager) Watch(ch chan<- Config)

Watch registers a channel to receive configuration updates.

Jump to

Keyboard shortcuts

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