mirror of
https://github.com/tauri-apps/plugins-workspace.git
synced 2026-06-06 13:53:54 +02:00
feat(positioner, window-state): impl WindowExt for WebviewWindow (#1283)
closes #1281
This commit is contained in:
@@ -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(())
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user