Skip to content

The agent that grows with you

fix(desktop): keep native Wayland fullscreen windows painting

Kevin Rajan3632f9173d21
diff --git a/apps/desktop/electron/stream-throttle.ts b/apps/desktop/electron/stream-throttle.ts
index 912b40b9167..432319c9904 100644
--- a/apps/desktop/electron/stream-throttle.ts
+++ b/apps/desktop/electron/stream-throttle.ts
@@ -15,6 +15,11 @@
// after a short trailing delay (so tail flushes land at full cadence) Chromium's
// default throttling returns and hidden windows go quiet.
//
+// On native Wayland only, a fullscreen chat may be misclassified as occluded
+// after sitting idle (#94865). The caller can opt into keeping the fleet
+// unthrottled while any registered window is fullscreen. The policy is
+// deliberately opt-in so macOS/Windows/X11 keep the idle-CPU contract.
+//
// Pure and Electron-free (timers + the WebContents surface are injected) so it
// can be unit-tested, mirroring session-windows.ts.
@@ -25,6 +30,7 @@ const RETHROTTLE_DELAY_MS = 5_000
export interface ThrottleWindowLike {
isDestroyed(): boolean
+ isFullScreen?: () => boolean
webContents?: {
isDestroyed(): boolean
setBackgroundThrottling(allowed: boolean): void
@@ -36,6 +42,12 @@ interface TimersLike {
setTimeout(fn: () => void, ms: number): unknown
}
+export interface StreamThrottleOptions {
+ /** Native-Wayland workaround for #94865. False by default so other
+ * platforms retain Chromium's idle background throttling. */
+ keepFullscreenPainting?: boolean
+}
+
export interface StreamThrottle {
/** True while windows are currently unthrottled (streaming or trailing). */
isUnthrottled(): boolean
@@ -48,11 +60,32 @@ export interface StreamThrottle {
export function createStreamThrottle(
timers: TimersLike = { clearTimeout: handle => clearTimeout(handle as never), setTimeout },
- delayMs: number = RETHROTTLE_DELAY_MS
+ delayMs: number = RETHROTTLE_DELAY_MS,
+ options: StreamThrottleOptions = {}
): StreamThrottle {
const windows = new Set<ThrottleWindowLike>()
+ const keepFullscreenPainting = options.keepFullscreenPainting === true
let unthrottled = false
let trailing: unknown = null
+ let lastBusy = false
+
+ function anyFullscreen(): boolean {
+ if (!keepFullscreenPainting) {
+ return false
+ }
+
+ for (const win of windows) {
+ try {
+ if (!win.isDestroyed() && win.isFullScreen?.()) {
+ return true
+ }
+ } catch {
+ // A window mid-teardown can throw from geometry queries; skip it.
+ }
+ }
+
+ return false
+ }
function apply(win: ThrottleWindowLike) {
if (win.isDestroyed()) {
@@ -80,16 +113,50 @@ export function createStreamThrottle(
}
}
+ function armRethrottleIfIdle() {
+ if (lastBusy || anyFullscreen() || !unthrottled || trailing !== null) {
+ return
+ }
+
+ trailing = timers.setTimeout(() => {
+ trailing = null
+ unthrottled = false
+ applyAll()
+ }, delayMs)
+ }
+
return {
isUnthrottled: () => unthrottled,
register(win) {
windows.add(win)
- win.on?.('closed', () => windows.delete(win))
+ win.on?.('closed', () => {
+ windows.delete(win)
+ armRethrottleIfIdle()
+ })
+
+ if (keepFullscreenPainting) {
+ win.on?.('enter-full-screen', () => {
+ if (trailing !== null) {
+ timers.clearTimeout(trailing)
+ trailing = null
+ }
+ if (!unthrottled) {
+ unthrottled = true
+ applyAll()
+ }
+ })
+ win.on?.('leave-full-screen', () => {
+ armRethrottleIfIdle()
+ })
+ }
+
apply(win)
},
update(busy) {
+ lastBusy = busy
+
if (busy) {
if (trailing !== null) {
timers.clearTimeout(trailing)
@@ -104,16 +171,12 @@ export function createStreamThrottle(
return
}
- if (!unthrottled || trailing !== null) {
+ if (anyFullscreen()) {
return
}
// Trailing edge: keep full cadence briefly so the final flush paints.
- trailing = timers.setTimeout(() => {
- trailing = null
- unthrottled = false
- applyAll()
- }, delayMs)
+ armRethrottleIfIdle()
}
}
}