@tauri-apps/plugin-window-state 2.0.0-alpha.0 → 2.0.0-alpha.2

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/README.md CHANGED
@@ -1,10 +1,10 @@
1
- ![plugin-window-state](banner.png)
1
+ ![plugin-window-state](https://github.com/tauri-apps/plugins-workspace/raw/v2/plugins/window-state/banner.png)
2
2
 
3
3
  Save window positions and sizes and restore them when the app is reopened.
4
4
 
5
5
  ## Install
6
6
 
7
- _This plugin requires a Rust version of at least **1.65**_
7
+ _This plugin requires a Rust version of at least **1.70**_
8
8
 
9
9
  There are three general methods of installation that we can recommend.
10
10
 
@@ -1,19 +1,3 @@
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
1
  export declare enum StateFlags {
18
2
  SIZE = 1,
19
3
  POSITION = 2,
@@ -1,3 +1,13 @@
1
+ var f=Object.defineProperty;var g=(a,b)=>{for(var c in b)f(a,c,{get:b[c],enumerable:!0});};var e=(a,b,c)=>{if(!b.has(a))throw TypeError("Cannot "+c)};var h$2=(a,b,c)=>(e(a,b,"read from private field"),c?c.call(a):b.get(a)),i$2=(a,b,c)=>{if(b.has(a))throw TypeError("Cannot add the same private member more than once");b instanceof WeakSet?b.add(a):b.set(a,c);},j=(a,b,c,d)=>(e(a,b,"write to private field"),d?d.call(a,c):b.set(a,c),c);
2
+
3
+ var T$1={};g(T$1,{Channel:()=>i$1,PluginListener:()=>o,addPluginListener:()=>l$1,convertFileSrc:()=>v$1,invoke:()=>u$1,transformCallback:()=>_$1});function _$1(e,n=!1){return window.__TAURI_INTERNALS__.transformCallback(e,n)}var r$1,i$1=class i{constructor(){this.__TAURI_CHANNEL_MARKER__=!0;i$2(this,r$1,()=>{});this.id=_$1(n=>{h$2(this,r$1).call(this,n);});}set onmessage(n){j(this,r$1,n);}get onmessage(){return h$2(this,r$1)}toJSON(){return `__CHANNEL__:${this.id}`}};r$1=new WeakMap;var o=class{constructor(n,s,t){this.plugin=n,this.event=s,this.channelId=t;}async unregister(){return u$1(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function l$1(e,n,s){let t=new i$1;return t.onmessage=s,u$1(`plugin:${e}|register_listener`,{event:n,handler:t}).then(()=>new o(e,n,t.id))}async function u$1(e,n={},s){return window.__TAURI_INTERNALS__.invoke(e,n,s)}function v$1(e,n="asset"){return window.__TAURI_INTERNALS__.convertFileSrc(e,n)}
4
+
5
+ var b$1={};g(b$1,{LogicalPosition:()=>h$1,LogicalSize:()=>r,PhysicalPosition:()=>i,PhysicalSize:()=>u});var r=class{constructor(t,e){this.type="Logical";this.width=t,this.height=e;}},u=class{constructor(t,e){this.type="Physical";this.width=t,this.height=e;}toLogical(t){return new r(this.width/t,this.height/t)}},h$1=class h{constructor(t,e){this.type="Logical";this.x=t,this.y=e;}},i=class{constructor(t,e){this.type="Physical";this.x=t,this.y=e;}toLogical(t){return new h$1(this.x/t,this.y/t)}};
6
+
7
+ var E={};g(E,{TauriEvent:()=>l,emit:()=>D$1,listen:()=>c$1,once:()=>W$1});var l=(e=>(e.WINDOW_RESIZED="tauri://resize",e.WINDOW_MOVED="tauri://move",e.WINDOW_CLOSE_REQUESTED="tauri://close-requested",e.WINDOW_CREATED="tauri://window-created",e.WINDOW_DESTROYED="tauri://destroyed",e.WINDOW_FOCUS="tauri://focus",e.WINDOW_BLUR="tauri://blur",e.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",e.WINDOW_THEME_CHANGED="tauri://theme-changed",e.WINDOW_FILE_DROP="tauri://file-drop",e.WINDOW_FILE_DROP_HOVER="tauri://file-drop-hover",e.WINDOW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled",e.MENU="tauri://menu",e))(l||{});async function s(n,t){await u$1("plugin:event|unlisten",{event:n,eventId:t});}async function c$1(n,t,i){return u$1("plugin:event|listen",{event:n,windowLabel:i?.target,handler:_$1(t)}).then(r=>async()=>s(n,r))}async function W$1(n,t,i){return c$1(n,r=>{t(r),s(n,r.id).catch(()=>{});},i)}async function D$1(n,t,i){await u$1("plugin:event|emit",{event:n,windowLabel:i?.target,payload:t});}
8
+
9
+ var T={};g(T,{CloseRequestedEvent:()=>d,Effect:()=>S,EffectState:()=>C,LogicalPosition:()=>h$1,LogicalSize:()=>r,PhysicalPosition:()=>i,PhysicalSize:()=>u,ProgressBarStatus:()=>_,UserAttentionType:()=>v,Window:()=>c,availableMonitors:()=>x,currentMonitor:()=>D,getAll:()=>b,getCurrent:()=>z,primaryMonitor:()=>L});var v=(n=>(n[n.Critical=1]="Critical",n[n.Informational=2]="Informational",n))(v||{}),d=class{constructor(e){this._preventDefault=!1;this.event=e.event,this.windowLabel=e.windowLabel,this.id=e.id;}preventDefault(){this._preventDefault=!0;}isPreventDefault(){return this._preventDefault}},_=(o=>(o.None="none",o.Normal="normal",o.Indeterminate="indeterminate",o.Paused="paused",o.Error="error",o))(_||{});function z(){return new c(window.__TAURI_INTERNALS__.metadata.currentWindow.label,{skip:!0})}function b(){return window.__TAURI_INTERNALS__.metadata.windows.map(a=>new c(a.label,{skip:!0}))}var P=["tauri://created","tauri://error"],c=class a{constructor(e,n={}){this.label=e,this.listeners=Object.create(null),n?.skip||u$1("plugin:window|create",{options:{...n,label:e}}).then(async()=>this.emit("tauri://created")).catch(async t=>this.emit("tauri://error",t));}static getByLabel(e){return b().some(n=>n.label===e)?new a(e,{skip:!0}):null}static getCurrent(){return z()}static getAll(){return b()}static async getFocusedWindow(){for(let e of b())if(await e.isFocused())return e;return null}async listen(e,n){return this._handleTauriEvent(e,n)?Promise.resolve(()=>{let t=this.listeners[e];t.splice(t.indexOf(n),1);}):c$1(e,n,{target:this.label})}async once(e,n){return this._handleTauriEvent(e,n)?Promise.resolve(()=>{let t=this.listeners[e];t.splice(t.indexOf(n),1);}):W$1(e,n,{target:this.label})}async emit(e,n){if(P.includes(e)){for(let t of this.listeners[e]||[])t({event:e,id:-1,windowLabel:this.label,payload:n});return Promise.resolve()}return D$1(e,n,{target:this.label})}_handleTauriEvent(e,n){return P.includes(e)?(e in this.listeners?this.listeners[e].push(n):this.listeners[e]=[n],!0):!1}async scaleFactor(){return u$1("plugin:window|scale_factor",{label:this.label})}async innerPosition(){return u$1("plugin:window|inner_position",{label:this.label}).then(({x:e,y:n})=>new i(e,n))}async outerPosition(){return u$1("plugin:window|outer_position",{label:this.label}).then(({x:e,y:n})=>new i(e,n))}async innerSize(){return u$1("plugin:window|inner_size",{label:this.label}).then(({width:e,height:n})=>new u(e,n))}async outerSize(){return u$1("plugin:window|outer_size",{label:this.label}).then(({width:e,height:n})=>new u(e,n))}async isFullscreen(){return u$1("plugin:window|is_fullscreen",{label:this.label})}async isMinimized(){return u$1("plugin:window|is_minimized",{label:this.label})}async isMaximized(){return u$1("plugin:window|is_maximized",{label:this.label})}async isFocused(){return u$1("plugin:window|is_focused",{label:this.label})}async isDecorated(){return u$1("plugin:window|is_decorated",{label:this.label})}async isResizable(){return u$1("plugin:window|is_resizable",{label:this.label})}async isMaximizable(){return u$1("plugin:window|is_maximizable",{label:this.label})}async isMinimizable(){return u$1("plugin:window|is_minimizable",{label:this.label})}async isClosable(){return u$1("plugin:window|is_closable",{label:this.label})}async isVisible(){return u$1("plugin:window|is_visible",{label:this.label})}async title(){return u$1("plugin:window|title",{label:this.label})}async theme(){return u$1("plugin:window|theme",{label:this.label})}async center(){return u$1("plugin:window|center",{label:this.label})}async requestUserAttention(e){let n=null;return e&&(e===1?n={type:"Critical"}:n={type:"Informational"}),u$1("plugin:window|request_user_attention",{label:this.label,value:n})}async setResizable(e){return u$1("plugin:window|set_resizable",{label:this.label,value:e})}async setMaximizable(e){return u$1("plugin:window|set_maximizable",{label:this.label,value:e})}async setMinimizable(e){return u$1("plugin:window|set_minimizable",{label:this.label,value:e})}async setClosable(e){return u$1("plugin:window|set_closable",{label:this.label,value:e})}async setTitle(e){return u$1("plugin:window|set_title",{label:this.label,value:e})}async maximize(){return u$1("plugin:window|maximize",{label:this.label})}async unmaximize(){return u$1("plugin:window|unmaximize",{label:this.label})}async toggleMaximize(){return u$1("plugin:window|toggle_maximize",{label:this.label})}async minimize(){return u$1("plugin:window|minimize",{label:this.label})}async unminimize(){return u$1("plugin:window|unminimize",{label:this.label})}async show(){return u$1("plugin:window|show",{label:this.label})}async hide(){return u$1("plugin:window|hide",{label:this.label})}async close(){return u$1("plugin:window|close",{label:this.label})}async setDecorations(e){return u$1("plugin:window|set_decorations",{label:this.label,value:e})}async setShadow(e){return u$1("plugin:window|set_shadow",{label:this.label,value:e})}async setEffects(e){return u$1("plugin:window|set_effects",{label:this.label,value:e})}async clearEffects(){return u$1("plugin:window|set_effects",{label:this.label,value:null})}async setAlwaysOnTop(e){return u$1("plugin:window|set_always_on_top",{label:this.label,value:e})}async setAlwaysOnBottom(e){return u$1("plugin:window|set_always_on_bottom",{label:this.label,value:e})}async setContentProtected(e){return u$1("plugin:window|set_content_protected",{label:this.label,value:e})}async setSize(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return u$1("plugin:window|set_size",{label:this.label,value:{type:e.type,data:{width:e.width,height:e.height}}})}async setMinSize(e){if(e&&e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return u$1("plugin:window|set_min_size",{label:this.label,value:e?{type:e.type,data:{width:e.width,height:e.height}}:null})}async setMaxSize(e){if(e&&e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return u$1("plugin:window|set_max_size",{label:this.label,value:e?{type:e.type,data:{width:e.width,height:e.height}}:null})}async setPosition(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");return u$1("plugin:window|set_position",{label:this.label,value:{type:e.type,data:{x:e.x,y:e.y}}})}async setFullscreen(e){return u$1("plugin:window|set_fullscreen",{label:this.label,value:e})}async setFocus(){return u$1("plugin:window|set_focus",{label:this.label})}async setIcon(e){return u$1("plugin:window|set_icon",{label:this.label,value:typeof e=="string"?e:Array.from(e)})}async setSkipTaskbar(e){return u$1("plugin:window|set_skip_taskbar",{label:this.label,value:e})}async setCursorGrab(e){return u$1("plugin:window|set_cursor_grab",{label:this.label,value:e})}async setCursorVisible(e){return u$1("plugin:window|set_cursor_visible",{label:this.label,value:e})}async setCursorIcon(e){return u$1("plugin:window|set_cursor_icon",{label:this.label,value:e})}async setCursorPosition(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");return u$1("plugin:window|set_cursor_position",{label:this.label,value:{type:e.type,data:{x:e.x,y:e.y}}})}async setIgnoreCursorEvents(e){return u$1("plugin:window|set_ignore_cursor_events",{label:this.label,value:e})}async startDragging(){return u$1("plugin:window|start_dragging",{label:this.label})}async setProgressBar(e){return u$1("plugin:window|set_progress_bar",{label:this.label,value:e})}async onResized(e){return this.listen("tauri://resize",n=>{n.payload=W(n.payload),e(n);})}async onMoved(e){return this.listen("tauri://move",n=>{n.payload=F(n.payload),e(n);})}async onCloseRequested(e){return this.listen("tauri://close-requested",n=>{let t=new d(n);Promise.resolve(e(t)).then(()=>{if(!t.isPreventDefault())return this.close()});})}async onFocusChanged(e){let n=await this.listen("tauri://focus",s=>{e({...s,payload:!0});}),t=await this.listen("tauri://blur",s=>{e({...s,payload:!1});});return ()=>{n(),t();}}async onScaleChanged(e){return this.listen("tauri://scale-change",e)}async onMenuClicked(e){return this.listen("tauri://menu",e)}async onFileDropEvent(e){let n=await this.listen("tauri://file-drop",o=>{e({...o,payload:{type:"drop",paths:o.payload}});}),t=await this.listen("tauri://file-drop-hover",o=>{e({...o,payload:{type:"hover",paths:o.payload}});}),s=await this.listen("tauri://file-drop-cancelled",o=>{e({...o,payload:{type:"cancel"}});});return ()=>{n(),t(),s();}}async onThemeChanged(e){return this.listen("tauri://theme-changed",e)}},S=(l=>(l.AppearanceBased="appearanceBased",l.Light="light",l.Dark="dark",l.MediumLight="mediumLight",l.UltraDark="ultraDark",l.Titlebar="titlebar",l.Selection="selection",l.Menu="menu",l.Popover="popover",l.Sidebar="sidebar",l.HeaderView="headerView",l.Sheet="sheet",l.WindowBackground="windowBackground",l.HudWindow="hudWindow",l.FullScreenUI="fullScreenUI",l.Tooltip="tooltip",l.ContentBackground="contentBackground",l.UnderWindowBackground="underWindowBackground",l.UnderPageBackground="underPageBackground",l.Mica="mica",l.Blur="blur",l.Acrylic="acrylic",l.Tabbed="tabbed",l.TabbedDark="tabbedDark",l.TabbedLight="tabbedLight",l))(S||{}),C=(t=>(t.FollowsWindowActiveState="followsWindowActiveState",t.Active="active",t.Inactive="inactive",t))(C||{});function h(a){return a===null?null:{name:a.name,scaleFactor:a.scaleFactor,position:F(a.position),size:W(a.size)}}function F(a){return new i(a.x,a.y)}function W(a){return new u(a.width,a.height)}async function D(){return u$1("plugin:window|current_monitor").then(h)}async function L(){return u$1("plugin:window|primary_monitor").then(h)}async function x(){return u$1("plugin:window|available_monitors").then(a=>a.map(h))}
10
+
1
11
  // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
2
12
  // SPDX-License-Identifier: Apache-2.0
3
13
  // SPDX-License-Identifier: MIT
@@ -15,13 +25,15 @@ var StateFlags;
15
25
  * Save the state of all open windows to disk.
16
26
  */
17
27
  async function saveWindowState(flags) {
18
- window.__TAURI_INVOKE__("plugin:window-state|save_window_state", { flags });
28
+ return u$1("plugin:window-state|save_window_state", {
29
+ flags,
30
+ });
19
31
  }
20
32
  /**
21
33
  * Restore the state for the specified window from disk.
22
34
  */
23
35
  async function restoreState(label, flags) {
24
- window.__TAURI_INVOKE__("plugin:window-state|restore_state", {
36
+ return u$1("plugin:window-state|restore_state", {
25
37
  label,
26
38
  flags,
27
39
  });
@@ -30,7 +42,7 @@ async function restoreState(label, flags) {
30
42
  * Restore the state for the current window from disk.
31
43
  */
32
44
  async function restoreStateCurrent(flags) {
33
- restoreState(window.__TAURI_METADATA__.__currentWindow.label, flags);
45
+ return restoreState(z().label, flags);
34
46
  }
35
47
 
36
48
  export { StateFlags, restoreState, restoreStateCurrent, saveWindowState };
package/dist-js/index.mjs CHANGED
@@ -1,3 +1,6 @@
1
+ import { invoke } from '@tauri-apps/api/primitives';
2
+ import { getCurrent } from '@tauri-apps/api/window';
3
+
1
4
  // Copyright 2019-2023 Tauri Programme within The Commons Conservancy
2
5
  // SPDX-License-Identifier: Apache-2.0
3
6
  // SPDX-License-Identifier: MIT
@@ -15,13 +18,15 @@ var StateFlags;
15
18
  * Save the state of all open windows to disk.
16
19
  */
17
20
  async function saveWindowState(flags) {
18
- window.__TAURI_INVOKE__("plugin:window-state|save_window_state", { flags });
21
+ return invoke("plugin:window-state|save_window_state", {
22
+ flags,
23
+ });
19
24
  }
20
25
  /**
21
26
  * Restore the state for the specified window from disk.
22
27
  */
23
28
  async function restoreState(label, flags) {
24
- window.__TAURI_INVOKE__("plugin:window-state|restore_state", {
29
+ return invoke("plugin:window-state|restore_state", {
25
30
  label,
26
31
  flags,
27
32
  });
@@ -30,7 +35,7 @@ async function restoreState(label, flags) {
30
35
  * Restore the state for the current window from disk.
31
36
  */
32
37
  async function restoreStateCurrent(flags) {
33
- restoreState(window.__TAURI_METADATA__.__currentWindow.label, flags);
38
+ return restoreState(getCurrent().label, flags);
34
39
  }
35
40
 
36
41
  export { StateFlags, restoreState, restoreStateCurrent, saveWindowState };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tauri-apps/plugin-window-state",
3
- "version": "2.0.0-alpha.0",
3
+ "version": "2.0.0-alpha.2",
4
4
  "description": "Save window positions and sizes and restore them when the app is reopened.",
5
5
  "license": "MIT or APACHE-2.0",
6
6
  "authors": [
@@ -22,10 +22,10 @@
22
22
  "LICENSE"
23
23
  ],
24
24
  "devDependencies": {
25
- "tslib": "^2.5.0"
25
+ "tslib": "2.6.0"
26
26
  },
27
27
  "dependencies": {
28
- "@tauri-apps/api": "2.0.0-alpha.4"
28
+ "@tauri-apps/api": "2.0.0-alpha.9"
29
29
  },
30
30
  "scripts": {
31
31
  "build": "rollup -c"