Skip to content

Commit 84b3612

Browse files
fix(window-state): port fixes from v1 (#436)
* fix(window-state): correctly set decoration state if no saved state exists, fixes #421 (#424) * fix(window-state): propagate promise (#435) closes #432 * fix(window-state): manual default implentation (#425) * fix(window-state): manual default implentation, closes #421 * Update lib.rs * change file * generated files * fix symlinks? --------- Co-authored-by: Fabian-Lars <[email protected]>
1 parent c73049d commit 84b3612

16 files changed

+36
-9
lines changed

.changes/window-state-decorated.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"window-state": "patch"
3+
---
4+
5+
Correctly set decoration state if no saved state xists

.changes/window-state-promise.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"window-state-js": "patch"
3+
---
4+
5+
Correctly propagate the promise inside `saveWindowState`, `restoreState` and `restoreStateCurrent` so callers can choose to `await` them.

plugins/authenticator/tsconfig.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

plugins/authenticator/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"include": ["guest-js/*.ts"]
4+
}

plugins/autostart/tsconfig.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

plugins/autostart/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"include": ["guest-js/*.ts"]
4+
}

plugins/fs/tsconfig.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

plugins/fs/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"include": ["guest-js/*.ts"]
4+
}

plugins/log/tsconfig.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

plugins/log/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"include": ["guest-js/*.ts"]
4+
}

plugins/positioner/tsconfig.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

plugins/positioner/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"include": ["guest-js/*.ts"]
4+
}

plugins/sql/tsconfig.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

plugins/sql/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"include": ["guest-js/*.ts"]
4+
}

plugins/store/tsconfig.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

plugins/store/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"include": ["guest-js/*.ts"]
4+
}

plugins/stronghold/tsconfig.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

plugins/stronghold/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"include": ["guest-js/*.ts"]
4+
}

plugins/upload/tsconfig.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

plugins/upload/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"include": ["guest-js/*.ts"]
4+
}

plugins/websocket/tsconfig.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

plugins/websocket/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"include": ["guest-js/*.ts"]
4+
}

plugins/window-state/guest-js/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,17 @@ export enum StateFlags {
3434
/**
3535
* Save the state of all open windows to disk.
3636
*/
37-
async function saveWindowState(flags: StateFlags) {
38-
window.__TAURI_INVOKE__("plugin:window-state|save_window_state", { flags });
37+
async function saveWindowState(flags: StateFlags): Promise<void> {
38+
return window.__TAURI_INVOKE__("plugin:window-state|save_window_state", {
39+
flags,
40+
});
3941
}
4042

4143
/**
4244
* Restore the state for the specified window from disk.
4345
*/
44-
async function restoreState(label: string, flags: StateFlags) {
45-
window.__TAURI_INVOKE__("plugin:window-state|restore_state", {
46+
async function restoreState(label: string, flags: StateFlags): Promise<void> {
47+
return window.__TAURI_INVOKE__("plugin:window-state|restore_state", {
4648
label,
4749
flags,
4850
});
@@ -51,8 +53,8 @@ async function restoreState(label: string, flags: StateFlags) {
5153
/**
5254
* Restore the state for the current window from disk.
5355
*/
54-
async function restoreStateCurrent(flags: StateFlags) {
55-
restoreState(window.__TAURI_METADATA__.__currentWindow.label, flags);
56+
async function restoreStateCurrent(flags: StateFlags): Promise<void> {
57+
return restoreState(window.__TAURI_METADATA__.__currentWindow.label, flags);
5658
}
5759

5860
export { restoreState, restoreStateCurrent, saveWindowState };

plugins/window-state/src/api-iife.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/window-state/src/lib.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl Default for StateFlags {
5555
}
5656
}
5757

58-
#[derive(Debug, Default, Deserialize, Serialize, PartialEq)]
58+
#[derive(Debug, Deserialize, Serialize, PartialEq)]
5959
struct WindowState {
6060
width: f64,
6161
height: f64,
@@ -67,6 +67,21 @@ struct WindowState {
6767
fullscreen: bool,
6868
}
6969

70+
impl Default for WindowState {
71+
fn default() -> Self {
72+
Self {
73+
width: Default::default(),
74+
height: Default::default(),
75+
x: Default::default(),
76+
y: Default::default(),
77+
maximized: Default::default(),
78+
visible: true,
79+
decorated: true,
80+
fullscreen: Default::default(),
81+
}
82+
}
83+
}
84+
7085
struct WindowStateCache(Arc<Mutex<HashMap<String, WindowState>>>);
7186
pub trait AppHandleExt {
7287
/// Saves all open windows state to disk
@@ -177,7 +192,7 @@ impl<R: Runtime> WindowExt for Window<R> {
177192
}
178193

179194
if flags.contains(StateFlags::DECORATIONS) {
180-
metadata.visible = self.is_visible()?;
195+
metadata.decorated = self.is_decorated()?;
181196
}
182197

183198
if flags.contains(StateFlags::FULLSCREEN) {

plugins/window-state/tsconfig.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

plugins/window-state/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"extends": "../../tsconfig.base.json",
3+
"include": ["guest-js/*.ts"]
4+
}

0 commit comments

Comments
 (0)