- 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
39 lines
755 B
Go
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
|
|
}
|