mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
* fix(window): repaint a never-shown background window on Windows so CDP screenshots return Windows composites nothing for an idle window that was never shown, so Page.captureScreenshot under ORCA_BACKGROUND_LAUNCH=1 waited forever once the status-bar usage chip stopped animating (#33799). * fix(window): pump hidden-window frames from the renderer on Windows background launches Main-process webContents.invalidate() did not make a never-shown Windows window produce a frame CDP can capture (verified on Windows 11). A one-frame root background flip from the preload does, so main stamps a preload flag for ORCA_BACKGROUND_LAUNCH=1 on win32 and tells the preload to stop on first show. * fix(window): stop the hidden-frame pump only on main's show signal, including after reloads A never-shown Windows window can report visible after a desktop change, so the preload no longer stops on visibilitychange; main re-sends the stop after any reload once the window has been shown. * fix(window): register the frame-pump stop with on('show') so every window double supports it createMainWindow suites simulate win32 under the runner's ORCA_BACKGROUND_LAUNCH=1, so they install the pump stop; their window doubles implement on() but not once().
63 lines
2.0 KiB
TypeScript
63 lines
2.0 KiB
TypeScript
import {
|
|
HIDDEN_WINDOW_FRAME_PUMP_INTERVAL_MS,
|
|
hasHiddenWindowFramePumpArgument
|
|
} from '../shared/hidden-window-frame-pump'
|
|
|
|
// Near-black so the single damaged frame is indistinguishable even if the window were visible.
|
|
const FLIP_COLOR = 'rgb(1, 1, 1)'
|
|
|
|
type FramePumpStyle = Pick<
|
|
CSSStyleDeclaration,
|
|
'getPropertyValue' | 'getPropertyPriority' | 'setProperty' | 'removeProperty'
|
|
>
|
|
|
|
export type HiddenWindowFramePumpDeps = {
|
|
rootStyle: () => FramePumpStyle | null
|
|
requestAnimationFrame: (callback: () => void) => unknown
|
|
/** Runs callback every ms; returns the cancel function. */
|
|
every: (callback: () => void, ms: number) => () => void
|
|
}
|
|
|
|
/** Damage one frame per interval by flipping the root background, then restore the inline style exactly. */
|
|
export function startHiddenWindowFramePump(deps: HiddenWindowFramePumpDeps): () => void {
|
|
let stopped = false
|
|
let flipping = false
|
|
const cancel = deps.every(() => {
|
|
const style = deps.rootStyle()
|
|
if (stopped || flipping || !style) {
|
|
return
|
|
}
|
|
flipping = true
|
|
deps.requestAnimationFrame(() => {
|
|
const previousValue = style.getPropertyValue('background-color')
|
|
const previousPriority = style.getPropertyPriority('background-color')
|
|
style.setProperty('background-color', FLIP_COLOR, previousPriority)
|
|
deps.requestAnimationFrame(() => {
|
|
if (previousValue) {
|
|
style.setProperty('background-color', previousValue, previousPriority)
|
|
} else {
|
|
style.removeProperty('background-color')
|
|
}
|
|
flipping = false
|
|
})
|
|
})
|
|
}, HIDDEN_WINDOW_FRAME_PUMP_INTERVAL_MS)
|
|
return () => {
|
|
if (!stopped) {
|
|
stopped = true
|
|
cancel()
|
|
}
|
|
}
|
|
}
|
|
|
|
/** Only main's stop ends the pump; Windows can report a never-shown window visible after a desktop change. */
|
|
export function installHiddenWindowFramePump(
|
|
argv: readonly string[],
|
|
onStopRequest: (stop: () => void) => void,
|
|
deps: HiddenWindowFramePumpDeps
|
|
): void {
|
|
if (hasHiddenWindowFramePumpArgument(argv)) {
|
|
onStopRequest(startHiddenWindowFramePump(deps))
|
|
}
|
|
}
|