feat(notify): Cancel button on Windows toasts via the talk: protocol handler

Windows toasts cannot call back into the daemon, so the Cancel button opens
a talk: link instead: `talk:cancel?id=<id>&port=<port>`. The daemon
registers the talk: URL protocol for the current user (HKCU, no admin) and
points it at `talk uri "%1"`; Windows starts that on the click, and `talk
uri` posts to the new endpoint POST /cancel-item, which cancels only the
announcement with that id (queue.CancelItem). The toast is tagged and
removed again when the announcement ends. For now the toast is shown under
Windows PowerShell's app identity, which unpackaged programs can use
without a Start Menu shortcut.

Verified on the Windows 11 VM: registry entry written by the daemon,
Start-Process "talk:cancel?id=…&port=7800" (what the button does) stops
the playing announcement within two seconds, no toast errors in the log.

Tests: `talk uri` against a real handler on a loopback port (playing vs
waiting id, dead daemon, talk:test, garbage links), POST /cancel-item
process test (only the playing item, waiting one plays next, 400 without
id).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
m3ta-chironandClaude Fable 5.1 committed 2026-10-24 12:14:38 +02:00
1 parent 83a15af9c5
commit 00eb76128b
16 files changed
+446 -22

No files matched your search

+15
View File
@@ -535,3 +535,18 @@ func mcpDecode(t *testing.T, raw rawResponse) map[string]any {
}
return m
}
// postJSON POSTs a JSON body to a daemon endpoint and decodes the reply.
func postJSON(t *testing.T, d *daemonProc, path, body string) (int, map[string]any) {
t.Helper()
resp, err := http.Post(d.baseURL+path, "application/json", strings.NewReader(body))
if err != nil {
t.Fatalf("POST %s: %v", path, err)
}
defer resp.Body.Close()
var m map[string]any
if err := json.NewDecoder(resp.Body).Decode(&m); err != nil {
t.Fatalf("decoding POST %s reply: %v", path, err)
}
return resp.StatusCode, m
}
+36
View File
@@ -271,3 +271,39 @@ func TestStatusContract(t *testing.T) {
t.Errorf("provider = %q, want elevenlabs", st.Provider)
}
}
// TestCancelItemEndpoint: POST /cancel-item cancels only the playing
// announcement with that id; waiting items stay and play next; a stale id
// yields cancelled:false, a missing id 400.
func TestCancelItemEndpoint(t *testing.T) {
root := t.TempDir()
fake := newFakeProvider(t, 5*time.Second)
d := startDaemon(t, root, fake.srv.URL, nil)
_, first := speak(t, d, `{"text":"blocker"}`)
fake.waitArrived(t, 1)
_, second := speak(t, d, `{"text":"waiting"}`)
code, m := postJSON(t, d, "/cancel-item", `{"id":"`+second["id"].(string)+`"}`)
if code != 200 || m["cancelled"] != false {
t.Fatalf("cancel-item on the waiting id: %d %v, want cancelled:false", code, m)
}
code, m = postJSON(t, d, "/cancel-item", `{"id":"`+first["id"].(string)+`"}`)
if code != 200 || m["cancelled"] != true {
t.Fatalf("cancel-item on the playing id: %d %v, want cancelled:true", code, m)
}
hits := fake.waitHits(t, 1)
if hits[0].Completed {
t.Errorf("blocker synthesis completed although cancelled: %+v", hits[0])
}
// The waiting item plays next (the queue was not emptied).
fake.setDelay(50 * time.Millisecond)
done := fake.waitCompleted(t, 1)
if done[0].Text != "waiting" {
t.Errorf("next completed = %q, want the waiting announcement", done[0].Text)
}
if code, m := postJSON(t, d, "/cancel-item", `{}`); code != 400 || m["error"] == nil {
t.Errorf("cancel-item without id: %d %v, want 400 with error", code, m)
}
waitStatusIdle(t, d, 3*time.Second)
}