From 38e8522be5532d9895450d5572c5aa6d1766f5f0 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Tue, 13 Jun 2023 15:47:55 +0300 Subject: [PATCH] fix(window-state): propagate promise (#435) closes #432 --- .changes/window-state-promise.md | 5 +++++ plugins/window-state/guest-js/index.ts | 14 ++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 .changes/window-state-promise.md diff --git a/.changes/window-state-promise.md b/.changes/window-state-promise.md new file mode 100644 index 00000000..f97c43df --- /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/window-state/guest-js/index.ts b/plugins/window-state/guest-js/index.ts index 706e3cbf..31d88f9a 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 };