Stop discarding Steam toasts on root defunct

This commit is contained in:
hjozwiak committed 2026-11-11 06:56:15 -05:00
1 parent 04a1070055
commit 469ed7c549
6 files changed
+54 -41

No files matched your search

+6 -2
View File
@@ -29,10 +29,14 @@ type webScriptController struct {
}
func (controller *webScriptController) handle(event atspi.Event) bool {
retiring := event.Type == atspi.WindowDestroyedEvent || event.Type == atspi.DefunctStateEvent && event.Detail1 != 0
// Only a destroyed window retires delayed content. Steam/CEF reports
// the toast root defunct after every fragment insertion, and the
// captured text is already copied, so root defunct must not discard a
// pending notification before its coalescing deadline.
retiring := event.Type == atspi.WindowDestroyedEvent
if retiring {
id := event.Source.ID()
if event.Type == atspi.WindowDestroyedEvent && event.Window.Valid() {
if event.Window.Valid() {
id = event.Window
}
controller.registry.Retire(id.BusName, id.Path)
+38 -6
View File
@@ -84,8 +84,8 @@ func TestSteamBackgroundNotificationReachesSpeechBrailleAndHistory(t *testing.T)
}
}
func TestSteamNotificationTimerCancelledOnLockAndDestruction(t *testing.T) {
for _, retire := range []string{"lock", "root", "window"} {
func TestSteamNotificationTimerCancelledOnLockAndWindowDestruction(t *testing.T) {
for _, retire := range []string{"lock", "window"} {
t.Run(retire, func(t *testing.T) {
queue := &fakeSpeechQueue{spoken: make(chan string, 1)}
history := notification.NewPresenter()
@@ -99,10 +99,6 @@ func TestSteamNotificationTimerCancelledOnLockAndDestruction(t *testing.T) {
case "lock":
gate.secure.Store(true)
controller.flush()
case "root":
event := atspi.NewEvent(atspi.DefunctStateEvent, atspi.Snapshot{BusName: ":1.42", Path: "/toast"})
event.Detail1 = 1
controller.handle(event)
case "window":
controller.handle(atspi.NewEvent(atspi.WindowDestroyedEvent, atspi.Snapshot{BusName: ":1.42", Path: "/steam"}))
}
@@ -112,3 +108,39 @@ func TestSteamNotificationTimerCancelledOnLockAndDestruction(t *testing.T) {
})
}
}
func TestSteamNotificationSurvivesToastRootDefunct(t *testing.T) {
queue := &fakeSpeechQueue{spoken: make(chan string, 1)}
history := notification.NewPresenter()
controller := &webScriptController{speech: queue, notifications: history, gate: &focusGate{}}
defer controller.reset()
if !controller.handle(steamToastEvent("Username is now online")) || controller.due == nil {
t.Fatal("toast did not arm a timer")
}
// Steam/CEF reports the toast root defunct after every fragment
// insertion, long before the coalescing deadline. The captured text
// must survive it.
event := atspi.NewEvent(atspi.DefunctStateEvent, atspi.Snapshot{BusName: ":1.42", Path: "/toast"})
event.Detail1 = 1
controller.handle(event)
if controller.due == nil || controller.registry.Deadline().IsZero() {
t.Fatal("toast root defunct discarded pending toast")
}
select {
case <-controller.due:
case <-time.After(2 * time.Second):
t.Fatal("toast timer did not fire")
}
controller.flush()
select {
case text := <-queue.spoken:
if text != "Steam: Username is now online" {
t.Fatalf("spoken toast: %q", text)
}
default:
t.Fatal("toast was not spoken after root defunct")
}
if entries := history.Entries(); len(entries) != 1 || entries[0].Message != "Steam: Username is now online" {
t.Fatalf("notification history: %+v", entries)
}
}