fix(core): store the hosting Window directly on Webview and WebviewWindow (#11161)

closes #11159
This commit is contained in:
Amr Bashir
2024-09-27 20:15:38 +03:00
committed by GitHub
parent 1d8b67b297
commit a49fc999fc
6 changed files with 141 additions and 115 deletions

View File

@@ -0,0 +1,5 @@
---
"tauri": "patch:bug"
---
Fix internal crash when trying to close the same window multiple times.

View File

@@ -364,7 +364,7 @@ impl<R: Runtime> Clone for AppHandle<R> {
impl<'de, R: Runtime> CommandArg<'de, R> for AppHandle<R> {
/// Grabs the [`Window`] from the [`CommandItem`] and returns the associated [`AppHandle`]. This will never fail.
fn from_command(command: CommandItem<'de, R>) -> std::result::Result<Self, InvokeError> {
Ok(command.message.webview().window().app_handle)
Ok(command.message.webview().app_handle)
}
}

View File

@@ -584,8 +584,12 @@ pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
/// Fetch a single webview window from the manager.
fn get_webview_window(&self, label: &str) -> Option<WebviewWindow<R>> {
self.manager().get_webview(label).and_then(|webview| {
if webview.window().is_webview_window() {
Some(WebviewWindow { webview })
let window = webview.window();
if window.is_webview_window() {
Some(WebviewWindow {
window: window.clone(),
webview,
})
} else {
None
}
@@ -599,8 +603,15 @@ pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
.webviews()
.into_iter()
.filter_map(|(label, webview)| {
if webview.window().is_webview_window() {
Some((label, WebviewWindow { webview }))
let window = webview.window();
if window.is_webview_window() {
Some((
label,
WebviewWindow {
window: window.clone(),
webview,
},
))
} else {
None
}

View File

@@ -792,19 +792,19 @@ fn main() {
/// Webview.
#[default_runtime(crate::Wry, wry)]
pub struct Webview<R: Runtime> {
window_label: Arc<Mutex<String>>,
pub(crate) window: Arc<Mutex<Window<R>>>,
/// The webview created by the runtime.
pub(crate) webview: DetachedWebview<EventLoopMessage, R>,
/// The manager to associate this webview with.
pub(crate) manager: Arc<AppManager<R>>,
pub(crate) app_handle: AppHandle<R>,
/// The webview created by the runtime.
pub(crate) webview: DetachedWebview<EventLoopMessage, R>,
pub(crate) resources_table: Arc<Mutex<ResourceTable>>,
}
impl<R: Runtime> std::fmt::Debug for Webview<R> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Window")
.field("window_label", &self.window_label)
.field("window", &self.window.lock().unwrap())
.field("webview", &self.webview)
.finish()
}
@@ -813,10 +813,10 @@ impl<R: Runtime> std::fmt::Debug for Webview<R> {
impl<R: Runtime> Clone for Webview<R> {
fn clone(&self) -> Self {
Self {
window_label: self.window_label.clone(),
window: self.window.clone(),
webview: self.webview.clone(),
manager: self.manager.clone(),
app_handle: self.app_handle.clone(),
webview: self.webview.clone(),
resources_table: self.resources_table.clone(),
}
}
@@ -842,9 +842,9 @@ impl<R: Runtime> Webview<R> {
/// Create a new webview that is attached to the window.
pub(crate) fn new(window: Window<R>, webview: DetachedWebview<EventLoopMessage, R>) -> Self {
Self {
window_label: Arc::new(Mutex::new(window.label().into())),
manager: window.manager.clone(),
app_handle: window.app_handle.clone(),
window: Arc::new(Mutex::new(window)),
webview,
resources_table: Default::default(),
}
@@ -957,14 +957,13 @@ impl<R: Runtime> Webview<R> {
pub fn reparent(&self, window: &Window<R>) -> crate::Result<()> {
#[cfg(not(feature = "unstable"))]
{
let current_window = self.window();
if current_window.is_webview_window() || window.is_webview_window() {
if self.window_ref().is_webview_window() || window.is_webview_window() {
return Err(crate::Error::CannotReparentWebviewWindow);
}
}
*self.window.lock().unwrap() = window.clone();
self.webview.dispatcher.reparent(window.window.id)?;
*self.window_label.lock().unwrap() = window.label().to_string();
Ok(())
}
@@ -1000,14 +999,16 @@ impl<R: Runtime> Webview<R> {
impl<R: Runtime> Webview<R> {
/// The window that is hosting this webview.
pub fn window(&self) -> Window<R> {
self
.manager
.get_window(&self.window_label.lock().unwrap())
.expect("could not locate webview parent window")
self.window.lock().unwrap().clone()
}
/// A reference to the window that is hosting this webview.
pub fn window_ref(&self) -> MutexGuard<'_, Window<R>> {
self.window.lock().unwrap()
}
pub(crate) fn window_label(&self) -> String {
self.window_label.lock().unwrap().clone()
self.window_ref().label().to_string()
}
/// Executes a closure, providing it with the webview handle that is specific to the current platform.
@@ -1193,7 +1194,7 @@ fn main() {
let runtime_authority = manager.runtime_authority.lock().unwrap();
let acl = runtime_authority.resolve_access(
&request.cmd,
message.webview.window().label(),
message.webview.window_ref().label(),
message.webview.label(),
&acl_origin,
);

View File

@@ -57,7 +57,7 @@ mod desktop_commands {
.webviews()
.values()
.map(|webview| WebviewRef {
window_label: webview.window().label().into(),
window_label: webview.window_ref().label().into(),
label: webview.label().into(),
})
.collect()

View File

@@ -14,7 +14,7 @@ use crate::{
event::EventTarget,
runtime::dpi::{PhysicalPosition, PhysicalSize},
window::Monitor,
Emitter, Listener, ResourceTable,
Emitter, Listener, ResourceTable, Window,
};
#[cfg(desktop)]
use crate::{
@@ -338,16 +338,22 @@ tauri::Builder::default()
mut self,
f: F,
) -> Self {
self.webview_builder = self
.webview_builder
.on_page_load(move |webview, payload| f(WebviewWindow { webview }, payload));
self.webview_builder = self.webview_builder.on_page_load(move |webview, payload| {
f(
WebviewWindow {
window: webview.window(),
webview,
},
payload,
)
});
self
}
/// Creates a new window.
pub fn build(self) -> crate::Result<WebviewWindow<R>> {
let (_window, webview) = self.window_builder.with_webview(self.webview_builder)?;
Ok(WebviewWindow { webview })
let (window, webview) = self.window_builder.with_webview(self.webview_builder)?;
Ok(WebviewWindow { window, webview })
}
}
@@ -589,7 +595,7 @@ impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M> {
/// - **Linux**: This makes the new window transient for parent, see <https://docs.gtk.org/gtk3/method.Window.set_transient_for.html>
/// - **macOS**: This adds the window as a child of parent, see <https://developer.apple.com/documentation/appkit/nswindow/1419152-addchildwindow?language=objc>
pub fn parent(mut self, parent: &WebviewWindow<R>) -> crate::Result<Self> {
self.window_builder = self.window_builder.parent(&parent.webview.window())?;
self.window_builder = self.window_builder.parent(&parent.window)?;
Ok(self)
}
@@ -603,7 +609,7 @@ impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M> {
/// For more information, see <https://docs.microsoft.com/en-us/windows/win32/winmsg/window-features#owned-windows>
#[cfg(windows)]
pub fn owner(mut self, owner: &WebviewWindow<R>) -> crate::Result<Self> {
self.window_builder = self.window_builder.owner(&owner.webview.window())?;
self.window_builder = self.window_builder.owner(&owner.window)?;
Ok(self)
}
@@ -655,9 +661,7 @@ impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M> {
target_os = "openbsd"
))]
pub fn transient_for(mut self, parent: &WebviewWindow<R>) -> crate::Result<Self> {
self.window_builder = self
.window_builder
.transient_for(&parent.webview.window())?;
self.window_builder = self.window_builder.transient_for(&parent.window)?;
Ok(self)
}
@@ -897,6 +901,7 @@ impl<'a, R: Runtime, M: Manager<R>> WebviewWindowBuilder<'a, R, M> {
#[default_runtime(crate::Wry, wry)]
#[derive(Debug)]
pub struct WebviewWindow<R: Runtime> {
pub(crate) window: Window<R>,
pub(crate) webview: Webview<R>,
}
@@ -909,6 +914,7 @@ impl<R: Runtime> AsRef<Webview<R>> for WebviewWindow<R> {
impl<R: Runtime> Clone for WebviewWindow<R> {
fn clone(&self) -> Self {
Self {
window: self.window.clone(),
webview: self.webview.clone(),
}
}
@@ -927,7 +933,7 @@ impl<R: Runtime> raw_window_handle::HasWindowHandle for WebviewWindow<R> {
&self,
) -> std::result::Result<raw_window_handle::WindowHandle<'_>, raw_window_handle::HandleError> {
Ok(unsafe {
raw_window_handle::WindowHandle::borrow_raw(self.webview.window().window_handle()?.as_raw())
raw_window_handle::WindowHandle::borrow_raw(self.window.window_handle()?.as_raw())
})
}
}
@@ -944,11 +950,15 @@ impl<'de, R: Runtime> CommandArg<'de, R> for WebviewWindow<R> {
/// Grabs the [`Window`] from the [`CommandItem`]. This will never fail.
fn from_command(command: CommandItem<'de, R>) -> Result<Self, InvokeError> {
let webview = command.message.webview();
if webview.window().is_webview_window() {
Ok(Self { webview })
} else {
Err(InvokeError::from("current webview is not a WebviewWindow"))
let window = webview.window();
if window.is_webview_window() {
return Ok(Self {
window: window.clone(),
webview,
});
}
Err(InvokeError::from("current webview is not a WebviewWindow"))
}
}
@@ -977,7 +987,7 @@ impl<R: Runtime> WebviewWindow<R> {
/// Registers a window event listener.
pub fn on_window_event<F: Fn(&WindowEvent) + Send + 'static>(&self, f: F) {
self.webview.window().on_window_event(f);
self.window.on_window_event(f);
}
}
@@ -1025,12 +1035,12 @@ impl<R: Runtime> WebviewWindow<R> {
&self,
f: F,
) {
self.webview.window().on_menu_event(f)
self.window.on_menu_event(f)
}
/// Returns this window menu .
pub fn menu(&self) -> Option<Menu<R>> {
self.webview.window().menu()
self.window.menu()
}
/// Sets the window menu and returns the previous one.
@@ -1041,7 +1051,7 @@ impl<R: Runtime> WebviewWindow<R> {
/// window, if you need to set it, use [`AppHandle::set_menu`] instead.
#[cfg_attr(target_os = "macos", allow(unused_variables))]
pub fn set_menu(&self, menu: Menu<R>) -> crate::Result<Option<Menu<R>>> {
self.webview.window().set_menu(menu)
self.window.set_menu(menu)
}
/// Removes the window menu and returns it.
@@ -1051,27 +1061,27 @@ impl<R: Runtime> WebviewWindow<R> {
/// - **macOS:** Unsupported. The menu on macOS is app-wide and not specific to one
/// window, if you need to remove it, use [`AppHandle::remove_menu`] instead.
pub fn remove_menu(&self) -> crate::Result<Option<Menu<R>>> {
self.webview.window().remove_menu()
self.window.remove_menu()
}
/// Hides the window menu.
pub fn hide_menu(&self) -> crate::Result<()> {
self.webview.window().hide_menu()
self.window.hide_menu()
}
/// Shows the window menu.
pub fn show_menu(&self) -> crate::Result<()> {
self.webview.window().show_menu()
self.window.show_menu()
}
/// Shows the window menu.
pub fn is_menu_visible(&self) -> crate::Result<bool> {
self.webview.window().is_menu_visible()
self.window.is_menu_visible()
}
/// Shows the specified menu as a context menu at the cursor position.
pub fn popup_menu<M: ContextMenu>(&self, menu: &M) -> crate::Result<()> {
self.webview.window().popup_menu(menu)
self.window.popup_menu(menu)
}
/// Shows the specified menu as a context menu at the specified position.
@@ -1082,7 +1092,7 @@ impl<R: Runtime> WebviewWindow<R> {
menu: &M,
position: P,
) -> crate::Result<()> {
menu.popup_at(self.webview.window(), position)
self.window.popup_menu_at(menu, position)
}
}
@@ -1090,61 +1100,61 @@ impl<R: Runtime> WebviewWindow<R> {
impl<R: Runtime> WebviewWindow<R> {
/// Returns the scale factor that can be used to map logical pixels to physical pixels, and vice versa.
pub fn scale_factor(&self) -> crate::Result<f64> {
self.webview.window().scale_factor()
self.window.scale_factor()
}
/// Returns the position of the top-left hand corner of the window's client area relative to the top-left hand corner of the desktop.
pub fn inner_position(&self) -> crate::Result<PhysicalPosition<i32>> {
self.webview.window().inner_position()
self.window.inner_position()
}
/// Returns the position of the top-left hand corner of the window relative to the top-left hand corner of the desktop.
pub fn outer_position(&self) -> crate::Result<PhysicalPosition<i32>> {
self.webview.window().outer_position()
self.window.outer_position()
}
/// Returns the physical size of the window's client area.
///
/// The client area is the content of the window, excluding the title bar and borders.
pub fn inner_size(&self) -> crate::Result<PhysicalSize<u32>> {
self.webview.window().inner_size()
self.window.inner_size()
}
/// Returns the physical size of the entire window.
///
/// These dimensions include the title bar and borders. If you don't want that (and you usually don't), use inner_size instead.
pub fn outer_size(&self) -> crate::Result<PhysicalSize<u32>> {
self.webview.window().outer_size()
self.window.outer_size()
}
/// Gets the window's current fullscreen state.
pub fn is_fullscreen(&self) -> crate::Result<bool> {
self.webview.window().is_fullscreen()
self.window.is_fullscreen()
}
/// Gets the window's current minimized state.
pub fn is_minimized(&self) -> crate::Result<bool> {
self.webview.window().is_minimized()
self.window.is_minimized()
}
/// Gets the window's current maximized state.
pub fn is_maximized(&self) -> crate::Result<bool> {
self.webview.window().is_maximized()
self.window.is_maximized()
}
/// Gets the window's current focus state.
pub fn is_focused(&self) -> crate::Result<bool> {
self.webview.window().is_focused()
self.window.is_focused()
}
/// Gets the window's current decoration state.
pub fn is_decorated(&self) -> crate::Result<bool> {
self.webview.window().is_decorated()
self.window.is_decorated()
}
/// Gets the window's current resizable state.
pub fn is_resizable(&self) -> crate::Result<bool> {
self.webview.window().is_resizable()
self.window.is_resizable()
}
/// Gets the window's native maximize button state
@@ -1153,7 +1163,7 @@ impl<R: Runtime> WebviewWindow<R> {
///
/// - **Linux / iOS / Android:** Unsupported.
pub fn is_maximizable(&self) -> crate::Result<bool> {
self.webview.window().is_maximizable()
self.window.is_maximizable()
}
/// Gets the window's native minimize button state
@@ -1162,7 +1172,7 @@ impl<R: Runtime> WebviewWindow<R> {
///
/// - **Linux / iOS / Android:** Unsupported.
pub fn is_minimizable(&self) -> crate::Result<bool> {
self.webview.window().is_minimizable()
self.window.is_minimizable()
}
/// Gets the window's native close button state
@@ -1171,59 +1181,59 @@ impl<R: Runtime> WebviewWindow<R> {
///
/// - **Linux / iOS / Android:** Unsupported.
pub fn is_closable(&self) -> crate::Result<bool> {
self.webview.window().is_closable()
self.window.is_closable()
}
/// Gets the window's current visibility state.
pub fn is_visible(&self) -> crate::Result<bool> {
self.webview.window().is_visible()
self.window.is_visible()
}
/// Gets the window's current title.
pub fn title(&self) -> crate::Result<String> {
self.webview.window().title()
self.window.title()
}
/// Returns the monitor on which the window currently resides.
///
/// Returns None if current monitor can't be detected.
pub fn current_monitor(&self) -> crate::Result<Option<Monitor>> {
self.webview.window().current_monitor()
self.window.current_monitor()
}
/// Returns the primary monitor of the system.
///
/// Returns None if it can't identify any monitor as a primary one.
pub fn primary_monitor(&self) -> crate::Result<Option<Monitor>> {
self.webview.window().primary_monitor()
self.window.primary_monitor()
}
/// Returns the monitor that contains the given point.
pub fn monitor_from_point(&self, x: f64, y: f64) -> crate::Result<Option<Monitor>> {
self.webview.window().monitor_from_point(x, y)
self.window.monitor_from_point(x, y)
}
/// Returns the list of all the monitors available on the system.
pub fn available_monitors(&self) -> crate::Result<Vec<Monitor>> {
self.webview.window().available_monitors()
self.window.available_monitors()
}
/// Returns the native handle that is used by this window.
#[cfg(target_os = "macos")]
pub fn ns_window(&self) -> crate::Result<*mut std::ffi::c_void> {
self.webview.window().ns_window()
self.window.ns_window()
}
/// Returns the pointer to the content view of this window.
#[cfg(target_os = "macos")]
pub fn ns_view(&self) -> crate::Result<*mut std::ffi::c_void> {
self.webview.window().ns_view()
self.window.ns_view()
}
/// Returns the native handle that is used by this window.
#[cfg(windows)]
pub fn hwnd(&self) -> crate::Result<HWND> {
self.webview.window().hwnd()
self.window.hwnd()
}
/// Returns the `ApplicationWindow` from gtk crate that is used by this window.
@@ -1237,7 +1247,7 @@ impl<R: Runtime> WebviewWindow<R> {
target_os = "openbsd"
))]
pub fn gtk_window(&self) -> crate::Result<gtk::ApplicationWindow> {
self.webview.window().gtk_window()
self.window.gtk_window()
}
/// Returns the vertical [`gtk::Box`] that is added by default as the sole child of this window.
@@ -1251,7 +1261,7 @@ impl<R: Runtime> WebviewWindow<R> {
target_os = "openbsd"
))]
pub fn default_vbox(&self) -> crate::Result<gtk::Box> {
self.webview.window().default_vbox()
self.window.default_vbox()
}
/// Returns the current window theme.
@@ -1260,7 +1270,7 @@ impl<R: Runtime> WebviewWindow<R> {
///
/// - **macOS**: Only supported on macOS 10.14+.
pub fn theme(&self) -> crate::Result<crate::Theme> {
self.webview.window().theme()
self.window.theme()
}
}
@@ -1285,7 +1295,7 @@ impl<R: Runtime> WebviewWindow<R> {
impl<R: Runtime> WebviewWindow<R> {
/// Centers the window.
pub fn center(&self) -> crate::Result<()> {
self.webview.window().center()
self.window.center()
}
/// Requests user attention to the window, this has no effect if the application
@@ -1303,13 +1313,13 @@ impl<R: Runtime> WebviewWindow<R> {
&self,
request_type: Option<UserAttentionType>,
) -> crate::Result<()> {
self.webview.window().request_user_attention(request_type)
self.window.request_user_attention(request_type)
}
/// Determines if this window should be resizable.
/// When resizable is set to false, native window's maximize button is automatically disabled.
pub fn set_resizable(&self, resizable: bool) -> crate::Result<()> {
self.webview.window().set_resizable(resizable)
self.window.set_resizable(resizable)
}
/// Determines if this window's native maximize button should be enabled.
@@ -1320,7 +1330,7 @@ impl<R: Runtime> WebviewWindow<R> {
/// - **macOS:** Disables the "zoom" button in the window titlebar, which is also used to enter fullscreen mode.
/// - **Linux / iOS / Android:** Unsupported.
pub fn set_maximizable(&self, maximizable: bool) -> crate::Result<()> {
self.webview.window().set_maximizable(maximizable)
self.window.set_maximizable(maximizable)
}
/// Determines if this window's native minimize button should be enabled.
@@ -1329,7 +1339,7 @@ impl<R: Runtime> WebviewWindow<R> {
///
/// - **Linux / iOS / Android:** Unsupported.
pub fn set_minimizable(&self, minimizable: bool) -> crate::Result<()> {
self.webview.window().set_minimizable(minimizable)
self.window.set_minimizable(minimizable)
}
/// Determines if this window's native close button should be enabled.
@@ -1340,59 +1350,59 @@ impl<R: Runtime> WebviewWindow<R> {
/// Depending on the system, this function may not have any effect when called on a window that is already visible"
/// - **iOS / Android:** Unsupported.
pub fn set_closable(&self, closable: bool) -> crate::Result<()> {
self.webview.window().set_closable(closable)
self.window.set_closable(closable)
}
/// Set this window's title.
pub fn set_title(&self, title: &str) -> crate::Result<()> {
self.webview.window().set_title(title)
self.window.set_title(title)
}
/// Maximizes this window.
pub fn maximize(&self) -> crate::Result<()> {
self.webview.window().maximize()
self.window.maximize()
}
/// Un-maximizes this window.
pub fn unmaximize(&self) -> crate::Result<()> {
self.webview.window().unmaximize()
self.window.unmaximize()
}
/// Minimizes this window.
pub fn minimize(&self) -> crate::Result<()> {
self.webview.window().minimize()
self.window.minimize()
}
/// Un-minimizes this window.
pub fn unminimize(&self) -> crate::Result<()> {
self.webview.window().unminimize()
self.window.unminimize()
}
/// Show this window.
pub fn show(&self) -> crate::Result<()> {
self.webview.window().show()
self.window.show()
}
/// Hide this window.
pub fn hide(&self) -> crate::Result<()> {
self.webview.window().hide()
self.window.hide()
}
/// Closes this window. It emits [`crate::RunEvent::CloseRequested`] first like a user-initiated close request so you can intercept it.
pub fn close(&self) -> crate::Result<()> {
self.webview.window().close()
self.window.close()
}
/// Destroys this window. Similar to [`Self::close`] but does not emit any events and force close the window instead.
pub fn destroy(&self) -> crate::Result<()> {
self.webview.window().destroy()
self.window.destroy()
}
/// Determines if this window should be [decorated].
///
/// [decorated]: https://en.wikipedia.org/wiki/Window_(computing)#Window_decoration
pub fn set_decorations(&self, decorations: bool) -> crate::Result<()> {
self.webview.window().set_decorations(decorations)
self.window.set_decorations(decorations)
}
/// Determines if this window should have shadow.
@@ -1405,7 +1415,7 @@ impl<R: Runtime> WebviewWindow<R> {
/// and on Windows 11, it will have a rounded corners.
/// - **Linux:** Unsupported.
pub fn set_shadow(&self, enable: bool) -> crate::Result<()> {
self.webview.window().set_shadow(enable)
self.window.set_shadow(enable)
}
/// Sets window effects, pass [`None`] to clear any effects applied if possible.
@@ -1440,17 +1450,17 @@ impl<R: Runtime> WebviewWindow<R> {
&self,
effects: E,
) -> crate::Result<()> {
self.webview.window().set_effects(effects)
self.window.set_effects(effects)
}
/// Determines if this window should always be below other windows.
pub fn set_always_on_bottom(&self, always_on_bottom: bool) -> crate::Result<()> {
self.webview.window().set_always_on_bottom(always_on_bottom)
self.window.set_always_on_bottom(always_on_bottom)
}
/// Determines if this window should always be on top of other windows.
pub fn set_always_on_top(&self, always_on_top: bool) -> crate::Result<()> {
self.webview.window().set_always_on_top(always_on_top)
self.window.set_always_on_top(always_on_top)
}
/// Sets whether the window should be visible on all workspaces or virtual desktops.
@@ -1459,29 +1469,28 @@ impl<R: Runtime> WebviewWindow<R> {
visible_on_all_workspaces: bool,
) -> crate::Result<()> {
self
.webview
.window()
.window
.set_visible_on_all_workspaces(visible_on_all_workspaces)
}
/// Prevents the window contents from being captured by other apps.
pub fn set_content_protected(&self, protected: bool) -> crate::Result<()> {
self.webview.window().set_content_protected(protected)
self.window.set_content_protected(protected)
}
/// Resizes this window.
pub fn set_size<S: Into<Size>>(&self, size: S) -> crate::Result<()> {
self.webview.window().set_size(size.into())
self.window.set_size(size.into())
}
/// Sets this window's minimum inner size.
pub fn set_min_size<S: Into<Size>>(&self, size: Option<S>) -> crate::Result<()> {
self.webview.window().set_min_size(size.map(|s| s.into()))
self.window.set_min_size(size.map(|s| s.into()))
}
/// Sets this window's maximum inner size.
pub fn set_max_size<S: Into<Size>>(&self, size: Option<S>) -> crate::Result<()> {
self.webview.window().set_max_size(size.map(|s| s.into()))
self.window.set_max_size(size.map(|s| s.into()))
}
/// Sets this window's minimum inner width.
@@ -1489,27 +1498,27 @@ impl<R: Runtime> WebviewWindow<R> {
&self,
constriants: tauri_runtime::window::WindowSizeConstraints,
) -> crate::Result<()> {
self.webview.window().set_size_constraints(constriants)
self.window.set_size_constraints(constriants)
}
/// Sets this window's position.
pub fn set_position<Pos: Into<Position>>(&self, position: Pos) -> crate::Result<()> {
self.webview.window().set_position(position)
self.window.set_position(position)
}
/// Determines if this window should be fullscreen.
pub fn set_fullscreen(&self, fullscreen: bool) -> crate::Result<()> {
self.webview.window().set_fullscreen(fullscreen)
self.window.set_fullscreen(fullscreen)
}
/// Bring the window to front and focus.
pub fn set_focus(&self) -> crate::Result<()> {
self.webview.window().set_focus()
self.window.set_focus()
}
/// Sets this window' icon.
pub fn set_icon(&self, icon: Image<'_>) -> crate::Result<()> {
self.webview.window().set_icon(icon)
self.window.set_icon(icon)
}
/// Whether to hide the window icon from the taskbar or not.
@@ -1518,7 +1527,7 @@ impl<R: Runtime> WebviewWindow<R> {
///
/// - **macOS:** Unsupported.
pub fn set_skip_taskbar(&self, skip: bool) -> crate::Result<()> {
self.webview.window().set_skip_taskbar(skip)
self.window.set_skip_taskbar(skip)
}
/// Grabs the cursor, preventing it from leaving the window.
@@ -1531,7 +1540,7 @@ impl<R: Runtime> WebviewWindow<R> {
/// - **Linux:** Unsupported.
/// - **macOS:** This locks the cursor in a fixed location, which looks visually awkward.
pub fn set_cursor_grab(&self, grab: bool) -> crate::Result<()> {
self.webview.window().set_cursor_grab(grab)
self.window.set_cursor_grab(grab)
}
/// Modifies the cursor's visibility.
@@ -1544,27 +1553,27 @@ impl<R: Runtime> WebviewWindow<R> {
/// - **macOS:** The cursor is hidden as long as the window has input focus, even if the cursor is
/// outside of the window.
pub fn set_cursor_visible(&self, visible: bool) -> crate::Result<()> {
self.webview.window().set_cursor_visible(visible)
self.window.set_cursor_visible(visible)
}
/// Modifies the cursor icon of the window.
pub fn set_cursor_icon(&self, icon: CursorIcon) -> crate::Result<()> {
self.webview.window().set_cursor_icon(icon)
self.window.set_cursor_icon(icon)
}
/// Changes the position of the cursor in window coordinates.
pub fn set_cursor_position<Pos: Into<Position>>(&self, position: Pos) -> crate::Result<()> {
self.webview.window().set_cursor_position(position)
self.window.set_cursor_position(position)
}
/// Ignores the window cursor events.
pub fn set_ignore_cursor_events(&self, ignore: bool) -> crate::Result<()> {
self.webview.window().set_ignore_cursor_events(ignore)
self.window.set_ignore_cursor_events(ignore)
}
/// Starts dragging the window.
pub fn start_dragging(&self) -> crate::Result<()> {
self.webview.window().start_dragging()
self.window.start_dragging()
}
/// Sets the taskbar progress state.
@@ -1578,17 +1587,17 @@ impl<R: Runtime> WebviewWindow<R> {
&self,
progress_state: crate::window::ProgressBarState,
) -> crate::Result<()> {
self.webview.window().set_progress_bar(progress_state)
self.window.set_progress_bar(progress_state)
}
/// Sets the title bar style. **macOS only**.
pub fn set_title_bar_style(&self, style: tauri_utils::TitleBarStyle) -> crate::Result<()> {
self.webview.window().set_title_bar_style(style)
self.window.set_title_bar_style(style)
}
/// Set the window theme.
pub fn set_theme(&self, theme: Option<Theme>) -> crate::Result<()> {
self.webview.window().set_theme(theme)
self.window.set_theme(theme)
}
}