From beb6b139eb669dc0346b3de919aed024f649b9d2 Mon Sep 17 00:00:00 2001 From: Mo Date: Sun, 22 Oct 2023 16:39:40 +0330 Subject: [PATCH] Fix invoke calls in dialog & shell init scripts (#675) Co-authored-by: Lucas Nogueira --- .changes/fix-invoke-usage.md | 6 +++ .changes/fix-window-state-api.md | 5 +++ .github/workflows/test-rust.yml | 7 +--- .../dialog/{src/init.js => guest-js/init.ts} | 7 +++- plugins/dialog/rollup.config.mjs | 25 +++++++++++- plugins/dialog/src/init-iife.js | 1 + plugins/dialog/src/lib.rs | 2 +- plugins/shell/guest-js/init.ts | 40 +++++++++++++++++++ plugins/shell/rollup.config.mjs | 25 +++++++++++- plugins/shell/src/init-iife.js | 1 + plugins/shell/src/init.js | 39 ------------------ plugins/shell/src/lib.rs | 2 +- plugins/window-state/guest-js/index.ts | 16 +------- plugins/window-state/src/api-iife.js | 2 +- 14 files changed, 112 insertions(+), 66 deletions(-) create mode 100644 .changes/fix-invoke-usage.md create mode 100644 .changes/fix-window-state-api.md rename plugins/dialog/{src/init.js => guest-js/init.ts} (60%) create mode 100644 plugins/dialog/src/init-iife.js create mode 100644 plugins/shell/guest-js/init.ts create mode 100644 plugins/shell/src/init-iife.js delete mode 100644 plugins/shell/src/init.js diff --git a/.changes/fix-invoke-usage.md b/.changes/fix-invoke-usage.md new file mode 100644 index 00000000..8782bc15 --- /dev/null +++ b/.changes/fix-invoke-usage.md @@ -0,0 +1,6 @@ +--- +"shell": patch +"dialog": patch +--- + +Fix invoke usage. diff --git a/.changes/fix-window-state-api.md b/.changes/fix-window-state-api.md new file mode 100644 index 00000000..9ed99806 --- /dev/null +++ b/.changes/fix-window-state-api.md @@ -0,0 +1,5 @@ +--- +"window-state-js": patch +--- + +Fix usage of no longer available `__TAURI_METADATA__` API. diff --git a/.github/workflows/test-rust.yml b/.github/workflows/test-rust.yml index 69576040..8095d0e7 100644 --- a/.github/workflows/test-rust.yml +++ b/.github/workflows/test-rust.yml @@ -181,17 +181,12 @@ jobs: - uses: Swatinem/rust-cache@v2 with: - key: cache-${{ matrix.package }} + key: cache-${{ matrix.package }}-${{ matrix.platform.target }} - name: create dummy dist working-directory: examples/api run: mkdir dist - - name: Downgrade crates with MSRV conflict - # The --precise flag can only be used once per invocation. - run: | - cargo update -p time@0.3.24 --precise 0.3.23 - - name: install cross if: ${{ matrix.platform.runner == 'cross' }} run: cargo install cross --git https://github.com/cross-rs/cross diff --git a/plugins/dialog/src/init.js b/plugins/dialog/guest-js/init.ts similarity index 60% rename from plugins/dialog/src/init.js rename to plugins/dialog/guest-js/init.ts index c4107018..22a18775 100644 --- a/plugins/dialog/src/init.js +++ b/plugins/dialog/guest-js/init.ts @@ -2,13 +2,16 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT -window.alert = function (message) { +import { invoke } from "@tauri-apps/api/primitives"; + +window.alert = function (message: string) { invoke("plugin:dialog|message", { message: message.toString(), }); }; -window.confirm = function (message) { +// @ts-expect-error tauri does not have sync IPC :( +window.confirm = function (message: string) { return invoke("plugin:dialog|confirm", { message: message.toString(), }); diff --git a/plugins/dialog/rollup.config.mjs b/plugins/dialog/rollup.config.mjs index 99a3dd31..d2a3cda6 100644 --- a/plugins/dialog/rollup.config.mjs +++ b/plugins/dialog/rollup.config.mjs @@ -2,10 +2,33 @@ import { readFileSync } from "fs"; import { createConfig } from "../../shared/rollup.config.mjs"; -export default createConfig({ +import typescript from "@rollup/plugin-typescript"; +import resolve from "@rollup/plugin-node-resolve"; +import terser from "@rollup/plugin-terser"; + +const config = createConfig({ input: "guest-js/index.ts", pkg: JSON.parse( readFileSync(new URL("./package.json", import.meta.url), "utf8"), ), external: [/^@tauri-apps\/api/], }); + +config.push({ + input: "guest-js/init.ts", + output: { + file: "src/init-iife.js", + format: "iife", + }, + plugins: [ + resolve(), + typescript({ + sourceMap: false, + declaration: false, + declarationDir: undefined, + }), + terser(), + ], +}); + +export default config; diff --git a/plugins/dialog/src/init-iife.js b/plugins/dialog/src/init-iife.js new file mode 100644 index 00000000..fcfd45ca --- /dev/null +++ b/plugins/dialog/src/init-iife.js @@ -0,0 +1 @@ +!function(){"use strict";var e=Object.defineProperty,n=(e,n,t)=>{if(!n.has(e))throw TypeError("Cannot "+t)},t=(e,t,r)=>(n(e,t,"read from private field"),r?r.call(e):t.get(e));function r(e,n=!1){return window.__TAURI_INTERNALS__.transformCallback(e,n)}((n,t)=>{for(var r in t)e(n,r,{get:t[r],enumerable:!0})})({},{Channel:()=>s,PluginListener:()=>a,addPluginListener:()=>o,convertFileSrc:()=>c,invoke:()=>l,transformCallback:()=>r});var i,s=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,n,t)=>{if(n.has(e))throw TypeError("Cannot add the same private member more than once");n instanceof WeakSet?n.add(e):n.set(e,t)})(this,i,(()=>{})),this.id=r((e=>{t(this,i).call(this,e)}))}set onmessage(e){var t,r,s,a;s=e,n(t=this,r=i,"write to private field"),a?a.call(t,s):r.set(t,s)}get onmessage(){return t(this,i)}toJSON(){return`__CHANNEL__:${this.id}`}};i=new WeakMap;var a=class{constructor(e,n,t){this.plugin=e,this.event=n,this.channelId=t}async unregister(){return l(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function o(e,n,t){let r=new s;return r.onmessage=t,l(`plugin:${e}|register_listener`,{event:n,handler:r}).then((()=>new a(e,n,r.id)))}async function l(e,n={},t){return window.__TAURI_INTERNALS__.invoke(e,n,t)}function c(e,n="asset"){return window.__TAURI_INTERNALS__.convertFileSrc(e,n)}window.alert=function(e){l("plugin:dialog|message",{message:e.toString()})},window.confirm=function(e){return l("plugin:dialog|confirm",{message:e.toString()})}}(); diff --git a/plugins/dialog/src/lib.rs b/plugins/dialog/src/lib.rs index 626249b2..325ba92d 100644 --- a/plugins/dialog/src/lib.rs +++ b/plugins/dialog/src/lib.rs @@ -84,7 +84,7 @@ pub fn init() -> TauriPlugin { // Dialogs are implemented natively on Android #[cfg(not(target_os = "android"))] { - let mut init_script = include_str!("init.js").to_string(); + let mut init_script = include_str!("init-iife.js").to_string(); init_script.push_str(include_str!("api-iife.js")); builder = builder.js_init_script(init_script); } diff --git a/plugins/shell/guest-js/init.ts b/plugins/shell/guest-js/init.ts new file mode 100644 index 00000000..61c10a9e --- /dev/null +++ b/plugins/shell/guest-js/init.ts @@ -0,0 +1,40 @@ +// 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"; + +// open links with the API +function openLinks() { + document.querySelector("body")?.addEventListener("click", function (e) { + let target = e.target as HTMLElement; + while (target != null) { + if (target.matches("a")) { + const t = target as HTMLAnchorElement; + if ( + t.href && + ["http://", "https://", "mailto:", "tel:"].some((v) => + t.href.startsWith(v), + ) && + t.target === "_blank" + ) { + invoke("plugin:shell|open", { + path: t.href, + }); + e.preventDefault(); + } + break; + } + target = target.parentElement as HTMLElement; + } + }); +} + +if ( + document.readyState === "complete" || + document.readyState === "interactive" +) { + openLinks(); +} else { + window.addEventListener("DOMContentLoaded", openLinks, true); +} diff --git a/plugins/shell/rollup.config.mjs b/plugins/shell/rollup.config.mjs index 99a3dd31..d2a3cda6 100644 --- a/plugins/shell/rollup.config.mjs +++ b/plugins/shell/rollup.config.mjs @@ -2,10 +2,33 @@ import { readFileSync } from "fs"; import { createConfig } from "../../shared/rollup.config.mjs"; -export default createConfig({ +import typescript from "@rollup/plugin-typescript"; +import resolve from "@rollup/plugin-node-resolve"; +import terser from "@rollup/plugin-terser"; + +const config = createConfig({ input: "guest-js/index.ts", pkg: JSON.parse( readFileSync(new URL("./package.json", import.meta.url), "utf8"), ), external: [/^@tauri-apps\/api/], }); + +config.push({ + input: "guest-js/init.ts", + output: { + file: "src/init-iife.js", + format: "iife", + }, + plugins: [ + resolve(), + typescript({ + sourceMap: false, + declaration: false, + declarationDir: undefined, + }), + terser(), + ], +}); + +export default config; diff --git a/plugins/shell/src/init-iife.js b/plugins/shell/src/init-iife.js new file mode 100644 index 00000000..6c32a6c7 --- /dev/null +++ b/plugins/shell/src/init-iife.js @@ -0,0 +1 @@ +!function(){"use strict";var e=Object.defineProperty,t=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},n=(e,n,r)=>(t(e,n,"read from private field"),r?r.call(e):n.get(e));function r(e,t=!1){return window.__TAURI_INTERNALS__.transformCallback(e,t)}((t,n)=>{for(var r in n)e(t,r,{get:n[r],enumerable:!0})})({},{Channel:()=>i,PluginListener:()=>s,addPluginListener:()=>o,convertFileSrc:()=>c,invoke:()=>l,transformCallback:()=>r});var a,i=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)})(this,a,(()=>{})),this.id=r((e=>{n(this,a).call(this,e)}))}set onmessage(e){var n,r,i,s;i=e,t(n=this,r=a,"write to private field"),s?s.call(n,i):r.set(n,i)}get onmessage(){return n(this,a)}toJSON(){return`__CHANNEL__:${this.id}`}};a=new WeakMap;var s=class{constructor(e,t,n){this.plugin=e,this.event=t,this.channelId=n}async unregister(){return l(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function o(e,t,n){let r=new i;return r.onmessage=n,l(`plugin:${e}|register_listener`,{event:t,handler:r}).then((()=>new s(e,t,r.id)))}async function l(e,t={},n){return window.__TAURI_INTERNALS__.invoke(e,t,n)}function c(e,t="asset"){return window.__TAURI_INTERNALS__.convertFileSrc(e,t)}function h(){var e;null===(e=document.querySelector("body"))||void 0===e||e.addEventListener("click",(function(e){let t=e.target;for(;null!=t;){if(t.matches("a")){const n=t;n.href&&["http://","https://","mailto:","tel:"].some((e=>n.href.startsWith(e)))&&"_blank"===n.target&&(l("plugin:shell|open",{path:n.href}),e.preventDefault());break}t=t.parentElement}}))}"complete"===document.readyState||"interactive"===document.readyState?h():window.addEventListener("DOMContentLoaded",h,!0)}(); diff --git a/plugins/shell/src/init.js b/plugins/shell/src/init.js deleted file mode 100644 index fa637a5b..00000000 --- a/plugins/shell/src/init.js +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2019-2023 Tauri Programme within The Commons Conservancy -// SPDX-License-Identifier: Apache-2.0 -// SPDX-License-Identifier: MIT - -(function () { - // open links with the API - function openLinks() { - document.querySelector("body").addEventListener("click", function (e) { - var target = e.target; - while (target != null) { - if (target.matches("a")) { - if ( - target.href && - ["http://", "https://", "mailto:", "tel:"].some((v) => - target.href.startsWith(v), - ) && - target.target === "_blank" - ) { - invoke("plugin:shell|open", { - path: target.href, - }); - e.preventDefault(); - } - break; - } - target = target.parentElement; - } - }); - } - - if ( - document.readyState === "complete" || - document.readyState === "interactive" - ) { - openLinks(); - } else { - window.addEventListener("DOMContentLoaded", openLinks, true); - } -})(); diff --git a/plugins/shell/src/lib.rs b/plugins/shell/src/lib.rs index c20ae942..36d022aa 100644 --- a/plugins/shell/src/lib.rs +++ b/plugins/shell/src/lib.rs @@ -78,7 +78,7 @@ impl> ShellExt for T { } pub fn init() -> TauriPlugin> { - let mut init_script = include_str!("init.js").to_string(); + let mut init_script = include_str!("init-iife.js").to_string(); init_script.push_str(include_str!("api-iife.js")); Builder::>::new("shell") diff --git a/plugins/window-state/guest-js/index.ts b/plugins/window-state/guest-js/index.ts index ecfa4e8e..4d84f898 100644 --- a/plugins/window-state/guest-js/index.ts +++ b/plugins/window-state/guest-js/index.ts @@ -3,19 +3,7 @@ // SPDX-License-Identifier: MIT import { invoke } from "@tauri-apps/api/primitives"; - -interface WindowDef { - label: string; -} - -declare global { - interface Window { - __TAURI_METADATA__: { - __windows: WindowDef[]; - __currentWindow: WindowDef; - }; - } -} +import { getCurrent } from "@tauri-apps/api/window"; export enum StateFlags { SIZE = 1 << 0, @@ -50,7 +38,7 @@ async function restoreState(label: string, flags: StateFlags): Promise { * Restore the state for the current window from disk. */ async function restoreStateCurrent(flags: StateFlags): Promise { - return restoreState(window.__TAURI_METADATA__.__currentWindow.label, flags); + return restoreState(getCurrent().label, flags); } export { restoreState, restoreStateCurrent, saveWindowState }; diff --git a/plugins/window-state/src/api-iife.js b/plugins/window-state/src/api-iife.js index abd48f8e..680f61cd 100644 --- a/plugins/window-state/src/api-iife.js +++ b/plugins/window-state/src/api-iife.js @@ -1 +1 @@ -if("__TAURI__"in window){var __TAURI_WINDOWSTATE__=function(e){"use strict";var t=Object.defineProperty,n=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},r=(e,t,r)=>(n(e,t,"read from private field"),r?r.call(e):t.get(e));function a(e,t=!1){return window.__TAURI_INTERNALS__.transformCallback(e,t)}((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})({},{Channel:()=>s,PluginListener:()=>o,addPluginListener:()=>l,convertFileSrc:()=>u,invoke:()=>c,transformCallback:()=>a});var i,s=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)})(this,i,(()=>{})),this.id=a((e=>{r(this,i).call(this,e)}))}set onmessage(e){var t,r,a,s;a=e,n(t=this,r=i,"write to private field"),s?s.call(t,a):r.set(t,a)}get onmessage(){return r(this,i)}toJSON(){return`__CHANNEL__:${this.id}`}};i=new WeakMap;var _,o=class{constructor(e,t,n){this.plugin=e,this.event=t,this.channelId=n}async unregister(){return c(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function l(e,t,n){let r=new s;return r.onmessage=n,c(`plugin:${e}|register_listener`,{event:t,handler:r}).then((()=>new o(e,t,r.id)))}async function c(e,t={},n){return window.__TAURI_INTERNALS__.invoke(e,t,n)}function u(e,t="asset"){return window.__TAURI_INTERNALS__.convertFileSrc(e,t)}async function I(e,t){return c("plugin:window-state|restore_state",{label:e,flags:t})}return e.StateFlags=void 0,(_=e.StateFlags||(e.StateFlags={}))[_.SIZE=1]="SIZE",_[_.POSITION=2]="POSITION",_[_.MAXIMIZED=4]="MAXIMIZED",_[_.VISIBLE=8]="VISIBLE",_[_.DECORATIONS=16]="DECORATIONS",_[_.FULLSCREEN=32]="FULLSCREEN",_[_.ALL=63]="ALL",e.restoreState=I,e.restoreStateCurrent=async function(e){return I(window.__TAURI_METADATA__.__currentWindow.label,e)},e.saveWindowState=async function(e){return c("plugin:window-state|save_window_state",{flags:e})},e}({});Object.defineProperty(window.__TAURI__,"windowState",{value:__TAURI_WINDOWSTATE__})} +if("__TAURI__"in window){var __TAURI_WINDOWSTATE__=function(e){"use strict";var t=Object.defineProperty,i=(e,i)=>{for(var n in i)t(e,n,{get:i[n],enumerable:!0})},n=(e,t,i)=>{if(!t.has(e))throw TypeError("Cannot "+i)},a=(e,t,i)=>(n(e,t,"read from private field"),i?i.call(e):t.get(e));function l(e,t=!1){return window.__TAURI_INTERNALS__.transformCallback(e,t)}i({},{Channel:()=>r,PluginListener:()=>o,addPluginListener:()=>u,convertFileSrc:()=>h,invoke:()=>c,transformCallback:()=>l});var s,r=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,t,i)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,i)})(this,s,(()=>{})),this.id=l((e=>{a(this,s).call(this,e)}))}set onmessage(e){((e,t,i,a)=>{n(e,t,"write to private field"),a?a.call(e,i):t.set(e,i)})(this,s,e)}get onmessage(){return a(this,s)}toJSON(){return`__CHANNEL__:${this.id}`}};s=new WeakMap;var o=class{constructor(e,t,i){this.plugin=e,this.event=t,this.channelId=i}async unregister(){return c(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function u(e,t,i){let n=new r;return n.onmessage=i,c(`plugin:${e}|register_listener`,{event:t,handler:n}).then((()=>new o(e,t,n.id)))}async function c(e,t={},i){return window.__TAURI_INTERNALS__.invoke(e,t,i)}function h(e,t="asset"){return window.__TAURI_INTERNALS__.convertFileSrc(e,t)}i({},{LogicalPosition:()=>b,LogicalSize:()=>d,PhysicalPosition:()=>p,PhysicalSize:()=>w});var d=class{constructor(e,t){this.type="Logical",this.width=e,this.height=t}},w=class{constructor(e,t){this.type="Physical",this.width=e,this.height=t}toLogical(e){return new d(this.width/e,this.height/e)}},b=class{constructor(e,t){this.type="Logical",this.x=e,this.y=t}},p=class{constructor(e,t){this.type="Physical",this.x=e,this.y=t}toLogical(e){return new b(this.x/e,this.y/e)}};i({},{TauriEvent:()=>g,emit:()=>v,listen:()=>_,once:()=>m});var g=(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))(g||{});async function y(e,t){await c("plugin:event|unlisten",{event:e,eventId:t})}async function _(e,t,i){return c("plugin:event|listen",{event:e,windowLabel:i?.target,handler:l(t)}).then((t=>async()=>y(e,t)))}async function m(e,t,i){return _(e,(i=>{t(i),y(e,i.id).catch((()=>{}))}),i)}async function v(e,t,i){await c("plugin:event|emit",{event:e,windowLabel:i?.target,payload:t})}i({},{CloseRequestedEvent:()=>I,Effect:()=>C,EffectState:()=>N,LogicalPosition:()=>b,LogicalSize:()=>d,PhysicalPosition:()=>p,PhysicalSize:()=>w,ProgressBarStatus:()=>S,UserAttentionType:()=>E,Window:()=>T,availableMonitors:()=>M,currentMonitor:()=>k,getAll:()=>z,getCurrent:()=>L,primaryMonitor:()=>x});var f,E=((f=E||{})[f.Critical=1]="Critical",f[f.Informational=2]="Informational",f),I=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}},S=(e=>(e.None="none",e.Normal="normal",e.Indeterminate="indeterminate",e.Paused="paused",e.Error="error",e))(S||{});function L(){return new T(window.__TAURI_INTERNALS__.metadata.currentWindow.label,{skip:!0})}function z(){return window.__TAURI_INTERNALS__.metadata.windows.map((e=>new T(e.label,{skip:!0})))}var P,D,A=["tauri://created","tauri://error"],T=class e{constructor(e,t={}){this.label=e,this.listeners=Object.create(null),t?.skip||c("plugin:window|create",{options:{...t,label:e}}).then((async()=>this.emit("tauri://created"))).catch((async e=>this.emit("tauri://error",e)))}static getByLabel(t){return z().some((e=>e.label===t))?new e(t,{skip:!0}):null}static getCurrent(){return L()}static getAll(){return z()}static async getFocusedWindow(){for(let e of z())if(await e.isFocused())return e;return null}async listen(e,t){return this._handleTauriEvent(e,t)?Promise.resolve((()=>{let i=this.listeners[e];i.splice(i.indexOf(t),1)})):_(e,t,{target:this.label})}async once(e,t){return this._handleTauriEvent(e,t)?Promise.resolve((()=>{let i=this.listeners[e];i.splice(i.indexOf(t),1)})):m(e,t,{target:this.label})}async emit(e,t){if(A.includes(e)){for(let i of this.listeners[e]||[])i({event:e,id:-1,windowLabel:this.label,payload:t});return Promise.resolve()}return v(e,t,{target:this.label})}_handleTauriEvent(e,t){return!!A.includes(e)&&(e in this.listeners?this.listeners[e].push(t):this.listeners[e]=[t],!0)}async scaleFactor(){return c("plugin:window|scale_factor",{label:this.label})}async innerPosition(){return c("plugin:window|inner_position",{label:this.label}).then((({x:e,y:t})=>new p(e,t)))}async outerPosition(){return c("plugin:window|outer_position",{label:this.label}).then((({x:e,y:t})=>new p(e,t)))}async innerSize(){return c("plugin:window|inner_size",{label:this.label}).then((({width:e,height:t})=>new w(e,t)))}async outerSize(){return c("plugin:window|outer_size",{label:this.label}).then((({width:e,height:t})=>new w(e,t)))}async isFullscreen(){return c("plugin:window|is_fullscreen",{label:this.label})}async isMinimized(){return c("plugin:window|is_minimized",{label:this.label})}async isMaximized(){return c("plugin:window|is_maximized",{label:this.label})}async isFocused(){return c("plugin:window|is_focused",{label:this.label})}async isDecorated(){return c("plugin:window|is_decorated",{label:this.label})}async isResizable(){return c("plugin:window|is_resizable",{label:this.label})}async isMaximizable(){return c("plugin:window|is_maximizable",{label:this.label})}async isMinimizable(){return c("plugin:window|is_minimizable",{label:this.label})}async isClosable(){return c("plugin:window|is_closable",{label:this.label})}async isVisible(){return c("plugin:window|is_visible",{label:this.label})}async title(){return c("plugin:window|title",{label:this.label})}async theme(){return c("plugin:window|theme",{label:this.label})}async center(){return c("plugin:window|center",{label:this.label})}async requestUserAttention(e){let t=null;return e&&(t=1===e?{type:"Critical"}:{type:"Informational"}),c("plugin:window|request_user_attention",{label:this.label,value:t})}async setResizable(e){return c("plugin:window|set_resizable",{label:this.label,value:e})}async setMaximizable(e){return c("plugin:window|set_maximizable",{label:this.label,value:e})}async setMinimizable(e){return c("plugin:window|set_minimizable",{label:this.label,value:e})}async setClosable(e){return c("plugin:window|set_closable",{label:this.label,value:e})}async setTitle(e){return c("plugin:window|set_title",{label:this.label,value:e})}async maximize(){return c("plugin:window|maximize",{label:this.label})}async unmaximize(){return c("plugin:window|unmaximize",{label:this.label})}async toggleMaximize(){return c("plugin:window|toggle_maximize",{label:this.label})}async minimize(){return c("plugin:window|minimize",{label:this.label})}async unminimize(){return c("plugin:window|unminimize",{label:this.label})}async show(){return c("plugin:window|show",{label:this.label})}async hide(){return c("plugin:window|hide",{label:this.label})}async close(){return c("plugin:window|close",{label:this.label})}async setDecorations(e){return c("plugin:window|set_decorations",{label:this.label,value:e})}async setShadow(e){return c("plugin:window|set_shadow",{label:this.label,value:e})}async setEffects(e){return c("plugin:window|set_effects",{label:this.label,value:e})}async clearEffects(){return c("plugin:window|set_effects",{label:this.label,value:null})}async setAlwaysOnTop(e){return c("plugin:window|set_always_on_top",{label:this.label,value:e})}async setAlwaysOnBottom(e){return c("plugin:window|set_always_on_bottom",{label:this.label,value:e})}async setContentProtected(e){return c("plugin:window|set_content_protected",{label:this.label,value:e})}async setSize(e){if(!e||"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return c("plugin:window|set_size",{label:this.label,value:{type:e.type,data:{width:e.width,height:e.height}}})}async setMinSize(e){if(e&&"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return c("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&&"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return c("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||"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");return c("plugin:window|set_position",{label:this.label,value:{type:e.type,data:{x:e.x,y:e.y}}})}async setFullscreen(e){return c("plugin:window|set_fullscreen",{label:this.label,value:e})}async setFocus(){return c("plugin:window|set_focus",{label:this.label})}async setIcon(e){return c("plugin:window|set_icon",{label:this.label,value:"string"==typeof e?e:Array.from(e)})}async setSkipTaskbar(e){return c("plugin:window|set_skip_taskbar",{label:this.label,value:e})}async setCursorGrab(e){return c("plugin:window|set_cursor_grab",{label:this.label,value:e})}async setCursorVisible(e){return c("plugin:window|set_cursor_visible",{label:this.label,value:e})}async setCursorIcon(e){return c("plugin:window|set_cursor_icon",{label:this.label,value:e})}async setCursorPosition(e){if(!e||"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");return c("plugin:window|set_cursor_position",{label:this.label,value:{type:e.type,data:{x:e.x,y:e.y}}})}async setIgnoreCursorEvents(e){return c("plugin:window|set_ignore_cursor_events",{label:this.label,value:e})}async startDragging(){return c("plugin:window|start_dragging",{label:this.label})}async setProgressBar(e){return c("plugin:window|set_progress_bar",{label:this.label,value:e})}async onResized(e){return this.listen("tauri://resize",(t=>{t.payload=R(t.payload),e(t)}))}async onMoved(e){return this.listen("tauri://move",(t=>{t.payload=O(t.payload),e(t)}))}async onCloseRequested(e){return this.listen("tauri://close-requested",(t=>{let i=new I(t);Promise.resolve(e(i)).then((()=>{if(!i.isPreventDefault())return this.close()}))}))}async onFocusChanged(e){let t=await this.listen("tauri://focus",(t=>{e({...t,payload:!0})})),i=await this.listen("tauri://blur",(t=>{e({...t,payload:!1})}));return()=>{t(),i()}}async onScaleChanged(e){return this.listen("tauri://scale-change",e)}async onMenuClicked(e){return this.listen("tauri://menu",e)}async onFileDropEvent(e){let t=await this.listen("tauri://file-drop",(t=>{e({...t,payload:{type:"drop",paths:t.payload}})})),i=await this.listen("tauri://file-drop-hover",(t=>{e({...t,payload:{type:"hover",paths:t.payload}})})),n=await this.listen("tauri://file-drop-cancelled",(t=>{e({...t,payload:{type:"cancel"}})}));return()=>{t(),i(),n()}}async onThemeChanged(e){return this.listen("tauri://theme-changed",e)}},C=(e=>(e.AppearanceBased="appearanceBased",e.Light="light",e.Dark="dark",e.MediumLight="mediumLight",e.UltraDark="ultraDark",e.Titlebar="titlebar",e.Selection="selection",e.Menu="menu",e.Popover="popover",e.Sidebar="sidebar",e.HeaderView="headerView",e.Sheet="sheet",e.WindowBackground="windowBackground",e.HudWindow="hudWindow",e.FullScreenUI="fullScreenUI",e.Tooltip="tooltip",e.ContentBackground="contentBackground",e.UnderWindowBackground="underWindowBackground",e.UnderPageBackground="underPageBackground",e.Mica="mica",e.Blur="blur",e.Acrylic="acrylic",e.Tabbed="tabbed",e.TabbedDark="tabbedDark",e.TabbedLight="tabbedLight",e))(C||{}),N=((P=N||{}).FollowsWindowActiveState="followsWindowActiveState",P.Active="active",P.Inactive="inactive",P);function W(e){return null===e?null:{name:e.name,scaleFactor:e.scaleFactor,position:O(e.position),size:R(e.size)}}function O(e){return new p(e.x,e.y)}function R(e){return new w(e.width,e.height)}async function k(){return c("plugin:window|current_monitor").then(W)}async function x(){return c("plugin:window|primary_monitor").then(W)}async function M(){return c("plugin:window|available_monitors").then((e=>e.map(W)))}async function F(e,t){return c("plugin:window-state|restore_state",{label:e,flags:t})}return e.StateFlags=void 0,(D=e.StateFlags||(e.StateFlags={}))[D.SIZE=1]="SIZE",D[D.POSITION=2]="POSITION",D[D.MAXIMIZED=4]="MAXIMIZED",D[D.VISIBLE=8]="VISIBLE",D[D.DECORATIONS=16]="DECORATIONS",D[D.FULLSCREEN=32]="FULLSCREEN",D[D.ALL=63]="ALL",e.restoreState=F,e.restoreStateCurrent=async function(e){return F(L().label,e)},e.saveWindowState=async function(e){return c("plugin:window-state|save_window_state",{flags:e})},e}({});Object.defineProperty(window.__TAURI__,"windowState",{value:__TAURI_WINDOWSTATE__})}