@@ -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
28952910fn save_screenshot_project (
0 commit comments