Add callbacks, crescendo sound and better configs

This commit is contained in:
2026-02-04 20:55:03 +02:00
parent cdcdf2c644
commit 621815ed0f
5 changed files with 235 additions and 33 deletions

View File

@@ -2,6 +2,7 @@ package ui
import (
"fmt"
"os/exec"
"strings"
"time"
"woke/db"
@@ -200,6 +201,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case autoTimeoutMsg:
if m.firingAlarm != nil {
m.player.Stop()
m.runCallback("timeout", m.firingAlarm.Name)
m.statusMsg = fmt.Sprintf("Alarm auto-dismissed after %d minutes", m.settings.TimeoutMinutes)
m.firingAlarm = nil
m.snoozeCount = 0
@@ -232,12 +234,14 @@ func (m Model) handleKey(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
case "enter", " ", "d":
m.player.Stop()
alarm := m.firingAlarm
m.runCallback("dismiss", alarm.Name)
m.firingAlarm = nil
m.snoozeCount = 0
m.statusMsg = fmt.Sprintf("Alarm '%s' dismissed", alarm.Name)
case "s":
m.player.Stop()
alarm := *m.firingAlarm
m.runCallback("snooze", alarm.Name)
dur := m.snoozeDuration()
m.firingAlarm = nil
m.snoozeUntil = time.Now().Add(dur)
@@ -342,7 +346,30 @@ func (m *Model) startFiring(alarm *db.Alarm) {
if sound == "default" || sound == "" {
sound = m.settings.DefaultSound
}
m.player.PlayLoop(sound)
// Use crescendo if enabled
cresc := player.CrescendoConfig{
Enabled: m.settings.CrescendoEnabled,
StartPct: m.settings.CrescendoStartPct,
EndPct: m.settings.CrescendoEndPct,
DurationS: m.settings.CrescendoDurationS,
}
m.player.PlayLoopWithCrescendo(sound, cresc)
// Fire callback
m.runCallback("start", alarm.Name)
}
// runCallback executes the configured callback script with the event type and alarm name.
func (m *Model) runCallback(event, alarmName string) {
script := m.settings.CallbackScript
if script == "" {
return
}
// Run in background, don't block
go func() {
_ = exec.Command(script, event, alarmName).Run()
}()
}
func snoozeCmd(alarm db.Alarm, after time.Duration) tea.Cmd {