From 115570046a07ef354ec0fecd51e4bc629d0e8e84 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sun, 15 Nov 2026 12:03:34 +0000 Subject: [PATCH] fwb2-fix: web SCREEN_CAPTURE from the browser's EyeDropper (cherry picked from commit 0e2c2c65e7ed9c8394ed9dc7efa523c71b7ce530) --- crates/platform/src/screen.rs | 7 +++---- crates/ui-contract/Cargo.toml | 4 ++++ crates/ui-contract/src/runtime/install.rs | 18 +++++++++++++++++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/crates/platform/src/screen.rs b/crates/platform/src/screen.rs index 554d186e8..4aa00d50b 100644 --- a/crates/platform/src/screen.rs +++ b/crates/platform/src/screen.rs @@ -103,10 +103,9 @@ pub fn capture(scale: f32, wake: Wake) -> CaptureHandle { } } -/// Whether the browser has the EyeDropper API. A web host sets `Caps::SCREEN_CAPTURE` from it at -/// startup, so the picker's button shows only where a pick can work. Native builds take the -/// capability from `Caps::native`; a session without a display answers [`ScreenError::Unsupported`] -/// at its first capture. +/// Whether the browser has the EyeDropper API. The runtime's install sets `Caps::SCREEN_CAPTURE` from it, so the +/// picker's button shows only where a pick can work. Native builds take the capability from `Caps::native`; a session +/// without a display answers [`ScreenError::Unsupported`] at its first capture. #[cfg(target_arch = "wasm32")] pub fn available() -> bool { web::available() diff --git a/crates/ui-contract/Cargo.toml b/crates/ui-contract/Cargo.toml index 4f2b92514..7dab97453 100644 --- a/crates/ui-contract/Cargo.toml +++ b/crates/ui-contract/Cargo.toml @@ -75,6 +75,10 @@ egui_kittest = { version = "0.37", features = ["wgpu"], optional = true } image = { version = "0.25", default-features = false, features = ["png"], optional = true } # The window host's end hook sets `NSWindow.movable` through craft-window's AppKit code. +[target.'cfg(target_arch = "wasm32")'.dependencies] +# `screen::available`: whether the browser has the EyeDropper, read at install for `Caps::SCREEN_CAPTURE`. +craft-platform = { workspace = true, features = ["screen", "browser"] } + [target.'cfg(target_os = "macos")'.dependencies] craft-window = { workspace = true, features = ["ui", "appkit"] } diff --git a/crates/ui-contract/src/runtime/install.rs b/crates/ui-contract/src/runtime/install.rs index cabf8bbb2..c9ba2d65d 100644 --- a/crates/ui-contract/src/runtime/install.rs +++ b/crates/ui-contract/src/runtime/install.rs @@ -149,6 +149,22 @@ impl std::fmt::Display for InstallError { impl std::error::Error for InstallError {} +/// The shell with what the running browser offers: a browser build captures a screen colour only where the browser +/// has the EyeDropper, so `Caps::SCREEN_CAPTURE` is read here, once for every app. Native capabilities are the +/// build's own (`Caps::native`). +fn with_browser_caps(shell: ShellInfo) -> ShellInfo { + #[cfg(target_arch = "wasm32")] + { + let mut shell = shell; + if craft_platform::screen::available() { + shell.caps.insert(craft_host::target::Caps::SCREEN_CAPTURE); + } + shell + } + #[cfg(not(target_arch = "wasm32"))] + shell +} + /// Adds the runtime plugin to `ctx` and sets the egui options the runtime owns: interface scale is a command, quit goes /// through the close guard, and the wheel's modifiers are the spec's. A second call on the same context is an error, /// checked first so an app that installs again (a language change) gets that answer; a call inside a pass is one too. @@ -167,7 +183,7 @@ pub fn install(ctx: &Context, spec: InstallSpec) -> Result<(), InstallError> { input::set_wheel_modifiers(ctx, spec.wheel.zoom, spec.wheel.sideways); system::install(ctx, spec.system); pen::install(ctx, spec.pen); - windows::install(ctx, spec.shell_info, spec.window_system, spec.placement, spec.frame, spec.app_id); + windows::install(ctx, with_browser_caps(spec.shell_info), spec.window_system, spec.placement, spec.frame, spec.app_id); frame::set_frame_layers(ctx, spec.frame_layers); frame::seed_hooked_passes(ctx); plugin::register(ctx);