-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.go
More file actions
118 lines (96 loc) · 2.97 KB
/
settings.go
File metadata and controls
118 lines (96 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package main
import (
"context"
"encoding/json"
"os"
"path/filepath"
"sync"
"wails-cast/pkg/folders"
)
const (
settingsFileName = "settings.json"
)
func getDefaultSettings() Settings {
return Settings{
SubtitleBurnIn: true,
IgnoreClosedCaptions: false,
DefaultTranslationLanguage: "English",
GeminiApiKey: "",
GeminiModel: "gemini-2.5-flash",
DefaultQuality: "5M",
SubtitleFontSize: 24,
MaxOutputWidth: 0,
TranslatePromptTemplate: "Create a subtitle translation in {{.TargetLanguage}} based on the references in other languages.\nMultiple language tracks from the same video are provided as reference to help you understand context and maintain consistent terminology.\n\nInput format:\ndelay: <seconds>\nduration: <seconds>\n<text>\n\n{{.SubtitleContent}}\n\nOutput the translation in the same format inside <llm_output></llm_output> tags.",
MaxSubtitleSamples: 4,
NoTranscodeCache: false,
}
}
type Settings struct {
SubtitleBurnIn bool `json:"subtitleBurnIn"`
IgnoreClosedCaptions bool `json:"ignoreClosedCaptions"`
DefaultTranslationLanguage string `json:"defaultTranslationLanguage"`
GeminiApiKey string `json:"geminiApiKey"`
GeminiModel string `json:"geminiModel"`
DefaultQuality string `json:"defaultQuality"`
SubtitleFontSize int `json:"subtitleFontSize"`
MaxOutputWidth int `json:"maxOutputWidth"`
TranslatePromptTemplate string `json:"translatePromptTemplate"`
MaxSubtitleSamples int `json:"maxSubtitleSamples"`
NoTranscodeCache bool `json:"noTranscodeCache"`
}
type SettingsStore struct {
settings Settings
filePath string
ctx context.Context
mu sync.RWMutex
}
func NewSettingsStore() *SettingsStore {
appConfigDir := folders.GetConfig()
os.MkdirAll(appConfigDir, 0755)
settingsPath := filepath.Join(appConfigDir, settingsFileName)
store := &SettingsStore{
settings: getDefaultSettings(),
filePath: settingsPath,
}
store.load()
return store
}
func (s *SettingsStore) SetContext(ctx context.Context) {
s.ctx = ctx
}
func (s *SettingsStore) load() error {
s.mu.Lock()
defer s.mu.Unlock()
data, err := os.ReadFile(s.filePath)
if err != nil {
if os.IsNotExist(err) {
return nil // No settings file yet, use defaults
}
return err
}
return json.Unmarshal(data, &s.settings)
}
func (s *SettingsStore) save() error {
data, err := json.MarshalIndent(s.settings, "", " ")
if err != nil {
return err
}
return os.WriteFile(s.filePath, data, 0644)
}
func (s *SettingsStore) Get() *Settings {
s.mu.RLock()
defer s.mu.RUnlock()
return &s.settings
}
func (s *SettingsStore) Update(settings Settings) error {
s.mu.Lock()
defer s.mu.Unlock()
s.settings = settings
return s.save()
}
func (s *SettingsStore) Reset() error {
s.mu.Lock()
defer s.mu.Unlock()
s.settings = getDefaultSettings()
return s.save()
}