mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-02-06 13:57:16 +00:00
fix(windows): allow web fullscreen APIs to work (#13558)
* fix(windows): allow web fullscreen APIs to work * tauri-runtime-wry not tauri-wry * Remove last clone * Change file on windows
This commit is contained in:
parent
6a39f49991
commit
78d15e892d
5
.changes/windows-fullscreen.md
Normal file
5
.changes/windows-fullscreen.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
tauri-runtime-wry: "patch:bug"
|
||||
---
|
||||
|
||||
Allow web fullscreen APIs to work on Windows (e.g. `video.requestFullscreen` and `document.exitFullscreen`)
|
||||
@ -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")]
|
||||
@ -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 {
|
||||
@ -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)),
|
||||
@ -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();
|
||||
@ -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)),
|
||||
));
|
||||
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user