Documentation
¶
Index ¶
- Constants
- func CategoryNames(categories []Category) []string
- func CategoryOrder() []string
- func EnsureDirs() error
- func GetDocumentsDir() string
- func GetDownloadsDir() string
- func GetLogsDir() string
- func GetMusicDir() string
- func GetPicturesDir() string
- func GetRuntimeDir() string
- func GetSettingsMetadata() map[string][]SettingMeta
- func GetSettingsPath() string
- func GetStateDir() string
- func GetSurgeDir() string
- func GetSystemRuntimeDir() string
- func GetSystemStateDir() string
- func GetSystemSurgeDir() string
- func GetThemesDir() string
- func GetVideosDir() string
- func Resolve[T any](s *Setting) T
- func ResolveCategoryPath(cat *Category, defaultDownloadDir string) string
- func SaveSettings(s *Settings) error
- func ValidateDNSList(s string) error
- type Category
- type CategorySettings
- type ExtensionSettings
- type GeneralSettings
- type NetworkSettings
- type PerformanceSettings
- type Setting
- type SettingMeta
- type Settings
- type SettingsCategory
Constants ¶
const ( KB = 1 << 10 MB = 1 << 20 )
const ( ThemeAdaptive = 0 ThemeLight = 1 ThemeDark = 2 )
Variables ¶
This section is empty.
Functions ¶
func CategoryNames ¶
CategoryNames returns a slice of category names.
func CategoryOrder ¶
func CategoryOrder() []string
CategoryOrder returns the order of categories for UI tabs.
func GetDocumentsDir ¶
func GetDocumentsDir() string
func GetDownloadsDir ¶
func GetDownloadsDir() string
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
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 ¶
ResolveCategoryPath returns the Path of a category.
func SaveSettings ¶
SaveSettings saves settings to disk atomically.
func ValidateDNSList ¶ added in v0.8.4
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 ¶
GetCategoryForFile returns the last matching category so user-added rules can override broader defaults that appear earlier in the list.
type CategorySettings ¶ added in v0.8.0
type ExtensionSettings ¶ added in v0.8.0
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
MarshalJSON serializes only the primitive value of this setting.
func (*Setting) Resolve ¶ added in v0.8.7
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
UnmarshalJSON updates only the Value field of the initialized pointer.
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 ¶
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) ToRuntimeConfig ¶
func (s *Settings) ToRuntimeConfig() *types.RuntimeConfig
ToRuntimeConfig creates the engine runtime config from validated settings.
type SettingsCategory ¶ added in v0.8.7
SettingsCategory represents a group of related Setting options.