settings

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package settings manages global and per-key plugin settings.

Index

Constants

View Source
const DefaultRefreshMinutes = 15

DefaultRefreshMinutes is the built-in fallback refresh interval in minutes when neither the user nor the provider overrides it.

Variables

View Source
var RefreshPresets = []int{5, 10, 15, 30, 60}

RefreshPresets are the allowed refresh intervals in minutes.

Functions

func ChangedProviderIDs added in v0.5.0

func ChangedProviderIDs(prev, next ProviderKeys) []string

ChangedProviderIDs returns the provider IDs whose credentials or endpoint overrides differ between prev and next. Callers use this to invalidate cached provider snapshots so the next poll picks up the new configuration instead of serving stale data.

func DefaultBgColorValue added in v0.5.0

func DefaultBgColorValue() string

DefaultBgColorValue returns the plugin-wide background-color default. When set, overrides the per-provider brand bg. Empty means fall through to brand bg.

func DefaultCriticalBelowValue added in v0.5.0

func DefaultCriticalBelowValue() (float64, bool)

DefaultCriticalBelowValue — same pattern as DefaultWarnBelowValue.

func DefaultCriticalColorValue added in v0.5.0

func DefaultCriticalColorValue() string

DefaultCriticalColorValue — same pattern as DefaultWarnColorValue.

func DefaultFillColorValue added in v0.5.0

func DefaultFillColorValue() string

DefaultFillColorValue returns the plugin-wide fill-color default, or empty string when unset. When set, it overrides the per-provider brand color for meter metrics. Reference cards still use their lightened-bg trick regardless — that's a visual differentiation users don't think of as "the fill color".

func DefaultFillDirectionValue added in v0.5.0

func DefaultFillDirectionValue() string

DefaultFillDirectionValue returns the plugin-wide fill direction default ("up" / "down" / "right" / "left"), falling back to "up" when unset.

func DefaultHideSubvalueEnabled added in v0.5.0

func DefaultHideSubvalueEnabled() bool

DefaultHideSubvalueEnabled returns the plugin-wide hide-subtext default. Off by default — users typically want to see the subtext.

func DefaultShowBorderEnabled added in v0.5.0

func DefaultShowBorderEnabled() bool

DefaultShowBorderEnabled returns the plugin-wide border default, which is on when unset — matches the pre-setting behavior.

func DefaultShowRawCountsEnabled added in v0.5.0

func DefaultShowRawCountsEnabled() bool

DefaultShowRawCountsEnabled returns the plugin-wide raw-counts default. Off by default — the render path auto-enables for credit providers when the API returns counts, so a user typically only flips this on to force raw counts for a percent-only metric.

func DefaultShowResetTimerEnabled added in v0.5.0

func DefaultShowResetTimerEnabled() bool

DefaultShowResetTimerEnabled returns the plugin-wide reset-timer default, on when unset. Only has a visible effect on metrics whose type includes a timer (pct, pace).

func DefaultTextColorValue added in v0.5.0

func DefaultTextColorValue() string

DefaultTextColorValue returns the plugin-wide text default, falling back to the historical hardcoded value when unset.

func DefaultWarnBelowValue added in v0.5.0

func DefaultWarnBelowValue() (float64, bool)

DefaultWarnBelowValue returns the plugin-wide warn-threshold default and true when the user has set one. Returns (0, false) when unset, in which case the per-metric-type smart default applies.

func DefaultWarnColorValue added in v0.5.0

func DefaultWarnColorValue() string

DefaultWarnColorValue returns the plugin-wide warn color, falling back to the historical #f59e0b when unset.

func InvertFillEnabled

func InvertFillEnabled() bool

InvertFillEnabled returns the global invert-fill toggle.

func ResolveAPIKey added in v0.5.0

func ResolveAPIKey(fromUser string, envNames ...string) string

ResolveAPIKey returns the first non-empty credential from: the user-supplied value (typically a PI settings field) or the named environment variables in order. Values are trimmed and stripped of surrounding quotes. Returns "" when nothing is set.

func ResolveEndpoint added in v0.5.0

func ResolveEndpoint(fromUser string, defaultURL string, envNames ...string) string

ResolveEndpoint returns the first non-empty endpoint from: the user-supplied settings field, the named environment variables, or the provided default. Trims trailing slashes.

func ResolveRefreshMs

func ResolveRefreshMs(ks KeySettings, providerID string) int64

ResolveRefreshMs returns the effective refresh interval in ms for a key. Precedence: button RefreshMinutes -> provider RefreshMinutes -> plugin DefaultRefreshMinutes -> built-in DefaultRefreshMinutes.

func Set

func Set(gs GlobalSettings)

Set replaces the global settings, normalising values.

func ShowGlyphsEnabled

func ShowGlyphsEnabled() bool

ShowGlyphsEnabled returns the global show-glyphs toggle.

func SkipUpdateCheckEnabled

func SkipUpdateCheckEnabled() bool

SkipUpdateCheckEnabled returns the skip-update-check toggle.

func SmartContrastEnabled added in v0.5.0

func SmartContrastEnabled() bool

SmartContrastEnabled returns the global smart-contrast toggle. On by default so the out-of-box experience stays legible across provider palettes (Ollama's light fill + dark bg pair especially needs the auto-flip); users can opt out in the plugin settings tab.

Types

type GlobalSettings

type GlobalSettings struct {
	DefaultRefreshMinutes *int     `json:"defaultRefreshMinutes,omitempty"`
	DefaultValueSize      TextSize `json:"defaultValueSize,omitempty"`
	DefaultSubvalueSize   TextSize `json:"defaultSubvalueSize,omitempty"`
	DefaultTextColor      string   `json:"defaultTextColor,omitempty"`
	DefaultFillColor      string   `json:"defaultFillColor,omitempty"`
	DefaultBgColor        string   `json:"defaultBgColor,omitempty"`
	DefaultShowBorder     *bool    `json:"defaultShowBorder,omitempty"`
	DefaultFillDirection  string   `json:"defaultFillDirection,omitempty"`
	DefaultShowResetTimer *bool    `json:"defaultShowResetTimer,omitempty"`
	DefaultShowRawCounts  *bool    `json:"defaultShowRawCounts,omitempty"`
	DefaultHideSubvalue   *bool    `json:"defaultHideSubvalue,omitempty"`
	DefaultWarnBelow      *float64 `json:"defaultWarnBelow,omitempty"`
	DefaultWarnColor      string   `json:"defaultWarnColor,omitempty"`
	DefaultCriticalBelow  *float64 `json:"defaultCriticalBelow,omitempty"`
	DefaultCriticalColor  string   `json:"defaultCriticalColor,omitempty"`
	InvertFill            bool     `json:"invertFill,omitempty"`
	// SmartContrast enables the renderer's dual-layer text + glyph
	// contrast auto-flip so a user-chosen foreground that would sit on
	// a similar-luminance brand bg or fill gets auto-inverted on the
	// offending region. Off by default — users opt in via the plugin
	// settings tab when their provider palette needs it.
	SmartContrast      *bool        `json:"smartContrast,omitempty"`
	ShowGlyphs         *bool        `json:"showGlyphs,omitempty"`
	SkipUpdateCheck    bool         `json:"skipUpdateCheck,omitempty"`
	CookieHostOptedOut bool         `json:"cookieHostOptedOut,omitempty"`
	ProviderKeys       ProviderKeys `json:"providerKeys,omitempty"`
	// ProviderSettings are per-provider overrides that sit between the
	// plugin-wide defaults above and the per-button KeySettings. Only
	// fields that make sense at the provider tier are overridable —
	// see ProviderSettings for the set. Keyed by provider ID ("claude",
	// "codex", "zai", ...).
	ProviderSettings map[string]ProviderSettings `json:"providerSettings,omitempty"`
}

GlobalSettings are shared across every key and persisted by Stream Deck (survive plugin rebuilds, ride with user profiles).

func Get

func Get() GlobalSettings

Get returns the current global settings.

type KeySettings

type KeySettings struct {
	// Provider is now derived from action UUID; this field is
	// kept for backwards compat but ignored.
	ProviderID      string   `json:"providerId,omitempty"`
	MetricID        string   `json:"metricId,omitempty"`
	RefreshMinutes  *int     `json:"refreshMinutes,omitempty"`
	WarnBelow       *float64 `json:"warnBelow,omitempty"`
	CriticalBelow   *float64 `json:"criticalBelow,omitempty"`
	WarnColor       string   `json:"warnColor,omitempty"`
	CriticalColor   string   `json:"criticalColor,omitempty"`
	LabelOverride   string   `json:"labelOverride,omitempty"`
	HideLabel       bool     `json:"hideLabel,omitempty"`
	CaptionOverride string   `json:"captionOverride,omitempty"`
	FillColor       string   `json:"fillColor,omitempty"`
	BgColor         string   `json:"bgColor,omitempty"`
	TextColor       string   `json:"textColor,omitempty"`
	FillDirection   string   `json:"fillDirection,omitempty"`
	ValueSize       TextSize `json:"valueSize,omitempty"`
	SubvalueSize    TextSize `json:"subvalueSize,omitempty"`
	ShowBorder      *bool    `json:"showBorder,omitempty"`
	ShowGlyph       *bool    `json:"showGlyph,omitempty"`
	ShowResetTimer  *bool    `json:"showResetTimer,omitempty"`
	ShowRawCounts   *bool    `json:"showRawCounts,omitempty"`
	HideSubvalue    *bool    `json:"hideSubvalue,omitempty"`
}

KeySettings are per-button settings stored by Stream Deck.

func EffectiveSettings added in v0.5.0

func EffectiveSettings(ks KeySettings, providerID string) KeySettings

EffectiveSettings merges provider-tier overrides under per-button settings so the caller sees a single resolved KeySettings. Per-button values win; provider overrides fill in any fields the button didn't set; plugin-wide defaults are applied at read time by the individual getters (DefaultValueSz, ResolveRefreshMs, ...). This keeps the precedence chain plugin -> provider -> button without every call site having to walk it.

type ProviderKeys added in v0.5.0

type ProviderKeys struct {
	// API keys / tokens
	OpenRouterKey string `json:"openRouterKey,omitempty"`
	WarpKey       string `json:"warpKey,omitempty"`
	ZaiKey        string `json:"zaiKey,omitempty"`
	KimiK2Key     string `json:"kimiK2Key,omitempty"`
	CopilotToken  string `json:"copilotToken,omitempty"`

	// Endpoint overrides
	OpenRouterURL       string `json:"openRouterURL,omitempty"`
	ZaiHost             string `json:"zaiHost,omitempty"`
	ZaiQuotaURL         string `json:"zaiQuotaURL,omitempty"`
	ZaiRegion           string `json:"zaiRegion,omitempty"` // "global" | "bigmodel-cn"
	CodexChatGPTBaseURL string `json:"codexChatGPTBaseURL,omitempty"`
}

ProviderKeys holds user-entered credentials and endpoint overrides from the Property Inspector. Fields are empty when the user hasn't provided one; resolvers fall back to environment variables in that case. Persisted by Stream Deck in the global settings blob, so survives plugin rebuilds.

func ProviderKeysGet added in v0.5.0

func ProviderKeysGet() ProviderKeys

ProviderKeysGet returns a snapshot of the per-provider credential and endpoint overrides from global settings.

type ProviderSettings added in v0.5.0

type ProviderSettings struct {
	RefreshMinutes *int     `json:"refreshMinutes,omitempty"`
	WarnBelow      *float64 `json:"warnBelow,omitempty"`
	CriticalBelow  *float64 `json:"criticalBelow,omitempty"`
	WarnColor      string   `json:"warnColor,omitempty"`
	CriticalColor  string   `json:"criticalColor,omitempty"`
	FillColor      string   `json:"fillColor,omitempty"`
	BgColor        string   `json:"bgColor,omitempty"`
	TextColor      string   `json:"textColor,omitempty"`
	FillDirection  string   `json:"fillDirection,omitempty"`
	ValueSize      TextSize `json:"valueSize,omitempty"`
	SubvalueSize   TextSize `json:"subvalueSize,omitempty"`
	ShowBorder     *bool    `json:"showBorder,omitempty"`
	ShowGlyph      *bool    `json:"showGlyph,omitempty"`
	ShowResetTimer *bool    `json:"showResetTimer,omitempty"`
	ShowRawCounts  *bool    `json:"showRawCounts,omitempty"`
	HideSubvalue   *bool    `json:"hideSubvalue,omitempty"`
}

ProviderSettings carries per-provider overrides. Every field is optional; an unset field means "inherit from the plugin default". At render time these values are merged under the per-button KeySettings via EffectiveSettings, so a field set here applies to every button for that provider unless the button overrides it too.

type TextSize

type TextSize string

TextSize is the discriminator for value / subvalue font-size buckets exposed in the Property Inspector.

const (
	// TextSmall is the small text-size preset persisted by the PI.
	TextSmall TextSize = "small"
	// TextMedium is the medium text-size preset persisted by the PI.
	TextMedium TextSize = "medium"
	// TextLarge is the large text-size preset persisted by the PI.
	TextLarge TextSize = "large"
)

TextSize presets. Values match the strings the PI persists.

func DefaultSubvalueSz

func DefaultSubvalueSz() TextSize

DefaultSubvalueSz returns the global default subvalue text size.

func DefaultValueSz

func DefaultValueSz() TextSize

DefaultValueSz returns the global default value text size.

Jump to

Keyboard shortcuts

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