Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
refactor(desktop): gate window content protection on active recording
Richie McIlroy36c39a66010c
diff --git a/apps/desktop/src-tauri/src/windows.rs b/apps/desktop/src-tauri/src/windows.rsindex f890ee6b2..1934dee12 100644--- a/apps/desktop/src-tauri/src/windows.rs+++ b/apps/desktop/src-tauri/src/windows.rs@@ -1941,8 +1941,9 @@ impl ShowCapWindow {warn!("Detected existing camera preview, will reuse it");}- let title = CapWindowId::Camera.title();- let should_protect = should_protect_window(app, &title);+ // Camera protection is applied per recording mode in `start_recording`;+ // protecting at creation hides the live preview on virtual/mirrored displays.+ let should_protect = false;#[cfg(target_os = "macos")]let panel_activation_guard = permissions::prepare_macos_panel_window(app);@@ -1994,7 +1995,11 @@ impl ShowCapWindow {lock_window_text_scale(&window);#[cfg(target_os = "windows")]- log_window_content_protection(&window, should_protect, &title);+ log_window_content_protection(+ &window,+ should_protect,+ &CapWindowId::Camera.title(),+ );let camera_monitor = CapWindowId::Main.get(app)@@ -2728,7 +2733,23 @@ fn position_traffic_lights_impl(.ok();}-fn should_protect_window(app: &AppHandle<Wry>, window_title: &str) -> bool {+// Capture exclusion (WDA_EXCLUDEFROMCAPTURE / NSWindowSharingType::None) also hides+// the window from "capture-based" displays such as virtual/indirect/dummy-HDMI or+// mirrored monitors, making it invisible and unreachable. We therefore only protect+// Cap's own windows while a recording is actually active, which is the only time the+// exclusion is meaningful.+fn content_protection_enabled(app: &AppHandle<Wry>) -> bool {+ app.try_state::<ArcLock<crate::App>>()+ .and_then(|state| {+ state+ .try_read()+ .ok()+ .map(|app| app.is_recording_active_or_pending())+ })+ .unwrap_or(false)+}++fn window_matches_exclusion_list(app: &AppHandle<Wry>, window_title: &str) -> bool {let matches = |list: &[WindowExclusion]| {list.iter().any(|entry| entry.matches(None, None, Some(window_title)))@@ -2741,6 +2762,35 @@ fn should_protect_window(app: &AppHandle<Wry>, window_title: &str) -> bool {.unwrap_or_else(|| matches(&general_settings::default_excluded_windows()))}+fn should_protect_window(app: &AppHandle<Wry>, window_title: &str) -> bool {+ content_protection_enabled(app) && window_matches_exclusion_list(app, window_title)+}++pub fn apply_content_protection(app: &AppHandle<Wry>, enabled: bool) {+ for (label, window) in app.webview_windows() {+ let Ok(id) = CapWindowId::from_str(&label) else {+ continue;+ };++ // The camera window's protection depends on the recording mode (studio excludes+ // the preview, instant keeps it) and is driven from `start_recording`. Only ever+ // clear it here so it stays visible outside of recordings.+ if matches!(id, CapWindowId::Camera) {+ if !enabled {+ let _ = window.set_content_protected(false);+ }+ continue;+ }++ let title = id.title();+ let should_protect = enabled && window_matches_exclusion_list(app, &title);+ let _ = window.set_content_protected(should_protect);++ #[cfg(target_os = "windows")]+ log_window_content_protection(&window, should_protect, &title);+ }+}+#[cfg(target_os = "windows")]fn cached_windows_version() -> Option<&'static scap_direct3d::WindowsVersion> {static VERSION: std::sync::OnceLock<Option<scap_direct3d::WindowsVersion>> =@@ -2837,18 +2887,8 @@ fn log_window_content_protection(window: &WebviewWindow, enabled: bool, window_t#[specta::specta]#[instrument(skip(app))]pub fn refresh_window_content_protection(app: AppHandle<Wry>) -> Result<(), String> {- for (label, window) in app.webview_windows() {- if let Ok(id) = CapWindowId::from_str(&label) {- let title = id.title();- let should_protect = should_protect_window(&app, &title);- window- .set_content_protected(should_protect)- .map_err(|e| e.to_string())?;- #[cfg(target_os = "windows")]- log_window_content_protection(&window, should_protect, &title);- }- }-+ let enabled = content_protection_enabled(&app);+ apply_content_protection(&app, enabled);Ok(())}