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 <fabianlars@fabianlars.de>
pull/439/head
Amr Bashir 2 years ago committed by GitHub
parent c73049d3ed
commit 84b3612393
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
"window-state": "patch"
---
Correctly set decoration state if no saved state xists

@ -0,0 +1,5 @@
---
"window-state-js": "patch"
---
Correctly propagate the promise inside `saveWindowState`, `restoreState` and `restoreStateCurrent` so callers can choose to `await` them.

@ -1,4 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

@ -1,4 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

@ -1,4 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

@ -1,4 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

@ -1,4 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

@ -1,4 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

@ -1,4 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

@ -1,4 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

@ -1,4 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

@ -1,4 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.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<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,
});
@ -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 };

@ -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__})}

@ -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<Mutex<HashMap<String, WindowState>>>);
pub trait AppHandleExt {
/// Saves all open windows state to disk
@ -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) {

@ -1,4 +0,0 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}

@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["guest-js/*.ts"]
}
Loading…
Cancel
Save