Documentation
¶
Overview ¶
Package userconfig exports and imports sectioned Forte user configuration (TOML).
Index ¶
- Constants
- Variables
- func DefaultPath() (string, error)
- func Dir() (string, error)
- func ExportToDBPath(db *library.DB) (string, error)
- func ValidateSchema(cfg File) error
- func WriteFile(path string, cfg File) error
- type AppSection
- type ApplyOptions
- type CustomStationEntry
- type FavouriteEntry
- type File
- type ImportResult
- type RadioSection
Constants ¶
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 ¶
var MergeOptions = ApplyOptions{MergeRadio: true}
MergeOptions adds radio entries from the file without updating existing UUIDs.
var ReplaceOptions = ApplyOptions{}
ReplaceOptions applies file values over matching database rows (upsert).
Functions ¶
func DefaultPath ¶
DefaultPath returns the canonical config file path (…/forte/config.toml).
func ExportToDBPath ¶
ExportToDBPath writes the canonical config file for the current database state.
func ValidateSchema ¶
ValidateSchema returns an error when the file version is not supported.
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 ¶
BuildFromDB reads exportable user state from the library database.
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.