Skip to content

Commit 5bd47b4

Browse files
fix(windows): changing WebView visibility on hide/show/minimize (#9246)
* Fix not changing visibilty for windows webview * Add change file * Move is_visible calculation to the caller * Rename update to set
1 parent 259d845 commit 5bd47b4

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

.changes/fix-visibility-change.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri-runtime-wry": patch:bug
3+
---
4+
5+
Fix webview's visibility doesn't change with the app window

core/tauri-runtime-wry/src/lib.rs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,8 +2632,16 @@ fn handle_user_message<T: UserEvent>(
26322632
WindowMessage::Unmaximize => window.set_maximized(false),
26332633
WindowMessage::Minimize => window.set_minimized(true),
26342634
WindowMessage::Unminimize => window.set_minimized(false),
2635-
WindowMessage::Show => window.set_visible(true),
2636-
WindowMessage::Hide => window.set_visible(false),
2635+
WindowMessage::Show => {
2636+
window.set_visible(true);
2637+
#[cfg(windows)]
2638+
let _ = set_webview_visibility(&webviews, !window.is_minimized());
2639+
}
2640+
WindowMessage::Hide => {
2641+
window.set_visible(false);
2642+
#[cfg(windows)]
2643+
let _ = set_webview_visibility(&webviews, false);
2644+
}
26372645
WindowMessage::Close => {
26382646
panic!("cannot handle `WindowMessage::Close` on the main thread")
26392647
}
@@ -3206,7 +3214,7 @@ fn handle_event_loop<T: UserEvent>(
32063214
.map(|w| (w.inner.clone(), w.webviews.clone()))
32073215
{
32083216
let size = size.to_logical::<f32>(window.scale_factor());
3209-
for webview in webviews {
3217+
for webview in &webviews {
32103218
if let Some(b) = &*webview.bounds.lock().unwrap() {
32113219
webview.set_bounds(wry::Rect {
32123220
x: (size.width * b.x_rate) as i32,
@@ -3216,6 +3224,9 @@ fn handle_event_loop<T: UserEvent>(
32163224
});
32173225
}
32183226
}
3227+
#[cfg(windows)]
3228+
let _ =
3229+
set_webview_visibility(&webviews, window.is_visible() && !window.is_minimized());
32193230
}
32203231
}
32213232
_ => {}
@@ -3950,3 +3961,15 @@ fn clear_window_surface(
39503961
let _ = buffer.present();
39513962
}
39523963
}
3964+
3965+
#[cfg(windows)]
3966+
fn set_webview_visibility(
3967+
webviews: &[WebviewWrapper],
3968+
is_visible: bool,
3969+
) -> windows::core::Result<()> {
3970+
for webview in webviews {
3971+
let controller = webview.controller();
3972+
unsafe { controller.SetIsVisible(is_visible) }?;
3973+
}
3974+
Ok(())
3975+
}

0 commit comments

Comments
 (0)