config

package
v0.8.7 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KB = 1 << 10
	MB = 1 << 20
)
View Source
const (
	ThemeAdaptive = 0
	ThemeLight    = 1
	ThemeDark     = 2
)

Variables

This section is empty.

Functions

func CategoryNames

func CategoryNames(categories []Category) []string

CategoryNames returns a slice of category names.

func CategoryOrder

func CategoryOrder() []string

CategoryOrder returns the order of categories for UI tabs.

func EnsureDirs

func EnsureDirs() error

EnsureDirs creates all required directories

func GetDocumentsDir

func GetDocumentsDir() string

func GetDownloadsDir

func GetDownloadsDir() string

func GetLogsDir

func GetLogsDir() string

GetLogsDir returns the directory for logs

func GetMusicDir

func GetMusicDir() string

func GetPicturesDir

func GetPicturesDir() string

func GetRuntimeDir

func GetRuntimeDir() string

func GetSettingsMetadata

func GetSettingsMetadata() map[string][]SettingMeta

GetSettingsMetadata returns metadata for all settings organized by category.

func GetSettingsPath

func GetSettingsPath() string

GetSettingsPath returns the path to the settings JSON file.

func GetStateDir

func GetStateDir() string

func GetSurgeDir

func GetSurgeDir() string

GetSurgeDir returns the directory for configuration files (settings.json). Linux: $XDG_CONFIG_HOME/surge or ~/.config/surge macOS: ~/Library/Application Support/surge Windows: %APPDATA%/surge

func GetSystemRuntimeDir added in v0.8.6

func GetSystemRuntimeDir() string

func GetSystemStateDir added in v0.8.6

func GetSystemStateDir() string

func GetSystemSurgeDir added in v0.8.6

func GetSystemSurgeDir() string

func GetThemesDir added in v0.8.2

func GetThemesDir() string

GetThemesDir returns the directory for themes

func GetVideosDir

func GetVideosDir() string

func Resolve added in v0.8.7

func Resolve[T any](s *Setting) T

Resolve retrieves the value of a setting converted to the expected generic type T. This is a unified, caller-agnostic function that handles all dynamic type conversions safely.

func ResolveCategoryPath

func ResolveCategoryPath(cat *Category, defaultDownloadDir string) string

ResolveCategoryPath returns the Path of a category.

func SaveSettings

func SaveSettings(s *Settings) error

SaveSettings saves settings to disk atomically.

func ValidateDNSList added in v0.8.4

func ValidateDNSList(s string) error

ValidateDNSList checks if a comma-separated list of DNS servers (IP or IP:port) is valid.

Types

type Category

type Category struct {
	Name        string `json:"name"`
	Description string `json:"description,omitempty"`
	Pattern     string `json:"pattern"`
	Path        string `json:"path"`
}

Category defines a download category for auto-sorting.

func DefaultCategories

func DefaultCategories() []Category

DefaultCategories returns the default set of download categories.

func GetCategoryForFile

func GetCategoryForFile(filename string, categories []Category) (*Category, error)

GetCategoryForFile returns the last matching category so user-added rules can override broader defaults that appear earlier in the list.

func (*Category) Validate

func (c *Category) Validate() error

type CategorySettings added in v0.8.0

type CategorySettings struct {
	CategoryEnabled *Setting   `json:"category_enabled"`
	Categories      []Category `json:"categories"`
}

type ExtensionSettings added in v0.8.0

type ExtensionSettings struct {
	ExtensionPrompt     *Setting `json:"extension_prompt"`
	ChromeExtensionURL  *Setting `json:"chrome_extension_url"`
	FirefoxExtensionURL *Setting `json:"firefox_extension_url"`
	AuthToken           *Setting `json:"auth_token"`
	InstructionsURL     *Setting `json:"instructions_url"`
}

type GeneralSettings

type GeneralSettings struct {
	DefaultDownloadDir           *Setting `json:"default_download_dir"`
	WarnOnDuplicate              *Setting `json:"warn_on_duplicate"`
	DownloadCompleteNotification *Setting `json:"download_complete_notification"`
	AllowRemoteOpenActions       *Setting `json:"allow_remote_open_actions"`
	AutoResume                   *Setting `json:"auto_resume"`
	AutoStart                    *Setting `json:"auto_start"`
	SkipUpdateCheck              *Setting `json:"skip_update_check"`
	ClipboardMonitor             *Setting `json:"clipboard_monitor"`
	Theme                        *Setting `json:"theme"`
	ThemePath                    *Setting `json:"theme_path"`
	LogRetentionCount            *Setting `json:"log_retention_count"`
	LiveSpeedGraph               *Setting `json:"live_speed_graph"`
}

type NetworkSettings

type NetworkSettings struct {
	MaxConnectionsPerDownload *Setting `json:"max_connections_per_host"`
	MaxConcurrentDownloads    *Setting `json:"max_concurrent_downloads"`
	MaxConcurrentProbes       *Setting `json:"max_concurrent_probes"`
	UserAgent                 *Setting `json:"user_agent"`
	ProxyURL                  *Setting `json:"proxy_url"`
	CustomDNS                 *Setting `json:"custom_dns"`
	SequentialDownload        *Setting `json:"sequential_download"`
	MinChunkSize              *Setting `json:"min_chunk_size"`
	WorkerBufferSize          *Setting `json:"worker_buffer_size"`
	DialHedgeCount            *Setting `json:"dial_hedge_count"`
}

type PerformanceSettings

type PerformanceSettings struct {
	MaxTaskRetries        *Setting `json:"max_task_retries"`
	SlowWorkerThreshold   *Setting `json:"slow_worker_threshold"`
	SlowWorkerGracePeriod *Setting `json:"slow_worker_grace_period"`
	StallTimeout          *Setting `json:"stall_timeout"`
	SpeedEmaAlpha         *Setting `json:"speed_ema_alpha"`
}

type Setting added in v0.8.7

type Setting struct {
	Key          string `json:"key"`
	Label        string `json:"label"`
	Description  string `json:"description"`
	NeedsRestart bool   `json:"needs_restart"`
	Type         string `json:"type"` // "string", "int", "bool", "float64", "duration", "int64", "auth_token", "link"

	Value        any `json:"value"`
	DefaultValue any `json:"default_value"`

	// ValidateFunc is a custom validator for this setting.
	ValidateFunc func(val any) error `json:"-"`
}

Setting represents a single application configuration option. It encapsulates the live value, its default fallback, UI/CLI metadata, reboot triggers, and localized validation logic into a unified, self-contained unit. This architecture decouples setting definitions from static struct fields, allowing dynamic schema resolution, introspection, and centralized validation.

func (*Setting) MarshalJSON added in v0.8.7

func (s *Setting) MarshalJSON() ([]byte, error)

MarshalJSON serializes only the primitive value of this setting.

func (*Setting) Resolve added in v0.8.7

func (s *Setting) Resolve() any

Resolve returns the setting's value dynamically converted to its schema-defined target type. This ensures that unmarshaled types (like float64) are resolved back to their correct Go types (int, duration, etc.) and can be accessed safely as any.

func (*Setting) UnmarshalJSON added in v0.8.7

func (s *Setting) UnmarshalJSON(data []byte) error

UnmarshalJSON updates only the Value field of the initialized pointer.

func (*Setting) Validate added in v0.8.7

func (s *Setting) Validate(val any) error

Validate checks the given value against any custom validation rule.

type SettingMeta

type SettingMeta struct {
	Key             string // JSON key name
	Label           string // Human-readable label
	Description     string // Help text displayed in right pane
	Type            string // "string", "int", "int64", "bool", "duration", "float64", "auth_token", "link"
	RequiresRestart bool   // Whether changing this setting requires an application restart
}

SettingMeta provides metadata for a single setting (for UI rendering).

type Settings

type Settings struct {
	General     GeneralSettings     `json:"general"`
	Network     NetworkSettings     `json:"network"`
	Performance PerformanceSettings `json:"performance"`
	Categories  CategorySettings    `json:"categories"`
	Extension   ExtensionSettings   `json:"extension"`

	// Schema-driven categories list populated on initialization
	CategoriesList []*SettingsCategory `json:"-"`

	StartupWarnings []string `json:"-"`
}

func DefaultSettings

func DefaultSettings() *Settings

DefaultSettings returns a new Settings instance with sensible defaults.

func LoadSettings

func LoadSettings() (*Settings, error)

LoadSettings loads settings from disk. Returns defaults if file doesn't exist or if the JSON is corrupt, so the application can always start.

func (*Settings) Clone added in v0.8.7

func (s *Settings) Clone() *Settings

Clone returns a deep copy of the settings.

func (*Settings) ToRuntimeConfig

func (s *Settings) ToRuntimeConfig() *types.RuntimeConfig

ToRuntimeConfig creates the engine runtime config from validated settings.

func (*Settings) Validate added in v0.8.4

func (s *Settings) Validate() []string

type SettingsCategory added in v0.8.7

type SettingsCategory struct {
	Name     string     `json:"name"`
	Settings []*Setting `json:"settings"`
}

SettingsCategory represents a group of related Setting options.

Jump to

Keyboard shortcuts

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