feat(webview-window): add set_simple_fullscreen to WebviewWindow (#14619)

* feat(webview): add set_simple_fullscreen to WebviewWindow

* add changes

* Combine per platform fn to one

---------

Co-authored-by: Tony <legendmastertony@gmail.com>
This commit is contained in:
Luke
2026-01-19 12:38:37 +09:00
committed by GitHub
parent 0575dd287e
commit e919a760ed
4 changed files with 61 additions and 17 deletions

View File

@@ -0,0 +1,7 @@
---
'tauri': 'minor:feat'
---
Add `set_simple_fullscreen` method to `WebviewWindow`.
This method was already available on the `Window` type and is now also available on `WebviewWindow` for consistency. On macOS, it toggles fullscreen mode without creating a new macOS Space. On other platforms, it falls back to regular fullscreen.

View File

@@ -2312,4 +2312,25 @@ mod tests {
crate::test_utils::assert_send::<super::Webview>();
crate::test_utils::assert_sync::<super::Webview>();
}
#[cfg(target_os = "macos")]
#[test]
fn test_webview_window_has_set_simple_fullscreen_method() {
use crate::test::{mock_builder, mock_context, noop_assets};
// Create a mock app with proper context
let app = mock_builder().build(mock_context(noop_assets())).unwrap();
// Get or create a webview window
let webview_window =
crate::WebviewWindowBuilder::new(&app, "test", crate::WebviewUrl::default())
.build()
.unwrap();
// This should compile if set_simple_fullscreen exists
let result = webview_window.set_simple_fullscreen(true);
// We expect this to work without panicking
assert!(result.is_ok(), "set_simple_fullscreen should succeed");
}
}

View File

@@ -2057,6 +2057,20 @@ impl<R: Runtime> WebviewWindow<R> {
self.window.set_fullscreen(fullscreen)
}
/// Toggles a fullscreen mode that doesn't require a new macOS space.
/// Returns a boolean indicating whether the transition was successful (this won't work if the window was already in the native fullscreen).
///
/// This is how fullscreen used to work on macOS in versions before Lion.
/// And allows the user to have a fullscreen window without using another space or taking control over the entire monitor.
///
/// ## Platform-specific
///
/// - **macOS:** Uses native simple fullscreen mode.
/// - **Other platforms:** Falls back to [`Self::set_fullscreen`].
pub fn set_simple_fullscreen(&self, enable: bool) -> crate::Result<()> {
self.window.set_simple_fullscreen(enable)
}
/// Bring the window to front and focus.
pub fn set_focus(&self) -> crate::Result<()> {
self.window.set_focus()

View File

@@ -1968,25 +1968,27 @@ tauri::Builder::default()
.map_err(Into::into)
}
/// Toggles a fullscreen mode that doesnt require a new macOS space. Returns a boolean indicating whether the transition was successful (this wont work if the window was already in the native fullscreen).
/// Toggles a fullscreen mode that doesn't require a new macOS space.
/// Returns a boolean indicating whether the transition was successful (this won't work if the window was already in the native fullscreen).
///
/// This is how fullscreen used to work on macOS in versions before Lion. And allows the user to have a fullscreen window without using another space or taking control over the entire monitor.
#[cfg(target_os = "macos")]
/// This is how fullscreen used to work on macOS in versions before Lion.
/// And allows the user to have a fullscreen window without using another space or taking control over the entire monitor.
///
/// ## Platform-specific
///
/// - **macOS:** Uses native simple fullscreen mode.
/// - **Other platforms:** Falls back to [`Self::set_fullscreen`].
pub fn set_simple_fullscreen(&self, enable: bool) -> crate::Result<()> {
self
.window
.dispatcher
.set_simple_fullscreen(enable)
.map_err(Into::into)
}
/// On macOS, Toggles a fullscreen mode that doesnt require a new macOS space. Returns a boolean indicating whether the transition was successful (this wont work if the window was already in the native fullscreen).
/// This is how fullscreen used to work on macOS in versions before Lion. And allows the user to have a fullscreen window without using another space or taking control over the entire monitor.
///
/// On other platforms, this is the same as [`Window#method.set_fullscreen`].
#[cfg(not(target_os = "macos"))]
pub fn set_simple_fullscreen(&self, fullscreen: bool) -> crate::Result<()> {
self.set_fullscreen(fullscreen)
#[cfg(target_os = "macos")]
{
self
.window
.dispatcher
.set_simple_fullscreen(enable)
.map_err(Into::into)
}
#[cfg(not(target_os = "macos"))]
self.set_fullscreen(enable)
}
/// Bring the window to front and focus.