fix(window-state): propagate promise (#435)

closes #432
pull/436/head
Amr Bashir 2 years ago committed by amrbashir
parent 48d11d50a8
commit 38e8522be5
No known key found for this signature in database
GPG Key ID: BBD7A47A2003FF33

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

@ -34,15 +34,17 @@ export enum StateFlags {
/** /**
* Save the state of all open windows to disk. * Save the state of all open windows to disk.
*/ */
async function saveWindowState(flags: StateFlags) { async function saveWindowState(flags: StateFlags): Promise<void> {
window.__TAURI_INVOKE__("plugin:window-state|save_window_state", { flags }); return window.__TAURI_INVOKE__("plugin:window-state|save_window_state", {
flags,
});
} }
/** /**
* Restore the state for the specified window from disk. * Restore the state for the specified window from disk.
*/ */
async function restoreState(label: string, flags: StateFlags) { async function restoreState(label: string, flags: StateFlags): Promise<void> {
window.__TAURI_INVOKE__("plugin:window-state|restore_state", { return window.__TAURI_INVOKE__("plugin:window-state|restore_state", {
label, label,
flags, flags,
}); });
@ -51,8 +53,8 @@ async function restoreState(label: string, flags: StateFlags) {
/** /**
* Restore the state for the current window from disk. * Restore the state for the current window from disk.
*/ */
async function restoreStateCurrent(flags: StateFlags) { async function restoreStateCurrent(flags: StateFlags): Promise<void> {
restoreState(window.__TAURI_METADATA__.__currentWindow.label, flags); return restoreState(window.__TAURI_METADATA__.__currentWindow.label, flags);
} }
export { restoreState, restoreStateCurrent, saveWindowState }; export { restoreState, restoreStateCurrent, saveWindowState };

Loading…
Cancel
Save