Files
vmux/focus.go
Pierre Martin b96c6d05be feat(04-01): add Notifier interface and FocusTimer
- Notifier interface with ExecNotifier (notify-send) and NullNotifier
- FocusTimer thread-safe with Set/IsActive/Remaining
- shortName helper for session display names
- Full test coverage for all components
2026-03-23 21:23:57 +01:00

39 lines
755 B
Go

package main
import (
"sync"
"time"
)
// FocusTimer suppresses notifications for a configurable duration.
// Thread-safe via mutex.
type FocusTimer struct {
mu sync.Mutex
expires time.Time
}
// Set activates focus mode for duration d.
func (f *FocusTimer) Set(d time.Duration) {
f.mu.Lock()
defer f.mu.Unlock()
f.expires = time.Now().Add(d)
}
// IsActive returns true if focus mode has not expired.
func (f *FocusTimer) IsActive() bool {
f.mu.Lock()
defer f.mu.Unlock()
return time.Now().Before(f.expires)
}
// Remaining returns how much focus time is left. Returns 0 if expired.
func (f *FocusTimer) Remaining() time.Duration {
f.mu.Lock()
defer f.mu.Unlock()
rem := time.Until(f.expires)
if rem < 0 {
return 0
}
return rem
}