F2: ui.screenshot captures the webview without focusing the window

On Windows the webview renders itself into a PNG through WebView2
CapturePreview (scheduled on the main thread via with_webview, 10 s
timeout, PNG signature and 64 MiB cap checked). macOS and Linux keep the
xcap screen-region capture as a documented fallback, now without focusing.
app.focus is the only control method that changes focus. A --control
instance opens its window without taking the foreground. An ignored live
test samples the foreground window while the app starts and takes five
screenshots and fails if Lutra ever owns it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-27 17:13:38 +01:00
parent d567f3957d
commit f49b42836a
12 changed files with 398 additions and 84 deletions

View file

@ -30,7 +30,8 @@ pub trait Backend: Send + Sync + 'static {
/// Lists every command with its current enabled state.
fn list_commands(&self) -> Vec<CommandInfo>;
/// Writes a PNG screenshot of the main window to `path`.
/// Writes a PNG screenshot of the main window to `path`. It must not
/// focus, raise or show any window; only [`Backend::focus`] may.
///
/// # Errors
/// A message if there is no window to capture or the file cannot be
@ -41,7 +42,7 @@ pub trait Backend: Send + Sync + 'static {
fn subscribe(&self, sink: EventSink);
/// Brings the main window to the front, for the CLI and a second app
/// start. The default has no window and fails.
/// start. The only method that changes focus. The default has no window and fails.
///
/// # Errors
/// A message if there is no window or it cannot be focused.

View file

@ -11,13 +11,14 @@ pub const APP_PING: &str = "app.ping";
pub const ENGINE_EXECUTE: &str = "engine.execute";
/// `engine.listCommands`: lists the engine's commands.
pub const ENGINE_LIST_COMMANDS: &str = "engine.listCommands";
/// `ui.screenshot`: writes a PNG of the main window.
/// `ui.screenshot`: writes a PNG of the main window without focusing it.
pub const UI_SCREENSHOT: &str = "ui.screenshot";
/// `events.subscribe`: streams engine events on this connection.
pub const EVENTS_SUBSCRIBE: &str = "events.subscribe";
/// `app.auth`: authenticates a connection to the rendezvous listener.
pub const APP_AUTH: &str = "app.auth";
/// `app.focus`: brings the main window to the front.
/// `app.focus`: brings the main window to the front; the only method that
/// changes focus.
pub const APP_FOCUS: &str = "app.focus";
/// Documentation of one method.
@ -61,7 +62,7 @@ pub const METHODS: &[MethodDoc] = &[
MethodDoc {
name: UI_SCREENSHOT,
params: "{ path: string }",
result: "{ path }; error screenshot_failed if the window cannot be captured",
result: "{ path }; error screenshot_failed if the window cannot be captured. Never focuses, raises or shows the window",
},
MethodDoc {
name: EVENTS_SUBSCRIBE,