@tauri-apps/plugin-window-state 2.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.spdx +20 -0
- package/README.md +107 -0
- package/dist-js/index.d.ts +38 -0
- package/dist-js/index.min.js +37 -0
- package/dist-js/index.mjs +37 -0
- package/package.json +33 -0
package/LICENSE.spdx
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
SPDXVersion: SPDX-2.1
|
|
2
|
+
DataLicense: CC0-1.0
|
|
3
|
+
PackageName: tauri
|
|
4
|
+
DataFormat: SPDXRef-1
|
|
5
|
+
PackageSupplier: Organization: The Tauri Programme in the Commons Conservancy
|
|
6
|
+
PackageHomePage: https://tauri.app
|
|
7
|
+
PackageLicenseDeclared: Apache-2.0
|
|
8
|
+
PackageLicenseDeclared: MIT
|
|
9
|
+
PackageCopyrightText: 2019-2022, The Tauri Programme in the Commons Conservancy
|
|
10
|
+
PackageSummary: <text>Tauri is a rust project that enables developers to make secure
|
|
11
|
+
and small desktop applications using a web frontend.
|
|
12
|
+
</text>
|
|
13
|
+
PackageComment: <text>The package includes the following libraries; see
|
|
14
|
+
Relationship information.
|
|
15
|
+
</text>
|
|
16
|
+
Created: 2019-05-20T09:00:00Z
|
|
17
|
+
PackageDownloadLocation: git://github.com/tauri-apps/tauri
|
|
18
|
+
PackageDownloadLocation: git+https://github.com/tauri-apps/tauri.git
|
|
19
|
+
PackageDownloadLocation: git+ssh://github.com/tauri-apps/tauri.git
|
|
20
|
+
Creator: Person: Daniel Thompson-Yvetot
|
package/README.md
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
Save window positions and sizes and restore them when the app is reopened.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
_This plugin requires a Rust version of at least **1.65**_
|
|
8
|
+
|
|
9
|
+
There are three general methods of installation that we can recommend.
|
|
10
|
+
|
|
11
|
+
1. Use crates.io and npm (easiest, and requires you to trust that our publishing pipeline worked)
|
|
12
|
+
2. Pull sources directly from Github using git tags / revision hashes (most secure)
|
|
13
|
+
3. Git submodule install this repo in your tauri project and then use file protocol to ingest the source (most secure, but inconvenient to use)
|
|
14
|
+
|
|
15
|
+
Install the Core plugin by adding the following to your `Cargo.toml` file:
|
|
16
|
+
|
|
17
|
+
`src-tauri/Cargo.toml`
|
|
18
|
+
|
|
19
|
+
```toml
|
|
20
|
+
[dependencies]
|
|
21
|
+
tauri-plugin-window-state = "2.0.0-alpha"
|
|
22
|
+
# alternatively with Git:
|
|
23
|
+
tauri-plugin-window-state = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" }
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
You can install the JavaScript Guest bindings using your preferred JavaScript package manager:
|
|
27
|
+
|
|
28
|
+
> Note: Since most JavaScript package managers are unable to install packages from git monorepos we provide read-only mirrors of each plugin. This makes installation option 2 more ergonomic to use.
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
pnpm add @tauri-apps/plugin-window-state
|
|
32
|
+
# or
|
|
33
|
+
npm add @tauri-apps/plugin-window-state
|
|
34
|
+
# or
|
|
35
|
+
yarn add @tauri-apps/plugin-window-state
|
|
36
|
+
|
|
37
|
+
# alternatively with Git:
|
|
38
|
+
pnpm add https://github.com/tauri-apps/tauri-plugin-window-state#v2
|
|
39
|
+
# or
|
|
40
|
+
npm add https://github.com/tauri-apps/tauri-plugin-window-state#v2
|
|
41
|
+
# or
|
|
42
|
+
yarn add https://github.com/tauri-apps/tauri-plugin-window-state#v2
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
First you need to register the core plugin with Tauri:
|
|
48
|
+
|
|
49
|
+
`src-tauri/src/main.rs`
|
|
50
|
+
|
|
51
|
+
```rust
|
|
52
|
+
fn main() {
|
|
53
|
+
tauri::Builder::default()
|
|
54
|
+
.plugin(tauri_plugin_window_state::Builder::default().build())
|
|
55
|
+
.run(tauri::generate_context!())
|
|
56
|
+
.expect("error while running tauri application");
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Afterwards all windows will remember their state when the app is being closed and will restore to their previous state on the next launch.
|
|
61
|
+
|
|
62
|
+
Optionally you can also tell the plugin to save the state of all open window to disk by using the `save_window_state()` method exposed by the `AppHandleExt` trait:
|
|
63
|
+
|
|
64
|
+
```rust
|
|
65
|
+
use tauri_plugin_window_state::{AppHandleExt, StateFlags};
|
|
66
|
+
|
|
67
|
+
// `tauri::AppHandle` now has the following additional method
|
|
68
|
+
app.save_window_state(StateFlags::all()); // will save the state of all open windows to disk
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
or through Javascript
|
|
72
|
+
|
|
73
|
+
```javascript
|
|
74
|
+
import { saveWindowState, StateFlags } from "@tauri-apps/plugin-window-state";
|
|
75
|
+
|
|
76
|
+
saveWindowState(StateFlags.ALL);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
To manually restore a windows state from disk you can call the `restore_state()` method exposed by the `WindowExt` trait:
|
|
80
|
+
|
|
81
|
+
```rust
|
|
82
|
+
use tauri_plugin_window_state::{WindowExt, StateFlags};
|
|
83
|
+
|
|
84
|
+
// all `Window` types now have the following additional method
|
|
85
|
+
window.restore_state(StateFlags::all()); // will restore the windows state from disk
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
or through Javascript
|
|
89
|
+
|
|
90
|
+
```javascript
|
|
91
|
+
import {
|
|
92
|
+
restoreStateCurrent,
|
|
93
|
+
StateFlags,
|
|
94
|
+
} from "@tauri-apps/plugin-window-state";
|
|
95
|
+
|
|
96
|
+
restoreStateCurrent(StateFlags.ALL);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Contributing
|
|
100
|
+
|
|
101
|
+
PRs accepted. Please make sure to read the Contributing Guide before making a pull request.
|
|
102
|
+
|
|
103
|
+
## License
|
|
104
|
+
|
|
105
|
+
Code: (c) 2015 - Present - The Tauri Programme within The Commons Conservancy.
|
|
106
|
+
|
|
107
|
+
MIT or MIT/Apache 2.0 where applicable.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
declare global {
|
|
2
|
+
interface Window {
|
|
3
|
+
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
interface WindowDef {
|
|
7
|
+
label: string;
|
|
8
|
+
}
|
|
9
|
+
declare global {
|
|
10
|
+
interface Window {
|
|
11
|
+
__TAURI_METADATA__: {
|
|
12
|
+
__windows: WindowDef[];
|
|
13
|
+
__currentWindow: WindowDef;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export declare enum StateFlags {
|
|
18
|
+
SIZE = 1,
|
|
19
|
+
POSITION = 2,
|
|
20
|
+
MAXIMIZED = 4,
|
|
21
|
+
VISIBLE = 8,
|
|
22
|
+
DECORATIONS = 16,
|
|
23
|
+
FULLSCREEN = 32,
|
|
24
|
+
ALL = 63
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Save the state of all open windows to disk.
|
|
28
|
+
*/
|
|
29
|
+
declare function saveWindowState(flags: StateFlags): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Restore the state for the specified window from disk.
|
|
32
|
+
*/
|
|
33
|
+
declare function restoreState(label: string, flags: StateFlags): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* Restore the state for the current window from disk.
|
|
36
|
+
*/
|
|
37
|
+
declare function restoreStateCurrent(flags: StateFlags): Promise<void>;
|
|
38
|
+
export { restoreState, restoreStateCurrent, saveWindowState };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// SPDX-License-Identifier: MIT
|
|
4
|
+
var StateFlags;
|
|
5
|
+
(function (StateFlags) {
|
|
6
|
+
StateFlags[StateFlags["SIZE"] = 1] = "SIZE";
|
|
7
|
+
StateFlags[StateFlags["POSITION"] = 2] = "POSITION";
|
|
8
|
+
StateFlags[StateFlags["MAXIMIZED"] = 4] = "MAXIMIZED";
|
|
9
|
+
StateFlags[StateFlags["VISIBLE"] = 8] = "VISIBLE";
|
|
10
|
+
StateFlags[StateFlags["DECORATIONS"] = 16] = "DECORATIONS";
|
|
11
|
+
StateFlags[StateFlags["FULLSCREEN"] = 32] = "FULLSCREEN";
|
|
12
|
+
StateFlags[StateFlags["ALL"] = 63] = "ALL";
|
|
13
|
+
})(StateFlags || (StateFlags = {}));
|
|
14
|
+
/**
|
|
15
|
+
* Save the state of all open windows to disk.
|
|
16
|
+
*/
|
|
17
|
+
async function saveWindowState(flags) {
|
|
18
|
+
window.__TAURI_INVOKE__("plugin:window-state|save_window_state", { flags });
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Restore the state for the specified window from disk.
|
|
22
|
+
*/
|
|
23
|
+
async function restoreState(label, flags) {
|
|
24
|
+
window.__TAURI_INVOKE__("plugin:window-state|restore_state", {
|
|
25
|
+
label,
|
|
26
|
+
flags,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Restore the state for the current window from disk.
|
|
31
|
+
*/
|
|
32
|
+
async function restoreStateCurrent(flags) {
|
|
33
|
+
restoreState(window.__TAURI_METADATA__.__currentWindow.label, flags);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { StateFlags, restoreState, restoreStateCurrent, saveWindowState };
|
|
37
|
+
//# sourceMappingURL=index.min.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
// SPDX-License-Identifier: MIT
|
|
4
|
+
var StateFlags;
|
|
5
|
+
(function (StateFlags) {
|
|
6
|
+
StateFlags[StateFlags["SIZE"] = 1] = "SIZE";
|
|
7
|
+
StateFlags[StateFlags["POSITION"] = 2] = "POSITION";
|
|
8
|
+
StateFlags[StateFlags["MAXIMIZED"] = 4] = "MAXIMIZED";
|
|
9
|
+
StateFlags[StateFlags["VISIBLE"] = 8] = "VISIBLE";
|
|
10
|
+
StateFlags[StateFlags["DECORATIONS"] = 16] = "DECORATIONS";
|
|
11
|
+
StateFlags[StateFlags["FULLSCREEN"] = 32] = "FULLSCREEN";
|
|
12
|
+
StateFlags[StateFlags["ALL"] = 63] = "ALL";
|
|
13
|
+
})(StateFlags || (StateFlags = {}));
|
|
14
|
+
/**
|
|
15
|
+
* Save the state of all open windows to disk.
|
|
16
|
+
*/
|
|
17
|
+
async function saveWindowState(flags) {
|
|
18
|
+
window.__TAURI_INVOKE__("plugin:window-state|save_window_state", { flags });
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Restore the state for the specified window from disk.
|
|
22
|
+
*/
|
|
23
|
+
async function restoreState(label, flags) {
|
|
24
|
+
window.__TAURI_INVOKE__("plugin:window-state|restore_state", {
|
|
25
|
+
label,
|
|
26
|
+
flags,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Restore the state for the current window from disk.
|
|
31
|
+
*/
|
|
32
|
+
async function restoreStateCurrent(flags) {
|
|
33
|
+
restoreState(window.__TAURI_METADATA__.__currentWindow.label, flags);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { StateFlags, restoreState, restoreStateCurrent, saveWindowState };
|
|
37
|
+
//# sourceMappingURL=index.mjs.map
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tauri-apps/plugin-window-state",
|
|
3
|
+
"version": "2.0.0-alpha.0",
|
|
4
|
+
"description": "Save window positions and sizes and restore them when the app is reopened.",
|
|
5
|
+
"license": "MIT or APACHE-2.0",
|
|
6
|
+
"authors": [
|
|
7
|
+
"Tauri Programme within The Commons Conservancy"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"browser": "dist-js/index.min.js",
|
|
11
|
+
"module": "dist-js/index.mjs",
|
|
12
|
+
"types": "dist-js/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
"import": "./dist-js/index.mjs",
|
|
15
|
+
"types": "./dist-js/index.d.ts",
|
|
16
|
+
"browser": "./dist-js/index.min.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist-js",
|
|
20
|
+
"!dist-js/**/*.map",
|
|
21
|
+
"README.md",
|
|
22
|
+
"LICENSE"
|
|
23
|
+
],
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"tslib": "^2.5.0"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@tauri-apps/api": "2.0.0-alpha.4"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "rollup -c"
|
|
32
|
+
}
|
|
33
|
+
}
|