Skip to content

Commit

Permalink
fix(window-state): port fixes from v1 (tauri-apps#436)
Browse files Browse the repository at this point in the history
* fix(window-state): correctly set decoration state if no saved state exists, fixes tauri-apps#421 (tauri-apps#424)

* fix(window-state): propagate promise (tauri-apps#435)

closes tauri-apps#432

* fix(window-state): manual default implentation (tauri-apps#425)

* fix(window-state): manual default implentation, closes tauri-apps#421

* Update lib.rs

* change file

* generated files

* fix symlinks?

---------

Co-authored-by: Fabian-Lars <[email protected]>
  • Loading branch information
amrbashir and FabianLars authored Jun 13, 2023
1 parent c73049d commit 84b3612
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changes/window-state-decorated.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"window-state": "patch"
---

Correctly set decoration state if no saved state xists
5 changes: 5 additions & 0 deletions .changes/window-state-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"window-state-js": "patch"
---

Correctly propagate the promise inside `saveWindowState`, `restoreState` and `restoreStateCurrent` so callers can choose to `await` them.
4 changes: 0 additions & 4 deletions plugins/authenticator/tsconfig.json

This file was deleted.

4 changes: 4 additions & 0 deletions plugins/authenticator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}
4 changes: 0 additions & 4 deletions plugins/autostart/tsconfig.json

This file was deleted.

4 changes: 4 additions & 0 deletions plugins/autostart/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}
4 changes: 0 additions & 4 deletions plugins/fs/tsconfig.json

This file was deleted.

4 changes: 4 additions & 0 deletions plugins/fs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}
4 changes: 0 additions & 4 deletions plugins/log/tsconfig.json

This file was deleted.

4 changes: 4 additions & 0 deletions plugins/log/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}
4 changes: 0 additions & 4 deletions plugins/positioner/tsconfig.json

This file was deleted.

4 changes: 4 additions & 0 deletions plugins/positioner/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}
4 changes: 0 additions & 4 deletions plugins/sql/tsconfig.json

This file was deleted.

4 changes: 4 additions & 0 deletions plugins/sql/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}
4 changes: 0 additions & 4 deletions plugins/store/tsconfig.json

This file was deleted.

4 changes: 4 additions & 0 deletions plugins/store/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}
4 changes: 0 additions & 4 deletions plugins/stronghold/tsconfig.json

This file was deleted.

4 changes: 4 additions & 0 deletions plugins/stronghold/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}
4 changes: 0 additions & 4 deletions plugins/upload/tsconfig.json

This file was deleted.

4 changes: 4 additions & 0 deletions plugins/upload/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}
4 changes: 0 additions & 4 deletions plugins/websocket/tsconfig.json

This file was deleted.

4 changes: 4 additions & 0 deletions plugins/websocket/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}
14 changes: 8 additions & 6 deletions plugins/window-state/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ export enum StateFlags {
/**
* Save the state of all open windows to disk.
*/
async function saveWindowState(flags: StateFlags) {
window.__TAURI_INVOKE__("plugin:window-state|save_window_state", { flags });
async function saveWindowState(flags: StateFlags): Promise<void> {
return window.__TAURI_INVOKE__("plugin:window-state|save_window_state", {
flags,
});
}

/**
* Restore the state for the specified window from disk.
*/
async function restoreState(label: string, flags: StateFlags) {
window.__TAURI_INVOKE__("plugin:window-state|restore_state", {
async function restoreState(label: string, flags: StateFlags): Promise<void> {
return window.__TAURI_INVOKE__("plugin:window-state|restore_state", {
label,
flags,
});
Expand All @@ -51,8 +53,8 @@ async function restoreState(label: string, flags: StateFlags) {
/**
* Restore the state for the current window from disk.
*/
async function restoreStateCurrent(flags: StateFlags) {
restoreState(window.__TAURI_METADATA__.__currentWindow.label, flags);
async function restoreStateCurrent(flags: StateFlags): Promise<void> {
return restoreState(window.__TAURI_METADATA__.__currentWindow.label, flags);
}

export { restoreState, restoreStateCurrent, saveWindowState };
2 changes: 1 addition & 1 deletion plugins/window-state/src/api-iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions plugins/window-state/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Default for StateFlags {
}
}

#[derive(Debug, Default, Deserialize, Serialize, PartialEq)]
#[derive(Debug, Deserialize, Serialize, PartialEq)]
struct WindowState {
width: f64,
height: f64,
Expand All @@ -67,6 +67,21 @@ struct WindowState {
fullscreen: bool,
}

impl Default for WindowState {
fn default() -> Self {
Self {
width: Default::default(),
height: Default::default(),
x: Default::default(),
y: Default::default(),
maximized: Default::default(),
visible: true,
decorated: true,
fullscreen: Default::default(),
}
}
}

struct WindowStateCache(Arc<Mutex<HashMap<String, WindowState>>>);
pub trait AppHandleExt {
/// Saves all open windows state to disk
Expand Down Expand Up @@ -177,7 +192,7 @@ impl<R: Runtime> WindowExt for Window<R> {
}

if flags.contains(StateFlags::DECORATIONS) {
metadata.visible = self.is_visible()?;
metadata.decorated = self.is_decorated()?;
}

if flags.contains(StateFlags::FULLSCREEN) {
Expand Down
4 changes: 0 additions & 4 deletions plugins/window-state/tsconfig.json

This file was deleted.

4 changes: 4 additions & 0 deletions plugins/window-state/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

0 comments on commit 84b3612

Please sign in to comment.