Files
vmux/notify.go
Pierre Martin 001c453462 fix: improve state detection accuracy and notification UX
- Hook reads JSON from stdin (not env vars) matching Claude Code protocol
- end_turn = Idle (not NeedsInput); real questions come from hooks
- Permission prompt (stale tool_use) never becomes Idle
- Notifications auto-expire after 10s (--expire-time)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-24 11:29:26 +01:00

46 lines
953 B
Go

package main
import (
"context"
"os/exec"
"path/filepath"
"time"
)
// Notifier sends desktop notifications.
type Notifier interface {
Notify(title, body string) error
}
// ExecNotifier calls notify-send via os/exec.
type ExecNotifier struct{}
func (n *ExecNotifier) Notify(title, body string) error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
return exec.CommandContext(ctx, "notify-send",
"--urgency=critical",
"--app-name=vmux",
"--expire-time=10000",
title,
body,
).Run()
}
// NullNotifier discards all notifications (for tests and focus mode).
type NullNotifier struct{}
func (n *NullNotifier) Notify(_, _ string) error {
return nil
}
// shortName returns a human-readable short name for a session.
// Prefers Label if set, otherwise uses the last component of Cwd.
func shortName(s SessionInfo) string {
if s.Label != "" {
return s.Label
}
return filepath.Base(s.Cwd)
}