Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/windows-fullscreen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
tauri-runtime-wry: "patch:bug"
---

Allow web fullscreen APIs to work on Windows (e.g. `video.requestFullscreen` and `document.exitFullscreen`)
33 changes: 27 additions & 6 deletions crates/tauri-runtime-wry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use tao::platform::unix::{WindowBuilderExtUnix, WindowExtUnix};
#[cfg(windows)]
use tao::platform::windows::{WindowBuilderExtWindows, WindowExtWindows};
#[cfg(windows)]
use webview2_com::FocusChangedEventHandler;
use webview2_com::{ContainsFullScreenElementChangedEventHandler, FocusChangedEventHandler};
#[cfg(windows)]
use windows::Win32::Foundation::HWND;
#[cfg(target_os = "ios")]
Expand Down Expand Up @@ -4821,8 +4821,7 @@ You may have it installed on another user account, but it is not available for t
#[cfg(windows)]
{
let controller = webview.controller();
let proxy = context.proxy.clone();
let proxy_ = proxy.clone();
let proxy_clone = context.proxy.clone();
let window_id_ = window_id.clone();
let mut token = 0;
unsafe {
Expand All @@ -4837,7 +4836,7 @@ You may have it installed on another user account, but it is not available for t
focused_webview.replace(label_.clone());

if !already_focused {
let _ = proxy.send_event(Message::Webview(
let _ = proxy_clone.send_event(Message::Webview(
*window_id_.lock().unwrap(),
id,
WebviewMessage::SynthesizedWindowEvent(SynthesizedWindowEvent::Focused(true)),
Expand All @@ -4851,6 +4850,8 @@ You may have it installed on another user account, but it is not available for t
.unwrap();
unsafe {
let label_ = label.clone();
let window_id_ = window_id.clone();
let proxy_clone = context.proxy.clone();
controller.add_LostFocus(
&FocusChangedEventHandler::create(Box::new(move |_, _| {
let mut focused_webview = focused_webview.lock().unwrap();
Expand All @@ -4866,8 +4867,8 @@ You may have it installed on another user account, but it is not available for t
if lost_window_focus {
// only reset when we lost window focus - otherwise some other webview is focused
*focused_webview = None;
let _ = proxy_.send_event(Message::Webview(
*window_id.lock().unwrap(),
let _ = proxy_clone.send_event(Message::Webview(
*window_id_.lock().unwrap(),
id,
WebviewMessage::SynthesizedWindowEvent(SynthesizedWindowEvent::Focused(false)),
));
Expand All @@ -4878,6 +4879,26 @@ You may have it installed on another user account, but it is not available for t
)
}
.unwrap();

if let Ok(webview) = unsafe { controller.CoreWebView2() } {
let proxy_clone = context.proxy.clone();
unsafe {
let _ = webview.add_ContainsFullScreenElementChanged(
&ContainsFullScreenElementChangedEventHandler::create(Box::new(move |sender, _| {
let mut contains_fullscreen_element = windows::core::BOOL::default();
sender
.ok_or_else(windows::core::Error::empty)?
.ContainsFullScreenElement(&mut contains_fullscreen_element)?;
let _ = proxy_clone.send_event(Message::Window(
*window_id.lock().unwrap(),
WindowMessage::SetFullscreen(contains_fullscreen_element.as_bool()),
));
Ok(())
})),
&mut token,
);
}
}
}

Ok(WebviewWrapper {
Expand Down