feat(window-state): add js api, closes #254
parent
fa8e68fd6a
commit
9166089464
@ -0,0 +1 @@
|
|||||||
|
node_modules
|
@ -0,0 +1,35 @@
|
|||||||
|
import { invoke } from "@tauri-apps/api/tauri";
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves all open windows state to disk
|
||||||
|
*/
|
||||||
|
async function saveWindowState(flags: StateFlags) {
|
||||||
|
invoke("plugin:window-state|js_save_window_state", { flags });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore the specified window state from disk
|
||||||
|
*/
|
||||||
|
async function restoreState(label: WindowLabel, flags: StateFlags) {
|
||||||
|
invoke("plugin:window-state|js_restore_state", { label, flags });
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restore the current window state from disk
|
||||||
|
*/
|
||||||
|
async function restoreStateCurrent(flags: StateFlags) {
|
||||||
|
restoreState(getCurrent().label, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
export { restoreState, restoreStateCurrent, saveWindowState };
|
@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"name": "tauri-plugin-window-state-api",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"description": "Save window positions and sizse and restore them when the app is reopened.",
|
||||||
|
"license": "MIT or APACHE-2.0",
|
||||||
|
"authors": [
|
||||||
|
"Tauri Programme within The Commons Conservancy"
|
||||||
|
],
|
||||||
|
"type": "module",
|
||||||
|
"browser": "dist-js/index.min.js",
|
||||||
|
"module": "dist-js/index.mjs",
|
||||||
|
"types": "dist-js/index.d.ts",
|
||||||
|
"exports": {
|
||||||
|
"import": "./dist-js/index.mjs",
|
||||||
|
"types": "./dist-js/index.d.ts",
|
||||||
|
"browser": "./dist-js/index.min.js"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"build": "rollup -c"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"dist-js",
|
||||||
|
"!dist-js/**/*.map",
|
||||||
|
"README.md",
|
||||||
|
"LICENSE"
|
||||||
|
],
|
||||||
|
"devDependencies": {
|
||||||
|
"tslib": "^2.4.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@tauri-apps/api": "^1.2.0"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
import { readFileSync } from "fs";
|
||||||
|
|
||||||
|
import { createConfig } from "../../shared/rollup.config.mjs";
|
||||||
|
|
||||||
|
export default createConfig({
|
||||||
|
input: "guest-js/index.ts",
|
||||||
|
pkg: JSON.parse(
|
||||||
|
readFileSync(new URL("./package.json", import.meta.url), "utf8")
|
||||||
|
),
|
||||||
|
external: [/^@tauri-apps\/api/],
|
||||||
|
});
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue