mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-01-31 00:35:19 +01:00
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:
7
.changes/webview-set-simple-fullscreen.md
Normal file
7
.changes/webview-set-simple-fullscreen.md
Normal 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.
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -1968,25 +1968,27 @@ tauri::Builder::default()
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
/// 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).
|
||||
/// 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 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.
|
||||
///
|
||||
/// 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.
|
||||
|
||||
Reference in New Issue
Block a user