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 { 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 { if retiring {
id := event.Source.ID() id := event.Source.ID()
if event.Type == atspi.WindowDestroyedEvent && event.Window.Valid() { if event.Window.Valid() {
id = event.Window id = event.Window
} }
controller.registry.Retire(id.BusName, id.Path) 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) { func TestSteamNotificationTimerCancelledOnLockAndWindowDestruction(t *testing.T) {
for _, retire := range []string{"lock", "root", "window"} { for _, retire := range []string{"lock", "window"} {
t.Run(retire, func(t *testing.T) { t.Run(retire, func(t *testing.T) {
queue := &fakeSpeechQueue{spoken: make(chan string, 1)} queue := &fakeSpeechQueue{spoken: make(chan string, 1)}
history := notification.NewPresenter() history := notification.NewPresenter()
@@ -99,10 +99,6 @@ func TestSteamNotificationTimerCancelledOnLockAndDestruction(t *testing.T) {
case "lock": case "lock":
gate.secure.Store(true) gate.secure.Store(true)
controller.flush() controller.flush()
case "root":
event := atspi.NewEvent(atspi.DefunctStateEvent, atspi.Snapshot{BusName: ":1.42", Path: "/toast"})
event.Detail1 = 1
controller.handle(event)
case "window": case "window":
controller.handle(atspi.NewEvent(atspi.WindowDestroyedEvent, atspi.Snapshot{BusName: ":1.42", Path: "/steam"})) 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)
}
}
-1
View File
@@ -117,7 +117,6 @@ type Adapter struct {
captureLogger atomic.Pointer[slog.Logger] captureLogger atomic.Pointer[slog.Logger]
libreOfficeHeaders libreOfficeHeaderStore // copied choices shared with the event loop libreOfficeHeaders libreOfficeHeaderStore // copied choices shared with the event loop
applicationProcesses map[string]string // GLib owner; bounded provider identity cache applicationProcesses map[string]string // GLib owner; bounded provider identity cache
webNotificationRoots map[ObjectID]bool // copied identities only; no native references
deferredLiveRegions deferredLiveRegionStore // GLib owner; copied identities only deferredLiveRegions deferredLiveRegionStore // GLib owner; copied identities only
foregroundReader *xorg.ForegroundReader // GLib thread only foregroundReader *xorg.ForegroundReader // GLib thread only
foregroundProcesses map[int]bool // GLib thread; provider PID matches for current client foregroundProcesses map[int]bool // GLib thread; provider PID matches for current client
@@ -267,10 +267,6 @@ func (adapter *Adapter) enrichNativeWindowEvent(event *C.AtspiEvent, target *C.A
focusEvent.Window = nativeObjectID(window) focusEvent.Window = nativeObjectID(window)
if webNotification != nil { if webNotification != nil {
webNotification.WindowPath = focusEvent.Window.Path webNotification.WindowPath = focusEvent.Window.Path
if adapter.webNotificationRoots == nil || len(adapter.webNotificationRoots) >= 64 {
adapter.webNotificationRoots = make(map[ObjectID]bool)
}
adapter.webNotificationRoots[NewObjectID(webNotification.BusName, webNotification.RootPath)] = true
} }
focusEvent.WindowRecovered = restoredDocument.Valid() focusEvent.WindowRecovered = restoredDocument.Valid()
if eventType == WindowActivatedEvent && (snapshot.Role == "tree table" || snapshot.Role == "table cell") && window != nil { if eventType == WindowActivatedEvent && (snapshot.Role == "tree table" || snapshot.Role == "table cell") && window != nil {
@@ -507,15 +503,6 @@ func dispatch_native_event(event *C.AtspiEvent, userData unsafe.Pointer, deferre
adapter.enqueueSecureEvent(retired, secureEpoch) adapter.enqueueSecureEvent(retired, secureEpoch)
return return
} }
if eventType == DefunctStateEvent && C.cthulhu_event_detail1(event) != 0 && adapter.webNotificationRoots[originID] {
delete(adapter.webNotificationRoots, originID)
// Retire a known toast before the normal dead-object early return.
// Do not query or retain the accessible which has just been destroyed.
retired := NewEvent(eventType, Snapshot{BusName: originID.BusName, Path: originID.Path, Defunct: true})
retired.Detail1 = 1
adapter.enqueueSecureEvent(retired, secureEpoch)
return
}
// Showing/child-added events normally finish at invalidation. A matched // Showing/child-added events normally finish at invalidation. A matched
// notification script needs their semantics before that early return, // notification script needs their semantics before that early return,
// including when the provider is outside foreground ownership. // including when the provider is outside foreground ownership.
+7 -16
View File
@@ -113,27 +113,18 @@ func TestNativeWebScriptNotificationCapture(t *testing.T) {
t.Fatalf("fragment did not recover complete alert ancestor: %+v", message) t.Fatalf("fragment did not recover complete alert ancestor: %+v", message)
} }
fmt.Fprintln(input, "destroy") fmt.Fprintln(input, "destroy")
fmt.Fprintln(input, "add")
for { for {
select { select {
case ending := <-adapter.Events(): case added := <-adapter.Events():
if ending.Type == DefunctStateEvent && ending.Source.ID() == root && ending.Detail1 != 0 { if added.Type == ChildrenAddedEvent && added.Source.ApplicationProcess == processName && added.WebNotification != nil && added.WebNotification.RootPath != added.Source.Path {
fmt.Fprintln(input, "add") if added.WebNotification.Text != "A new toast" {
for { t.Fatalf("child-added did not use the added toast root: %+v", added.WebNotification)
select {
case added := <-adapter.Events():
if added.Type == ChildrenAddedEvent && added.Source.ApplicationProcess == processName && added.WebNotification != nil && added.WebNotification.RootPath != added.Source.Path {
if added.WebNotification.Text != "A new toast" {
t.Fatalf("child-added did not use the added toast root: %+v", added.WebNotification)
}
return
}
case <-ctx.Done():
t.Fatal("added toast did not reach notification handling")
}
} }
return
} }
case <-ctx.Done(): case <-ctx.Done():
t.Fatal("destroyed toast root did not reach lifecycle handling") t.Fatal("added toast did not reach notification handling")
} }
} }
case <-ctx.Done(): case <-ctx.Done():
+3 -3
View File
@@ -62,10 +62,10 @@ func (registry *Registry) Flush(now time.Time) []string { return registry.steam.
func (registry *Registry) Deadline() time.Time { return registry.steam.deadline() } func (registry *Registry) Deadline() time.Time { return registry.steam.deadline() }
func (registry *Registry) Reset() { registry.steam = steamNotifications{} } func (registry *Registry) Reset() { registry.steam = steamNotifications{} }
// Retire removes delayed content whose accessible root has been destroyed. // Retire removes delayed content whose window has been destroyed.
func (registry *Registry) Retire(busName, rootPath string) { func (registry *Registry) Retire(busName, windowPath string) {
for key, pending := range registry.steam.pending { for key, pending := range registry.steam.pending {
if key.busName == busName && (key.rootPath == rootPath || pending.windowPath == rootPath) { if key.busName == busName && (key.rootPath == windowPath || pending.windowPath == windowPath) {
delete(registry.steam.pending, key) delete(registry.steam.pending, key)
} }
} }