Skip to content

Commit d9de5b1

Browse files
authored
feat(positioner, window-state): impl WindowExt for WebviewWindow (#1283)
closes #1281
1 parent b4efa58 commit d9de5b1

5 files changed

Lines changed: 55 additions & 35 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"positioner": "patch"
3+
"window-state": "patch"
4+
---
5+
6+
Implement `WindowExt` for `WebviewWindow`.

Cargo.lock

Lines changed: 29 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/positioner/src/ext.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::Tray;
88
use serde_repr::Deserialize_repr;
99
#[cfg(feature = "tray-icon")]
1010
use tauri::Manager;
11-
use tauri::{PhysicalPosition, PhysicalSize, Result, Runtime, Window};
11+
use tauri::{PhysicalPosition, PhysicalSize, Result, Runtime, WebviewWindow, Window};
1212

1313
/// Well known window positions.
1414
#[derive(Debug, Deserialize_repr)]
@@ -45,6 +45,11 @@ pub trait WindowExt {
4545
fn move_window(&self, position: Position) -> Result<()>;
4646
}
4747

48+
impl<R: Runtime> WindowExt for WebviewWindow<R> {
49+
fn move_window(&self, pos: Position) -> Result<()> {
50+
self.as_ref().window().move_window(pos)
51+
}
52+
}
4853
impl<R: Runtime> WindowExt for Window<R> {
4954
fn move_window(&self, pos: Position) -> Result<()> {
5055
use Position::*;

plugins/window-state/src/cmd.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ pub async fn restore_state<R: Runtime>(
2626
.ok_or_else(|| format!("Invalid state flags bits: {}", flags))?;
2727
app.get_webview_window(&label)
2828
.ok_or_else(|| format!("Couldn't find window with label: {}", label))?
29-
.as_ref()
30-
.window()
3129
.restore_state(flags)
3230
.map_err(|e| e.to_string())?;
3331
Ok(())

plugins/window-state/src/lib.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use bitflags::bitflags;
1616
use serde::{Deserialize, Serialize};
1717
use tauri::{
1818
plugin::{Builder as PluginBuilder, TauriPlugin},
19-
LogicalSize, Manager, Monitor, PhysicalPosition, PhysicalSize, RunEvent, Runtime, Window,
20-
WindowEvent,
19+
LogicalSize, Manager, Monitor, PhysicalPosition, PhysicalSize, RunEvent, Runtime,
20+
WebviewWindow, Window, WindowEvent,
2121
};
2222

2323
use std::{
@@ -118,7 +118,7 @@ impl<R: Runtime> AppHandleExt for tauri::AppHandle<R> {
118118
let mut state = cache.0.lock().unwrap();
119119
for (label, s) in state.iter_mut() {
120120
if let Some(window) = self.get_webview_window(label) {
121-
window.as_ref().window().update_state(s, flags)?;
121+
window.update_state(s, flags)?;
122122
}
123123
}
124124

@@ -141,6 +141,11 @@ pub trait WindowExt {
141141
fn restore_state(&self, flags: StateFlags) -> tauri::Result<()>;
142142
}
143143

144+
impl<R: Runtime> WindowExt for WebviewWindow<R> {
145+
fn restore_state(&self, flags: StateFlags) -> tauri::Result<()> {
146+
self.as_ref().window().restore_state(flags)
147+
}
148+
}
144149
impl<R: Runtime> WindowExt for Window<R> {
145150
fn restore_state(&self, flags: StateFlags) -> tauri::Result<()> {
146151
let cache = self.state::<WindowStateCache>();
@@ -246,6 +251,12 @@ trait WindowExtInternal {
246251
fn update_state(&self, state: &mut WindowState, flags: StateFlags) -> tauri::Result<()>;
247252
}
248253

254+
impl<R: Runtime> WindowExtInternal for WebviewWindow<R> {
255+
fn update_state(&self, state: &mut WindowState, flags: StateFlags) -> tauri::Result<()> {
256+
self.as_ref().window().update_state(state, flags)
257+
}
258+
}
259+
249260
impl<R: Runtime> WindowExtInternal for Window<R> {
250261
fn update_state(&self, state: &mut WindowState, flags: StateFlags) -> tauri::Result<()> {
251262
let is_maximized = match flags.intersects(StateFlags::MAXIMIZED | StateFlags::SIZE) {

0 commit comments

Comments
 (0)