Add callbacks, crescendo sound and better configs
This commit is contained in:
72
db/db.go
72
db/db.go
@@ -207,22 +207,36 @@ type Settings struct {
|
||||
ServerPassword string // Password for authenticating to remote server
|
||||
APIPassword string // Password required for incoming API requests (host mode)
|
||||
PollSeconds int // How often to poll server in client mode
|
||||
|
||||
// Crescendo volume control (PulseAudio)
|
||||
CrescendoEnabled bool // Whether to gradually raise volume
|
||||
CrescendoStartPct int // Starting volume percentage (0-100)
|
||||
CrescendoEndPct int // Ending volume percentage (0-100)
|
||||
CrescendoDurationS int // Seconds to ramp from start to end
|
||||
|
||||
// Callback script
|
||||
CallbackScript string // Path to script called on alarm events (start, dismiss, snooze)
|
||||
}
|
||||
|
||||
func DefaultSettings() Settings {
|
||||
return Settings{
|
||||
SnoozeMinutes: 5,
|
||||
TimeoutMinutes: 5,
|
||||
DefaultSound: "default",
|
||||
BlinkOnMs: 1000,
|
||||
BlinkOffMs: 500,
|
||||
ColorClock: "#00FF88",
|
||||
ColorAlarm: "#FF4444",
|
||||
ShowSeconds: true,
|
||||
ServerURL: "",
|
||||
ServerPassword: "",
|
||||
APIPassword: "",
|
||||
PollSeconds: 5,
|
||||
SnoozeMinutes: 5,
|
||||
TimeoutMinutes: 5,
|
||||
DefaultSound: "default",
|
||||
BlinkOnMs: 1000,
|
||||
BlinkOffMs: 500,
|
||||
ColorClock: "#00FF88",
|
||||
ColorAlarm: "#FF4444",
|
||||
ShowSeconds: true,
|
||||
ServerURL: "",
|
||||
ServerPassword: "",
|
||||
APIPassword: "",
|
||||
PollSeconds: 5,
|
||||
CrescendoEnabled: false,
|
||||
CrescendoStartPct: 20,
|
||||
CrescendoEndPct: 100,
|
||||
CrescendoDurationS: 60,
|
||||
CallbackScript: "",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,23 +254,33 @@ func (s *Store) LoadSettings() Settings {
|
||||
cfg.ServerPassword = s.GetSetting("server_password", cfg.ServerPassword)
|
||||
cfg.APIPassword = s.GetSetting("api_password", cfg.APIPassword)
|
||||
cfg.PollSeconds = s.getSettingInt("poll_seconds", cfg.PollSeconds)
|
||||
cfg.CrescendoEnabled = s.GetSetting("crescendo_enabled", "false") == "true"
|
||||
cfg.CrescendoStartPct = s.getSettingInt("crescendo_start_pct", cfg.CrescendoStartPct)
|
||||
cfg.CrescendoEndPct = s.getSettingInt("crescendo_end_pct", cfg.CrescendoEndPct)
|
||||
cfg.CrescendoDurationS = s.getSettingInt("crescendo_duration_s", cfg.CrescendoDurationS)
|
||||
cfg.CallbackScript = s.GetSetting("callback_script", cfg.CallbackScript)
|
||||
return cfg
|
||||
}
|
||||
|
||||
func (s *Store) SaveSettings(cfg Settings) error {
|
||||
pairs := map[string]string{
|
||||
"snooze_minutes": fmt.Sprintf("%d", cfg.SnoozeMinutes),
|
||||
"timeout_minutes": fmt.Sprintf("%d", cfg.TimeoutMinutes),
|
||||
"default_sound": cfg.DefaultSound,
|
||||
"blink_on_ms": fmt.Sprintf("%d", cfg.BlinkOnMs),
|
||||
"blink_off_ms": fmt.Sprintf("%d", cfg.BlinkOffMs),
|
||||
"color_clock": cfg.ColorClock,
|
||||
"color_alarm": cfg.ColorAlarm,
|
||||
"show_seconds": fmt.Sprintf("%t", cfg.ShowSeconds),
|
||||
"server_url": cfg.ServerURL,
|
||||
"server_password": cfg.ServerPassword,
|
||||
"api_password": cfg.APIPassword,
|
||||
"poll_seconds": fmt.Sprintf("%d", cfg.PollSeconds),
|
||||
"snooze_minutes": fmt.Sprintf("%d", cfg.SnoozeMinutes),
|
||||
"timeout_minutes": fmt.Sprintf("%d", cfg.TimeoutMinutes),
|
||||
"default_sound": cfg.DefaultSound,
|
||||
"blink_on_ms": fmt.Sprintf("%d", cfg.BlinkOnMs),
|
||||
"blink_off_ms": fmt.Sprintf("%d", cfg.BlinkOffMs),
|
||||
"color_clock": cfg.ColorClock,
|
||||
"color_alarm": cfg.ColorAlarm,
|
||||
"show_seconds": fmt.Sprintf("%t", cfg.ShowSeconds),
|
||||
"server_url": cfg.ServerURL,
|
||||
"server_password": cfg.ServerPassword,
|
||||
"api_password": cfg.APIPassword,
|
||||
"poll_seconds": fmt.Sprintf("%d", cfg.PollSeconds),
|
||||
"crescendo_enabled": fmt.Sprintf("%t", cfg.CrescendoEnabled),
|
||||
"crescendo_start_pct": fmt.Sprintf("%d", cfg.CrescendoStartPct),
|
||||
"crescendo_end_pct": fmt.Sprintf("%d", cfg.CrescendoEndPct),
|
||||
"crescendo_duration_s": fmt.Sprintf("%d", cfg.CrescendoDurationS),
|
||||
"callback_script": cfg.CallbackScript,
|
||||
}
|
||||
for k, v := range pairs {
|
||||
if err := s.SetSetting(k, v); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user