feat: add backend configuration and windows utilities, and initialize frontend dependencies

This commit is contained in:
jahruz67
2026-05-15 10:39:30 -07:00
parent e645102d3a
commit b0f4ea3e6f
43 changed files with 931 additions and 541 deletions
+25 -4
View File
@@ -29,6 +29,7 @@ type HistoryItem struct {
// Config represents the complete application configuration.
type Config struct {
Version int `json:"version"`
APIKey string `json:"api_key"`
Shortcut string `json:"shortcut"`
WhisperModel string `json:"whisper_model"`
@@ -39,6 +40,9 @@ type Config struct {
History []HistoryItem `json:"history"`
}
const CurrentConfigVersion = 1
const MaxHistoryItems = 100
// DefaultConfig returns a new configuration with sensible default values.
func DefaultConfig() *Config {
return &Config{
@@ -70,12 +74,21 @@ func Load(configPath string) (*Config, error) {
return nil, err
}
// Apply defaults for any missing fields
// Apply defaults and migrations
cfg.migrate()
cfg.applyDefaults()
return &cfg, nil
}
// migrate handles version-based configuration upgrades
func (c *Config) migrate() {
if c.Version < CurrentConfigVersion {
// Migration logic for future versions goes here
c.Version = CurrentConfigVersion
}
}
// Save writes the configuration to the specified file path.
// If configPath is empty, it uses the default configuration path.
func Save(c *Config, configPath string) error {
@@ -134,12 +147,20 @@ func (c *Config) applyDefaults() {
}
}
// AddHistoryItem adds a new transcription to the history.
// AddHistoryItem adds a new transcription to the history, enforcing a maximum limit.
func (c *Config) AddHistoryItem(text, timestamp string) {
c.History = append(c.History, HistoryItem{
newItem := HistoryItem{
Text: text,
Timestamp: timestamp,
})
}
// Prepend to history so the newest items are at the top
c.History = append([]HistoryItem{newItem}, c.History...)
// Bounded history: keep only the most recent items
if len(c.History) > MaxHistoryItems {
c.History = c.History[:MaxHistoryItems]
}
}
// ClearHistory removes all history items.