From 84b3612393e3d0d4faeebe1e61cb7d7973556503 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Tue, 13 Jun 2023 23:30:39 +0300 Subject: [PATCH] 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 --- .changes/window-state-decorated.md | 5 +++++ .changes/window-state-promise.md | 5 +++++ plugins/authenticator/tsconfig.json | 0 plugins/autostart/tsconfig.json | 0 plugins/fs/tsconfig.json | 0 plugins/log/tsconfig.json | 0 plugins/positioner/tsconfig.json | 0 plugins/sql/tsconfig.json | 0 plugins/store/tsconfig.json | 0 plugins/stronghold/tsconfig.json | 0 plugins/upload/tsconfig.json | 0 plugins/websocket/tsconfig.json | 0 plugins/window-state/guest-js/index.ts | 14 ++++++++------ plugins/window-state/src/api-iife.js | 2 +- plugins/window-state/src/lib.rs | 19 +++++++++++++++++-- plugins/window-state/tsconfig.json | 0 16 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 .changes/window-state-decorated.md create mode 100644 .changes/window-state-promise.md mode change 120000 => 100644 plugins/authenticator/tsconfig.json mode change 120000 => 100644 plugins/autostart/tsconfig.json mode change 120000 => 100644 plugins/fs/tsconfig.json mode change 120000 => 100644 plugins/log/tsconfig.json mode change 120000 => 100644 plugins/positioner/tsconfig.json mode change 120000 => 100644 plugins/sql/tsconfig.json mode change 120000 => 100644 plugins/store/tsconfig.json mode change 120000 => 100644 plugins/stronghold/tsconfig.json mode change 120000 => 100644 plugins/upload/tsconfig.json mode change 120000 => 100644 plugins/websocket/tsconfig.json mode change 120000 => 100644 plugins/window-state/tsconfig.json diff --git a/.changes/window-state-decorated.md b/.changes/window-state-decorated.md new file mode 100644 index 000000000..191ec5c26 --- /dev/null +++ b/.changes/window-state-decorated.md @@ -0,0 +1,5 @@ +--- +"window-state": "patch" +--- + +Correctly set decoration state if no saved state xists diff --git a/.changes/window-state-promise.md b/.changes/window-state-promise.md new file mode 100644 index 000000000..f97c43df8 --- /dev/null +++ b/.changes/window-state-promise.md @@ -0,0 +1,5 @@ +--- +"window-state-js": "patch" +--- + +Correctly propagate the promise inside `saveWindowState`, `restoreState` and `restoreStateCurrent` so callers can choose to `await` them. diff --git a/plugins/authenticator/tsconfig.json b/plugins/authenticator/tsconfig.json deleted file mode 120000 index 5098169aa..000000000 --- a/plugins/authenticator/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/authenticator/tsconfig.json b/plugins/authenticator/tsconfig.json new file mode 100644 index 000000000..5098169aa --- /dev/null +++ b/plugins/authenticator/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/autostart/tsconfig.json b/plugins/autostart/tsconfig.json deleted file mode 120000 index 5098169aa..000000000 --- a/plugins/autostart/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/autostart/tsconfig.json b/plugins/autostart/tsconfig.json new file mode 100644 index 000000000..5098169aa --- /dev/null +++ b/plugins/autostart/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/fs/tsconfig.json b/plugins/fs/tsconfig.json deleted file mode 120000 index 5098169aa..000000000 --- a/plugins/fs/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/fs/tsconfig.json b/plugins/fs/tsconfig.json new file mode 100644 index 000000000..5098169aa --- /dev/null +++ b/plugins/fs/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/log/tsconfig.json b/plugins/log/tsconfig.json deleted file mode 120000 index 5098169aa..000000000 --- a/plugins/log/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/log/tsconfig.json b/plugins/log/tsconfig.json new file mode 100644 index 000000000..5098169aa --- /dev/null +++ b/plugins/log/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/positioner/tsconfig.json b/plugins/positioner/tsconfig.json deleted file mode 120000 index 5098169aa..000000000 --- a/plugins/positioner/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/positioner/tsconfig.json b/plugins/positioner/tsconfig.json new file mode 100644 index 000000000..5098169aa --- /dev/null +++ b/plugins/positioner/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/sql/tsconfig.json b/plugins/sql/tsconfig.json deleted file mode 120000 index 5098169aa..000000000 --- a/plugins/sql/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/sql/tsconfig.json b/plugins/sql/tsconfig.json new file mode 100644 index 000000000..5098169aa --- /dev/null +++ b/plugins/sql/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/store/tsconfig.json b/plugins/store/tsconfig.json deleted file mode 120000 index 5098169aa..000000000 --- a/plugins/store/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/store/tsconfig.json b/plugins/store/tsconfig.json new file mode 100644 index 000000000..5098169aa --- /dev/null +++ b/plugins/store/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/stronghold/tsconfig.json b/plugins/stronghold/tsconfig.json deleted file mode 120000 index 5098169aa..000000000 --- a/plugins/stronghold/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/stronghold/tsconfig.json b/plugins/stronghold/tsconfig.json new file mode 100644 index 000000000..5098169aa --- /dev/null +++ b/plugins/stronghold/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/upload/tsconfig.json b/plugins/upload/tsconfig.json deleted file mode 120000 index 5098169aa..000000000 --- a/plugins/upload/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/upload/tsconfig.json b/plugins/upload/tsconfig.json new file mode 100644 index 000000000..5098169aa --- /dev/null +++ b/plugins/upload/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/websocket/tsconfig.json b/plugins/websocket/tsconfig.json deleted file mode 120000 index 5098169aa..000000000 --- a/plugins/websocket/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/websocket/tsconfig.json b/plugins/websocket/tsconfig.json new file mode 100644 index 000000000..5098169aa --- /dev/null +++ b/plugins/websocket/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +} diff --git a/plugins/window-state/guest-js/index.ts b/plugins/window-state/guest-js/index.ts index 706e3cbfa..31d88f9ac 100644 --- a/plugins/window-state/guest-js/index.ts +++ b/plugins/window-state/guest-js/index.ts @@ -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 { + 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 { + return window.__TAURI_INVOKE__("plugin:window-state|restore_state", { label, flags, }); @@ -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 { + return restoreState(window.__TAURI_METADATA__.__currentWindow.label, flags); } export { restoreState, restoreStateCurrent, saveWindowState }; diff --git a/plugins/window-state/src/api-iife.js b/plugins/window-state/src/api-iife.js index 86c310f8c..3ded95ac5 100644 --- a/plugins/window-state/src/api-iife.js +++ b/plugins/window-state/src/api-iife.js @@ -1 +1 @@ -if("__TAURI__"in window){var __TAURI_WINDOWSTATE__=function(_){"use strict";var t;async function e(_,t){window.__TAURI_INVOKE__("plugin:window-state|restore_state",{label:_,flags:t})}return _.StateFlags=void 0,(t=_.StateFlags||(_.StateFlags={}))[t.SIZE=1]="SIZE",t[t.POSITION=2]="POSITION",t[t.MAXIMIZED=4]="MAXIMIZED",t[t.VISIBLE=8]="VISIBLE",t[t.DECORATIONS=16]="DECORATIONS",t[t.FULLSCREEN=32]="FULLSCREEN",t[t.ALL=63]="ALL",_.restoreState=e,_.restoreStateCurrent=async function(_){e(window.__TAURI_METADATA__.__currentWindow.label,_)},_.saveWindowState=async function(_){window.__TAURI_INVOKE__("plugin:window-state|save_window_state",{flags:_})},_}({});Object.defineProperty(window.__TAURI__,"windowState",{value:__TAURI_WINDOWSTATE__})} +if("__TAURI__"in window){var __TAURI_WINDOWSTATE__=function(t){"use strict";var _;async function e(t,_){return window.__TAURI_INVOKE__("plugin:window-state|restore_state",{label:t,flags:_})}return t.StateFlags=void 0,(_=t.StateFlags||(t.StateFlags={}))[_.SIZE=1]="SIZE",_[_.POSITION=2]="POSITION",_[_.MAXIMIZED=4]="MAXIMIZED",_[_.VISIBLE=8]="VISIBLE",_[_.DECORATIONS=16]="DECORATIONS",_[_.FULLSCREEN=32]="FULLSCREEN",_[_.ALL=63]="ALL",t.restoreState=e,t.restoreStateCurrent=async function(t){return e(window.__TAURI_METADATA__.__currentWindow.label,t)},t.saveWindowState=async function(t){return window.__TAURI_INVOKE__("plugin:window-state|save_window_state",{flags:t})},t}({});Object.defineProperty(window.__TAURI__,"windowState",{value:__TAURI_WINDOWSTATE__})} diff --git a/plugins/window-state/src/lib.rs b/plugins/window-state/src/lib.rs index 28e00b355..fa88be3bb 100644 --- a/plugins/window-state/src/lib.rs +++ b/plugins/window-state/src/lib.rs @@ -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, @@ -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>>); pub trait AppHandleExt { /// Saves all open windows state to disk @@ -177,7 +192,7 @@ impl WindowExt for Window { } if flags.contains(StateFlags::DECORATIONS) { - metadata.visible = self.is_visible()?; + metadata.decorated = self.is_decorated()?; } if flags.contains(StateFlags::FULLSCREEN) { diff --git a/plugins/window-state/tsconfig.json b/plugins/window-state/tsconfig.json deleted file mode 120000 index 5098169aa..000000000 --- a/plugins/window-state/tsconfig.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "extends": "../../tsconfig.base.json", - "include": ["guest-js/*.ts"] -} diff --git a/plugins/window-state/tsconfig.json b/plugins/window-state/tsconfig.json new file mode 100644 index 000000000..5098169aa --- /dev/null +++ b/plugins/window-state/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.base.json", + "include": ["guest-js/*.ts"] +}