feat(positioner, window-state): impl WindowExt for WebviewWindow (#1283)

closes #1281
This commit is contained in:
Amr Bashir
2024-05-03 14:16:40 +03:00
committed by GitHub
parent b4efa58d5d
commit d9de5b19d1
5 changed files with 55 additions and 35 deletions
-2
View File
@@ -26,8 +26,6 @@ pub async fn restore_state<R: Runtime>(
.ok_or_else(|| format!("Invalid state flags bits: {}", flags))?;
app.get_webview_window(&label)
.ok_or_else(|| format!("Couldn't find window with label: {}", label))?
.as_ref()
.window()
.restore_state(flags)
.map_err(|e| e.to_string())?;
Ok(())
+14 -3
View File
@@ -16,8 +16,8 @@ use bitflags::bitflags;
use serde::{Deserialize, Serialize};
use tauri::{
plugin::{Builder as PluginBuilder, TauriPlugin},
LogicalSize, Manager, Monitor, PhysicalPosition, PhysicalSize, RunEvent, Runtime, Window,
WindowEvent,
LogicalSize, Manager, Monitor, PhysicalPosition, PhysicalSize, RunEvent, Runtime,
WebviewWindow, Window, WindowEvent,
};
use std::{
@@ -118,7 +118,7 @@ impl<R: Runtime> AppHandleExt for tauri::AppHandle<R> {
let mut state = cache.0.lock().unwrap();
for (label, s) in state.iter_mut() {
if let Some(window) = self.get_webview_window(label) {
window.as_ref().window().update_state(s, flags)?;
window.update_state(s, flags)?;
}
}
@@ -141,6 +141,11 @@ pub trait WindowExt {
fn restore_state(&self, flags: StateFlags) -> tauri::Result<()>;
}
impl<R: Runtime> WindowExt for WebviewWindow<R> {
fn restore_state(&self, flags: StateFlags) -> tauri::Result<()> {
self.as_ref().window().restore_state(flags)
}
}
impl<R: Runtime> WindowExt for Window<R> {
fn restore_state(&self, flags: StateFlags) -> tauri::Result<()> {
let cache = self.state::<WindowStateCache>();
@@ -246,6 +251,12 @@ trait WindowExtInternal {
fn update_state(&self, state: &mut WindowState, flags: StateFlags) -> tauri::Result<()>;
}
impl<R: Runtime> WindowExtInternal for WebviewWindow<R> {
fn update_state(&self, state: &mut WindowState, flags: StateFlags) -> tauri::Result<()> {
self.as_ref().window().update_state(state, flags)
}
}
impl<R: Runtime> WindowExtInternal for Window<R> {
fn update_state(&self, state: &mut WindowState, flags: StateFlags) -> tauri::Result<()> {
let is_maximized = match flags.intersects(StateFlags::MAXIMIZED | StateFlags::SIZE) {