userconfig

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package userconfig exports and imports sectioned Forte user configuration (TOML).

Index

Constants

View Source
const (
	// SchemaVersion is the current on-disk config schema.
	SchemaVersion = 1
	// FileName is the canonical config file under the Forte config directory.
	FileName = "config.toml"
)

Variables

View Source
var MergeOptions = ApplyOptions{MergeRadio: true}

MergeOptions adds radio entries from the file without updating existing UUIDs.

View Source
var ReplaceOptions = ApplyOptions{}

ReplaceOptions applies file values over matching database rows (upsert).

Functions

func DefaultPath

func DefaultPath() (string, error)

DefaultPath returns the canonical config file path (…/forte/config.toml).

func Dir

func Dir() (string, error)

Dir returns the Forte config directory (e.g. ~/.config/forte).

func ExportToDBPath

func ExportToDBPath(db *library.DB) (string, error)

ExportToDBPath writes the canonical config file for the current database state.

func ValidateSchema

func ValidateSchema(cfg File) error

ValidateSchema returns an error when the file version is not supported.

func WriteFile

func WriteFile(path string, cfg File) error

WriteFile encodes cfg as TOML and writes it to path, creating parent directories.

Types

type AppSection

type AppSection struct {
	LibraryEnabled   bool   `toml:"libraryEnabled"`
	StartLastStation bool   `toml:"startLastStation"`
	AutoReconnect    bool   `toml:"autoReconnect"`
	ShowTitlebar     bool   `toml:"showTitlebar"`
	LogLevel         string `toml:"logLevel"`
}

AppSection holds product-level preferences (SQLite app_preferences).

type ApplyOptions

type ApplyOptions struct {
	// MergeRadio inserts favourites and custom stations only when the UUID is
	// not already in the database. Existing rows are left unchanged.
	MergeRadio bool
}

ApplyOptions controls how config sections are merged into the database.

type CustomStationEntry

type CustomStationEntry struct {
	StationUUID string `toml:"stationUuid"`
	Name        string `toml:"name"`
	StreamURL   string `toml:"streamUrl"`
	FaviconURL  string `toml:"faviconUrl"`
	Homepage    string `toml:"homepage"`
	Country     string `toml:"country"`
	Codec       string `toml:"codec"`
	Bitrate     int    `toml:"bitrate"`
	Tags        string `toml:"tags"`
}

CustomStationEntry is one user-defined radio stream.

type FavouriteEntry

type FavouriteEntry struct {
	StationUUID string `toml:"stationUuid"`
	Name        string `toml:"name"`
	StreamURL   string `toml:"streamUrl"`
	FaviconURL  string `toml:"faviconUrl"`
	Homepage    string `toml:"homepage"`
	Country     string `toml:"country"`
	Codec       string `toml:"codec"`
	Bitrate     int    `toml:"bitrate"`
	Tags        string `toml:"tags"`
	Pinned      bool   `toml:"pinned"`
}

FavouriteEntry is one saved radio favourite including pin state.

type File

type File struct {
	SchemaVersion int          `toml:"schemaVersion"`
	ExportedAt    string       `toml:"exportedAt,omitempty"`
	App           AppSection   `toml:"app"`
	Radio         RadioSection `toml:"radio"`
}

File is the top-level config document written to ~/.config/forte/config.toml.

func BuildFromDB

func BuildFromDB(db *library.DB) (File, error)

BuildFromDB reads exportable user state from the library database.

func LoadFile

func LoadFile(path string) (File, error)

LoadFile reads and decodes a config file from disk.

type ImportResult

type ImportResult struct {
	Path            string
	SectionsApplied []string
	SectionsSkipped []string
	Warnings        []string
}

ImportResult reports which sections were applied during import.

func ApplyToDB

func ApplyToDB(db *library.DB, cfg File, opts ApplyOptions) (ImportResult, error)

ApplyToDB imports supported sections from cfg into the library database.

Merge rules (schema v1):

  • app: always overwrites app_preferences.
  • radio: when opts.MergeRadio is true, inserts only new stationUuid values; when false, upserts by stationUuid (file wins for matches).

func ImportDefaultIfPresent

func ImportDefaultIfPresent(db *library.DB) (ImportResult, error)

ImportDefaultIfPresent loads the canonical config file when it exists. Schema errors are returned; a missing file is not an error.

func ImportFile

func ImportFile(db *library.DB, path string, opts ApplyOptions) (ImportResult, error)

ImportFile loads path and applies supported sections using opts.

type RadioSection

type RadioSection struct {
	Favourites     []FavouriteEntry     `toml:"favourites"`
	CustomStations []CustomStationEntry `toml:"customStations"`
}

RadioSection holds radio favourites and custom stations.

Jump to

Keyboard shortcuts

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