Skip to content

Commit b26aeff

Browse files
committed
Restore hidden overlays after capture and reveal main window without focus after OCR
1 parent 8a6644c commit b26aeff

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

apps/desktop/src-tauri/src/recording.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2864,8 +2864,10 @@ async fn capture_screen_image(
28642864
app: &AppHandle,
28652865
target: ScreenCaptureTarget,
28662866
) -> Result<image::DynamicImage, String> {
2867+
use crate::windows::show_overlay;
28672868
use cap_recording::screenshot::capture_screenshot;
28682869

2870+
let mut hidden_windows = Vec::new();
28692871
let mut hid_any = false;
28702872
for (label, window) in app.webview_windows() {
28712873
if let Ok(id) = CapWindowId::from_str(&label)
@@ -2877,19 +2879,32 @@ async fn capture_screen_image(
28772879
| CapWindowId::ModeSelect
28782880
| CapWindowId::RecordingsOverlay
28792881
)
2882+
&& window.is_visible().unwrap_or(false)
28802883
{
28812884
hide_overlay(&window);
28822885
hid_any = true;
2886+
// The target-select overlay's lifecycle is owned by the frontend,
2887+
// which hides it before invoking a capture and closes or restores
2888+
// it afterwards; re-showing it here would fight that.
2889+
if !matches!(id, CapWindowId::TargetSelectOverlay { .. }) {
2890+
hidden_windows.push(window);
2891+
}
28832892
}
28842893
}
28852894

28862895
if hid_any {
28872896
tokio::time::sleep(std::time::Duration::from_millis(150)).await;
28882897
}
28892898

2890-
capture_screenshot(target)
2899+
let result = capture_screenshot(target)
28912900
.await
2892-
.map_err(|e| format!("Failed to capture screenshot: {e}"))
2901+
.map_err(|e| format!("Failed to capture screenshot: {e}"));
2902+
2903+
for window in hidden_windows {
2904+
show_overlay(&window);
2905+
}
2906+
2907+
result
28932908
}
28942909

28952910
fn save_screenshot_project(

apps/desktop/src/routes/(window-chrome)/new-main/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2035,11 +2035,14 @@ function Page() {
20352035
const dismissalReveals =
20362036
dismissal === "cancelled" ||
20372037
dismissal === "screenshot" ||
2038+
dismissal === "ocr" ||
20382039
dismissal === "recordingInstant";
20392040
if (shouldRevealMainWindow && dismissalReveals) {
20402041
const currentWindow = getCurrentWindow();
20412042
void currentWindow.show();
2042-
void currentWindow.setFocus();
2043+
// An OCR capture is a background copy-to-clipboard gesture; bring
2044+
// the window back without stealing focus from the user's app.
2045+
if (dismissal !== "ocr") void currentWindow.setFocus();
20432046
}
20442047
}
20452048
});

0 commit comments

Comments
 (0)