You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tauri-plugins-workspace/plugins/window-state/guest-js/index.ts

43 lines
1.1 KiB

// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { invoke } from "@tauri-apps/api/primitives";
import { WindowLabel, getCurrent } from "@tauri-apps/api/window";
export enum StateFlags {
SIZE = 1 << 0,
POSITION = 1 << 1,
MAXIMIZED = 1 << 2,
VISIBLE = 1 << 3,
DECORATIONS = 1 << 4,
FULLSCREEN = 1 << 5,
ALL = SIZE | POSITION | MAXIMIZED | VISIBLE | DECORATIONS | FULLSCREEN,
}
/**
* Save the state of all open windows to disk.
*/
async function saveWindowState(flags: StateFlags): Promise<void> {
return invoke("plugin:window-state|save_window_state", { flags });
}
/**
* Restore the state for the specified window from disk.
*/
async function restoreState(
label: WindowLabel,
flags: StateFlags,
): Promise<void> {
return invoke("plugin:window-state|restore_state", { label, flags });
}
/**
* Restore the state for the current window from disk.
*/
async function restoreStateCurrent(flags: StateFlags): Promise<void> {
return restoreState(getCurrent().label, flags);
}
export { restoreState, restoreStateCurrent, saveWindowState };