Files
Amr Bashir 84b3612393 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>
2023-06-13 23:30:39 +03:00

61 lines
1.4 KiB
TypeScript

// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
}
}
interface WindowDef {
label: string;
}
declare global {
interface Window {
__TAURI_METADATA__: {
__windows: WindowDef[];
__currentWindow: WindowDef;
};
}
}
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 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): Promise<void> {
return window.__TAURI_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(window.__TAURI_METADATA__.__currentWindow.label, flags);
}
export { restoreState, restoreStateCurrent, saveWindowState };