diff --git a/.changes/positioner-v2-handleIconState.md b/.changes/positioner-v2-handleIconState.md new file mode 100644 index 000000000..e43c84d87 --- /dev/null +++ b/.changes/positioner-v2-handleIconState.md @@ -0,0 +1,6 @@ +--- +"positioner": patch +"positioner-js": patch +--- + +`handleIconState` function for use in JavaScript event handlers. This allows one to update the TrayIcon state through JavaScript and fully create and handle the TrayIcon without requiring Rust (and the side-effect of creating a TrayIcon). diff --git a/plugins/barcode-scanner/api-iife.js b/plugins/barcode-scanner/api-iife.js index cd6f1193c..620b59a70 100644 --- a/plugins/barcode-scanner/api-iife.js +++ b/plugins/barcode-scanner/api-iife.js @@ -1 +1 @@ -if("__TAURI__"in window){var __TAURI_PLUGIN_BARCODE_SCANNER__=function(n){"use strict";async function e(n,e={},r){return window.__TAURI_INTERNALS__.invoke(n,e,r)}var r;return"function"==typeof SuppressedError&&SuppressedError,n.Format=void 0,(r=n.Format||(n.Format={})).QRCode="QR_CODE",r.UPC_A="UPC_A",r.UPC_E="UPC_E",r.EAN8="EAN_8",r.EAN13="EAN_13",r.Code39="CODE_39",r.Code93="CODE_93",r.Code128="CODE_128",r.Codabar="CODABAR",r.ITF="ITF",r.Aztec="AZTEC",r.DataMatrix="DATA_MATRIX",r.PDF417="PDF_417",n.cancel=async function(){await e("plugin:barcode-scanner|cancel")},n.checkPermissions=async function(){return await async function(n){return e(`plugin:${n}|request_permissions`)}("barcode-scanner").then((n=>n.camera))},n.openAppSettings=async function(){await e("plugin:barcode-scanner|open_app_settings")},n.requestPermissions=async function(){return await async function(n){return e(`plugin:${n}|check_permissions`)}("barcode-scanner").then((n=>n.camera))},n.scan=async function(n){return await e("plugin:barcode-scanner|scan",{...n})},n}({});Object.defineProperty(window.__TAURI__,"barcodeScanner",{value:__TAURI_PLUGIN_BARCODE_SCANNER__})} +if("__TAURI__"in window){var __TAURI_PLUGIN_BARCODE_SCANNER__=function(n){"use strict";async function e(n,e={},r){return window.__TAURI_INTERNALS__.invoke(n,e,r)}var r;return"function"==typeof SuppressedError&&SuppressedError,n.Format=void 0,(r=n.Format||(n.Format={})).QRCode="QR_CODE",r.UPC_A="UPC_A",r.UPC_E="UPC_E",r.EAN8="EAN_8",r.EAN13="EAN_13",r.Code39="CODE_39",r.Code93="CODE_93",r.Code128="CODE_128",r.Codabar="CODABAR",r.ITF="ITF",r.Aztec="AZTEC",r.DataMatrix="DATA_MATRIX",r.PDF417="PDF_417",n.cancel=async function(){await e("plugin:barcode-scanner|cancel")},n.checkPermissions=async function(){return await async function(n){return e(`plugin:${n}|check_permissions`)}("barcode-scanner").then((n=>n.camera))},n.openAppSettings=async function(){await e("plugin:barcode-scanner|open_app_settings")},n.requestPermissions=async function(){return await async function(n){return e(`plugin:${n}|request_permissions`)}("barcode-scanner").then((n=>n.camera))},n.scan=async function(n){return await e("plugin:barcode-scanner|scan",{...n})},n}({});Object.defineProperty(window.__TAURI__,"barcodeScanner",{value:__TAURI_PLUGIN_BARCODE_SCANNER__})} diff --git a/plugins/positioner/README.md b/plugins/positioner/README.md index db9bab5ab..3c8ac1d91 100644 --- a/plugins/positioner/README.md +++ b/plugins/positioner/README.md @@ -58,6 +58,7 @@ fn main() { .plugin(tauri_plugin_positioner::init()) // This is required to get tray-relative positions to work .setup(|app| { + // note that this will create a new TrayIcon TrayIconBuilder::new() .on_tray_icon_event(|app, event| { tauri_plugin_positioner::on_tray_event(app.app_handle(), &event); @@ -70,6 +71,40 @@ fn main() { } ``` +Alternatively, you may handle the tray events through JavaScript. Register the plugin as previously noted. + +```rust +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_positioner::init()) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); +} +``` + +And in JavaScript, the `action` passed to the TrayIcon should include the handler. + +```javascript +import { + moveWindow, + Position, + handleIconState, +} from "@tauri-apps/plugin-positioner"; + +const action = async (event: TrayIconEvent) => { + // add the handle in the action to update the state + await handleIconState(event); + if ("click" in event) { + const { click } = event; + // note this option requires enabling the `tray-icon` + // feature in the Cargo.toml + await moveWindow(Position.TrayLeft); + } +}; + +const tray = await TrayIcon.new({ id: "main", action }); +``` + Afterwards all the plugin's APIs are available through the JavaScript guest bindings: ```javascript diff --git a/plugins/positioner/api-iife.js b/plugins/positioner/api-iife.js index d0c8ba69c..5504ebe87 100644 --- a/plugins/positioner/api-iife.js +++ b/plugins/positioner/api-iife.js @@ -1 +1 @@ -if("__TAURI__"in window){var __TAURI_PLUGIN_POSITIONER__=function(t){"use strict";var o;return"function"==typeof SuppressedError&&SuppressedError,t.Position=void 0,(o=t.Position||(t.Position={}))[o.TopLeft=0]="TopLeft",o[o.TopRight=1]="TopRight",o[o.BottomLeft=2]="BottomLeft",o[o.BottomRight=3]="BottomRight",o[o.TopCenter=4]="TopCenter",o[o.BottomCenter=5]="BottomCenter",o[o.LeftCenter=6]="LeftCenter",o[o.RightCenter=7]="RightCenter",o[o.Center=8]="Center",o[o.TrayLeft=9]="TrayLeft",o[o.TrayBottomLeft=10]="TrayBottomLeft",o[o.TrayRight=11]="TrayRight",o[o.TrayBottomRight=12]="TrayBottomRight",o[o.TrayCenter=13]="TrayCenter",o[o.TrayBottomCenter=14]="TrayBottomCenter",t.moveWindow=async function(t){await async function(t,o={},e){return window.__TAURI_INTERNALS__.invoke(t,o,e)}("plugin:positioner|move_window",{position:t})},t}({});Object.defineProperty(window.__TAURI__,"positioner",{value:__TAURI_PLUGIN_POSITIONER__})} +if("__TAURI__"in window){var __TAURI_PLUGIN_POSITIONER__=function(t){"use strict";async function o(t,o={},e){return window.__TAURI_INTERNALS__.invoke(t,o,e)}var e;return"function"==typeof SuppressedError&&SuppressedError,t.Position=void 0,(e=t.Position||(t.Position={}))[e.TopLeft=0]="TopLeft",e[e.TopRight=1]="TopRight",e[e.BottomLeft=2]="BottomLeft",e[e.BottomRight=3]="BottomRight",e[e.TopCenter=4]="TopCenter",e[e.BottomCenter=5]="BottomCenter",e[e.LeftCenter=6]="LeftCenter",e[e.RightCenter=7]="RightCenter",e[e.Center=8]="Center",e[e.TrayLeft=9]="TrayLeft",e[e.TrayBottomLeft=10]="TrayBottomLeft",e[e.TrayRight=11]="TrayRight",e[e.TrayBottomRight=12]="TrayBottomRight",e[e.TrayCenter=13]="TrayCenter",e[e.TrayBottomCenter=14]="TrayBottomCenter",t.handleIconState=async function(t){await async function(t){await o("plugin:positioner|set_tray_icon_state",{position:t.position,size:t.size})}(t.rect)},t.moveWindow=async function(t){await o("plugin:positioner|move_window",{position:t})},t}({});Object.defineProperty(window.__TAURI__,"positioner",{value:__TAURI_PLUGIN_POSITIONER__})} diff --git a/plugins/positioner/guest-js/index.ts b/plugins/positioner/guest-js/index.ts index 449e3298b..319f80db6 100644 --- a/plugins/positioner/guest-js/index.ts +++ b/plugins/positioner/guest-js/index.ts @@ -4,6 +4,7 @@ // SPDX-License-Identifier: MIT import { invoke } from '@tauri-apps/api/core' +import type { TrayIconEvent } from '@tauri-apps/api/tray' /** * Well known window positions. @@ -37,3 +38,14 @@ export async function moveWindow(to: Position): Promise { position: to }) } + +export async function handleIconState(event: TrayIconEvent): Promise { + await invokeSetTrayIconState(event.rect) +} + +async function invokeSetTrayIconState(rect: TrayIconEvent['rect']) { + await invoke('plugin:positioner|set_tray_icon_state', { + position: rect.position, + size: rect.size + }) +} diff --git a/plugins/positioner/permissions/autogenerated/commands/set_tray_icon_state.toml b/plugins/positioner/permissions/autogenerated/commands/set_tray_icon_state.toml new file mode 100644 index 000000000..dcc8fa56e --- /dev/null +++ b/plugins/positioner/permissions/autogenerated/commands/set_tray_icon_state.toml @@ -0,0 +1,8 @@ +# Automatically generated - DO NOT EDIT! + +"$schema" = "../../schemas/schema.json" + +[[permission]] +identifier = "allow-set-tray-icon-state" +description = "Enables the set_tray_icon_state to handle events and set the TrayIcon state." +commands.allow = ["set_tray_icon_state"] diff --git a/plugins/positioner/permissions/autogenerated/reference.md b/plugins/positioner/permissions/autogenerated/reference.md index f2a92c66f..324e4e56f 100644 --- a/plugins/positioner/permissions/autogenerated/reference.md +++ b/plugins/positioner/permissions/autogenerated/reference.md @@ -3,6 +3,7 @@ Allows the move_window command - `allow-move-window` +- `set-tray-icon-state` ## Permission Table @@ -36,6 +37,19 @@ Enables the move_window command without any pre-configured scope. Denies the move_window command without any pre-configured scope. + + + + + + +`positioner:allow-set-tray-icon-state` + + + + +Enables the set_tray_icon_state to handle events and set the TrayIcon state. + diff --git a/plugins/positioner/permissions/default.toml b/plugins/positioner/permissions/default.toml index b0b3b3e29..8492711c5 100644 --- a/plugins/positioner/permissions/default.toml +++ b/plugins/positioner/permissions/default.toml @@ -1,4 +1,4 @@ "$schema" = "schemas/schema.json" [default] description = "Allows the move_window command" -permissions = ["allow-move-window"] +permissions = ["allow-move-window", "set-tray-icon-state"] diff --git a/plugins/positioner/permissions/schemas/schema.json b/plugins/positioner/permissions/schemas/schema.json index f55148878..5bddddde3 100644 --- a/plugins/positioner/permissions/schemas/schema.json +++ b/plugins/positioner/permissions/schemas/schema.json @@ -304,6 +304,11 @@ "type": "string", "const": "deny-move-window" }, + { + "description": "Enables the set_tray_icon_state to handle events and set the TrayIcon state.", + "type": "string", + "const": "allow-set-tray-icon-state" + }, { "description": "Allows the move_window command", "type": "string", diff --git a/plugins/positioner/src/lib.rs b/plugins/positioner/src/lib.rs index 96c243e5f..81bfaef83 100644 --- a/plugins/positioner/src/lib.rs +++ b/plugins/positioner/src/lib.rs @@ -63,10 +63,27 @@ async fn move_window(window: tauri::Window, position: Position) - window.move_window(position) } +#[cfg(feature = "tray-icon")] +#[tauri::command] +fn set_tray_icon_state( + app: AppHandle, + position: PhysicalPosition, + size: PhysicalSize, +) { + app.state::() + .0 + .lock() + .unwrap() + .replace((position, size)); +} + /// The Tauri plugin that exposes [`WindowExt::move_window`] to the webview. pub fn init() -> TauriPlugin { - let plugin = - plugin::Builder::new("positioner").invoke_handler(tauri::generate_handler![move_window]); + let plugin = plugin::Builder::new("positioner").invoke_handler(tauri::generate_handler![ + move_window, + #[cfg(feature = "tray-icon")] + set_tray_icon_state + ]); #[cfg(feature = "tray-icon")] let plugin = plugin.setup(|app_handle, _api| { diff --git a/plugins/window-state/api-iife.js b/plugins/window-state/api-iife.js index 7f36809b3..de6e96136 100644 --- a/plugins/window-state/api-iife.js +++ b/plugins/window-state/api-iife.js @@ -1 +1 @@ -if("__TAURI__"in window){var __TAURI_PLUGIN_WINDOW_STATE__=function(e){"use strict";var t,i,n,a;function l(e,t=!1){return window.__TAURI_INTERNALS__.transformCallback(e,t)}async function s(e,t={},i){return window.__TAURI_INTERNALS__.invoke(e,t,i)}"function"==typeof SuppressedError&&SuppressedError;class r{get rid(){return function(e,t,i,n){if("a"===i&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?n:"a"===i?n.call(e):n?n.value:t.get(e)}(this,t,"f")}constructor(e){t.set(this,void 0),function(e,t,i,n,a){if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");t.set(e,i)}(this,t,e)}async close(){return s("plugin:resources|close",{rid:this.rid})}}t=new WeakMap;class o{constructor(e,t){this.type="Logical",this.width=e,this.height=t}}class u{constructor(e,t){this.type="Physical",this.width=e,this.height=t}toLogical(e){return new o(this.width/e,this.height/e)}}class c{constructor(e,t){this.type="Logical",this.x=e,this.y=t}}class d{constructor(e,t){this.type="Physical",this.x=e,this.y=t}toLogical(e){return new c(this.x/e,this.y/e)}}async function w(e,t){await s("plugin:event|unlisten",{event:e,eventId:t})}async function h(e,t,i){var n;const a="string"==typeof(null==i?void 0:i.target)?{kind:"AnyLabel",label:i.target}:null!==(n=null==i?void 0:i.target)&&void 0!==n?n:{kind:"Any"};return s("plugin:event|listen",{event:e,target:a,handler:l(t)}).then((t=>async()=>w(e,t)))}!function(e){e.WINDOW_RESIZED="tauri://resize",e.WINDOW_MOVED="tauri://move",e.WINDOW_CLOSE_REQUESTED="tauri://close-requested",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_CREATED="tauri://window-created",e.WEBVIEW_CREATED="tauri://webview-created",e.DRAG_ENTER="tauri://drag-enter",e.DRAG_OVER="tauri://drag-over",e.DRAG_DROP="tauri://drag-drop",e.DRAG_LEAVE="tauri://drag-leave"}(i||(i={}));class b extends r{constructor(e){super(e)}static async new(e,t,i){return s("plugin:image|new",{rgba:p(e),width:t,height:i}).then((e=>new b(e)))}static async fromBytes(e){return s("plugin:image|from_bytes",{bytes:p(e)}).then((e=>new b(e)))}static async fromPath(e){return s("plugin:image|from_path",{path:e}).then((e=>new b(e)))}async rgba(){return s("plugin:image|rgba",{rid:this.rid}).then((e=>new Uint8Array(e)))}async size(){return s("plugin:image|size",{rid:this.rid})}}function p(e){return null==e?null:"string"==typeof e?e:e instanceof b?e.rid:e}!function(e){e[e.Critical=1]="Critical",e[e.Informational=2]="Informational"}(n||(n={}));class y{constructor(e){this._preventDefault=!1,this.event=e.event,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}}function g(){return new v(window.__TAURI_INTERNALS__.metadata.currentWindow.label,{skip:!0})}async function _(){return s("plugin:window|get_all_windows").then((e=>e.map((e=>new v(e,{skip:!0})))))}!function(e){e.None="none",e.Normal="normal",e.Indeterminate="indeterminate",e.Paused="paused",e.Error="error"}(a||(a={}));const m=["tauri://created","tauri://error"];class v{constructor(e,t={}){var i;this.label=e,this.listeners=Object.create(null),(null==t?void 0:t.skip)||s("plugin:window|create",{options:{...t,parent:"string"==typeof t.parent?t.parent:null===(i=t.parent)||void 0===i?void 0:i.label,label:e}}).then((async()=>this.emit("tauri://created"))).catch((async e=>this.emit("tauri://error",e)))}static async getByLabel(e){var t;return null!==(t=(await _()).find((t=>t.label===e)))&&void 0!==t?t:null}static getCurrent(){return g()}static async getAll(){return _()}static async getFocusedWindow(){for(const e of await _())if(await e.isFocused())return e;return null}async listen(e,t){return this._handleTauriEvent(e,t)?()=>{const i=this.listeners[e];i.splice(i.indexOf(t),1)}:h(e,t,{target:{kind:"Window",label:this.label}})}async once(e,t){return this._handleTauriEvent(e,t)?()=>{const i=this.listeners[e];i.splice(i.indexOf(t),1)}:async function(e,t,i){return h(e,(i=>{w(e,i.id),t(i)}),i)}(e,t,{target:{kind:"Window",label:this.label}})}async emit(e,t){if(!m.includes(e))return async function(e,t){await s("plugin:event|emit",{event:e,payload:t})}(e,t);for(const i of this.listeners[e]||[])i({event:e,id:-1,payload:t})}async emitTo(e,t,i){if(!m.includes(t))return async function(e,t,i){const n="string"==typeof e?{kind:"AnyLabel",label:e}:e;await s("plugin:event|emit_to",{target:n,event:t,payload:i})}(e,t,i);for(const e of this.listeners[t]||[])e({event:t,id:-1,payload:i})}_handleTauriEvent(e,t){return!!m.includes(e)&&(e in this.listeners?this.listeners[e].push(t):this.listeners[e]=[t],!0)}async scaleFactor(){return s("plugin:window|scale_factor",{label:this.label})}async innerPosition(){return s("plugin:window|inner_position",{label:this.label}).then((({x:e,y:t})=>new d(e,t)))}async outerPosition(){return s("plugin:window|outer_position",{label:this.label}).then((({x:e,y:t})=>new d(e,t)))}async innerSize(){return s("plugin:window|inner_size",{label:this.label}).then((({width:e,height:t})=>new u(e,t)))}async outerSize(){return s("plugin:window|outer_size",{label:this.label}).then((({width:e,height:t})=>new u(e,t)))}async isFullscreen(){return s("plugin:window|is_fullscreen",{label:this.label})}async isMinimized(){return s("plugin:window|is_minimized",{label:this.label})}async isMaximized(){return s("plugin:window|is_maximized",{label:this.label})}async isFocused(){return s("plugin:window|is_focused",{label:this.label})}async isDecorated(){return s("plugin:window|is_decorated",{label:this.label})}async isResizable(){return s("plugin:window|is_resizable",{label:this.label})}async isMaximizable(){return s("plugin:window|is_maximizable",{label:this.label})}async isMinimizable(){return s("plugin:window|is_minimizable",{label:this.label})}async isClosable(){return s("plugin:window|is_closable",{label:this.label})}async isVisible(){return s("plugin:window|is_visible",{label:this.label})}async title(){return s("plugin:window|title",{label:this.label})}async theme(){return s("plugin:window|theme",{label:this.label})}async center(){return s("plugin:window|center",{label:this.label})}async requestUserAttention(e){let t=null;return e&&(t=e===n.Critical?{type:"Critical"}:{type:"Informational"}),s("plugin:window|request_user_attention",{label:this.label,value:t})}async setResizable(e){return s("plugin:window|set_resizable",{label:this.label,value:e})}async setMaximizable(e){return s("plugin:window|set_maximizable",{label:this.label,value:e})}async setMinimizable(e){return s("plugin:window|set_minimizable",{label:this.label,value:e})}async setClosable(e){return s("plugin:window|set_closable",{label:this.label,value:e})}async setTitle(e){return s("plugin:window|set_title",{label:this.label,value:e})}async maximize(){return s("plugin:window|maximize",{label:this.label})}async unmaximize(){return s("plugin:window|unmaximize",{label:this.label})}async toggleMaximize(){return s("plugin:window|toggle_maximize",{label:this.label})}async minimize(){return s("plugin:window|minimize",{label:this.label})}async unminimize(){return s("plugin:window|unminimize",{label:this.label})}async show(){return s("plugin:window|show",{label:this.label})}async hide(){return s("plugin:window|hide",{label:this.label})}async close(){return s("plugin:window|close",{label:this.label})}async destroy(){return s("plugin:window|destroy",{label:this.label})}async setDecorations(e){return s("plugin:window|set_decorations",{label:this.label,value:e})}async setShadow(e){return s("plugin:window|set_shadow",{label:this.label,value:e})}async setEffects(e){return s("plugin:window|set_effects",{label:this.label,value:e})}async clearEffects(){return s("plugin:window|set_effects",{label:this.label,value:null})}async setAlwaysOnTop(e){return s("plugin:window|set_always_on_top",{label:this.label,value:e})}async setAlwaysOnBottom(e){return s("plugin:window|set_always_on_bottom",{label:this.label,value:e})}async setContentProtected(e){return s("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");const t={};return t[`${e.type}`]={width:e.width,height:e.height},s("plugin:window|set_size",{label:this.label,value:t})}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");let t=null;return e&&(t={},t[`${e.type}`]={width:e.width,height:e.height}),s("plugin:window|set_min_size",{label:this.label,value:t})}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");let t=null;return e&&(t={},t[`${e.type}`]={width:e.width,height:e.height}),s("plugin:window|set_max_size",{label:this.label,value:t})}async setSizeConstraints(e){function t(e){return e?{Logical:e}:null}return s("plugin:window|set_size_constraints",{label:this.label,value:{minWidth:t(null==e?void 0:e.minWidth),minHeight:t(null==e?void 0:e.minHeight),maxWidth:t(null==e?void 0:e.maxWidth),maxHeight:t(null==e?void 0:e.maxHeight)}})}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");const t={};return t[`${e.type}`]={x:e.x,y:e.y},s("plugin:window|set_position",{label:this.label,value:t})}async setFullscreen(e){return s("plugin:window|set_fullscreen",{label:this.label,value:e})}async setFocus(){return s("plugin:window|set_focus",{label:this.label})}async setIcon(e){return s("plugin:window|set_icon",{label:this.label,value:p(e)})}async setSkipTaskbar(e){return s("plugin:window|set_skip_taskbar",{label:this.label,value:e})}async setCursorGrab(e){return s("plugin:window|set_cursor_grab",{label:this.label,value:e})}async setCursorVisible(e){return s("plugin:window|set_cursor_visible",{label:this.label,value:e})}async setCursorIcon(e){return s("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");const t={};return t[`${e.type}`]={x:e.x,y:e.y},s("plugin:window|set_cursor_position",{label:this.label,value:t})}async setIgnoreCursorEvents(e){return s("plugin:window|set_ignore_cursor_events",{label:this.label,value:e})}async startDragging(){return s("plugin:window|start_dragging",{label:this.label})}async startResizeDragging(e){return s("plugin:window|start_resize_dragging",{label:this.label,value:e})}async setProgressBar(e){return s("plugin:window|set_progress_bar",{label:this.label,value:e})}async setVisibleOnAllWorkspaces(e){return s("plugin:window|set_visible_on_all_workspaces",{label:this.label,value:e})}async setTitleBarStyle(e){return s("plugin:window|set_title_bar_style",{label:this.label,value:e})}async onResized(e){return this.listen(i.WINDOW_RESIZED,(t=>{var i;t.payload=(i=t.payload,new u(i.width,i.height)),e(t)}))}async onMoved(e){return this.listen(i.WINDOW_MOVED,(t=>{t.payload=I(t.payload),e(t)}))}async onCloseRequested(e){return this.listen(i.WINDOW_CLOSE_REQUESTED,(async t=>{const i=new y(t);await e(i),i.isPreventDefault()||await this.destroy()}))}async onDragDropEvent(e){const t=await this.listen(i.DRAG_ENTER,(t=>{e({...t,payload:{type:"enter",paths:t.payload.paths,position:I(t.payload.position)}})})),n=await this.listen(i.DRAG_OVER,(t=>{e({...t,payload:{type:"over",position:I(t.payload.position)}})})),a=await this.listen(i.DRAG_DROP,(t=>{e({...t,payload:{type:"drop",paths:t.payload.paths,position:I(t.payload.position)}})})),l=await this.listen(i.DRAG_LEAVE,(t=>{e({...t,payload:{type:"leave"}})}));return()=>{t(),a(),n(),l()}}async onFocusChanged(e){const t=await this.listen(i.WINDOW_FOCUS,(t=>{e({...t,payload:!0})})),n=await this.listen(i.WINDOW_BLUR,(t=>{e({...t,payload:!1})}));return()=>{t(),n()}}async onScaleChanged(e){return this.listen(i.WINDOW_SCALE_FACTOR_CHANGED,e)}async onThemeChanged(e){return this.listen(i.WINDOW_THEME_CHANGED,e)}}var f,E,D;function I(e){return new d(e.x,e.y)}async function S(e,t){await s("plugin:window-state|restore_state",{label:e,flags:t})}return function(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"}(f||(f={})),function(e){e.FollowsWindowActiveState="followsWindowActiveState",e.Active="active",e.Inactive="inactive"}(E||(E={})),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.filename=async function(){return await s("plugin:window-state|filename")},e.restoreState=S,e.restoreStateCurrent=async function(e){await S(g().label,e)},e.saveWindowState=async function(e){await s("plugin:window-state|save_window_state",{flags:e})},e}({});Object.defineProperty(window.__TAURI__,"windowState",{value:__TAURI_PLUGIN_WINDOW_STATE__})} +if("__TAURI__"in window){var __TAURI_PLUGIN_WINDOW_STATE__=function(e){"use strict";var t,i,n,a;function l(e,t=!1){return window.__TAURI_INTERNALS__.transformCallback(e,t)}async function s(e,t={},i){return window.__TAURI_INTERNALS__.invoke(e,t,i)}"function"==typeof SuppressedError&&SuppressedError;class r{get rid(){return function(e,t,i,n){if("a"===i&&!n)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===i?n:"a"===i?n.call(e):n?n.value:t.get(e)}(this,t,"f")}constructor(e){t.set(this,void 0),function(e,t,i,n,a){if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");t.set(e,i)}(this,t,e)}async close(){return s("plugin:resources|close",{rid:this.rid})}}t=new WeakMap;class o{constructor(e,t){this.type="Logical",this.width=e,this.height=t}toPhysical(e){return new u(this.width*e,this.height*e)}}class u{constructor(e,t){this.type="Physical",this.width=e,this.height=t}toLogical(e){return new o(this.width/e,this.height/e)}}class c{constructor(e,t){this.type="Logical",this.x=e,this.y=t}toPhysical(e){return new d(this.x*e,this.x*e)}}class d{constructor(e,t){this.type="Physical",this.x=e,this.y=t}toLogical(e){return new c(this.x/e,this.y/e)}}async function h(e,t){await s("plugin:event|unlisten",{event:e,eventId:t})}async function w(e,t,i){var n;const a="string"==typeof(null==i?void 0:i.target)?{kind:"AnyLabel",label:i.target}:null!==(n=null==i?void 0:i.target)&&void 0!==n?n:{kind:"Any"};return s("plugin:event|listen",{event:e,target:a,handler:l(t)}).then((t=>async()=>h(e,t)))}!function(e){e.WINDOW_RESIZED="tauri://resize",e.WINDOW_MOVED="tauri://move",e.WINDOW_CLOSE_REQUESTED="tauri://close-requested",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_CREATED="tauri://window-created",e.WEBVIEW_CREATED="tauri://webview-created",e.DRAG_ENTER="tauri://drag-enter",e.DRAG_OVER="tauri://drag-over",e.DRAG_DROP="tauri://drag-drop",e.DRAG_LEAVE="tauri://drag-leave"}(i||(i={}));class b extends r{constructor(e){super(e)}static async new(e,t,i){return s("plugin:image|new",{rgba:y(e),width:t,height:i}).then((e=>new b(e)))}static async fromBytes(e){return s("plugin:image|from_bytes",{bytes:y(e)}).then((e=>new b(e)))}static async fromPath(e){return s("plugin:image|from_path",{path:e}).then((e=>new b(e)))}async rgba(){return s("plugin:image|rgba",{rid:this.rid}).then((e=>new Uint8Array(e)))}async size(){return s("plugin:image|size",{rid:this.rid})}}function y(e){return null==e?null:"string"==typeof e?e:e instanceof b?e.rid:e}!function(e){e[e.Critical=1]="Critical",e[e.Informational=2]="Informational"}(n||(n={}));class p{constructor(e){this._preventDefault=!1,this.event=e.event,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}}function g(){return new v(window.__TAURI_INTERNALS__.metadata.currentWindow.label,{skip:!0})}async function _(){return s("plugin:window|get_all_windows").then((e=>e.map((e=>new v(e,{skip:!0})))))}!function(e){e.None="none",e.Normal="normal",e.Indeterminate="indeterminate",e.Paused="paused",e.Error="error"}(a||(a={}));const m=["tauri://created","tauri://error"];class v{constructor(e,t={}){var i;this.label=e,this.listeners=Object.create(null),(null==t?void 0:t.skip)||s("plugin:window|create",{options:{...t,parent:"string"==typeof t.parent?t.parent:null===(i=t.parent)||void 0===i?void 0:i.label,label:e}}).then((async()=>this.emit("tauri://created"))).catch((async e=>this.emit("tauri://error",e)))}static async getByLabel(e){var t;return null!==(t=(await _()).find((t=>t.label===e)))&&void 0!==t?t:null}static getCurrent(){return g()}static async getAll(){return _()}static async getFocusedWindow(){for(const e of await _())if(await e.isFocused())return e;return null}async listen(e,t){return this._handleTauriEvent(e,t)?()=>{const i=this.listeners[e];i.splice(i.indexOf(t),1)}:w(e,t,{target:{kind:"Window",label:this.label}})}async once(e,t){return this._handleTauriEvent(e,t)?()=>{const i=this.listeners[e];i.splice(i.indexOf(t),1)}:async function(e,t,i){return w(e,(i=>{h(e,i.id),t(i)}),i)}(e,t,{target:{kind:"Window",label:this.label}})}async emit(e,t){if(!m.includes(e))return async function(e,t){await s("plugin:event|emit",{event:e,payload:t})}(e,t);for(const i of this.listeners[e]||[])i({event:e,id:-1,payload:t})}async emitTo(e,t,i){if(!m.includes(t))return async function(e,t,i){const n="string"==typeof e?{kind:"AnyLabel",label:e}:e;await s("plugin:event|emit_to",{target:n,event:t,payload:i})}(e,t,i);for(const e of this.listeners[t]||[])e({event:t,id:-1,payload:i})}_handleTauriEvent(e,t){return!!m.includes(e)&&(e in this.listeners?this.listeners[e].push(t):this.listeners[e]=[t],!0)}async scaleFactor(){return s("plugin:window|scale_factor",{label:this.label})}async innerPosition(){return s("plugin:window|inner_position",{label:this.label}).then((({x:e,y:t})=>new d(e,t)))}async outerPosition(){return s("plugin:window|outer_position",{label:this.label}).then((({x:e,y:t})=>new d(e,t)))}async innerSize(){return s("plugin:window|inner_size",{label:this.label}).then((({width:e,height:t})=>new u(e,t)))}async outerSize(){return s("plugin:window|outer_size",{label:this.label}).then((({width:e,height:t})=>new u(e,t)))}async isFullscreen(){return s("plugin:window|is_fullscreen",{label:this.label})}async isMinimized(){return s("plugin:window|is_minimized",{label:this.label})}async isMaximized(){return s("plugin:window|is_maximized",{label:this.label})}async isFocused(){return s("plugin:window|is_focused",{label:this.label})}async isDecorated(){return s("plugin:window|is_decorated",{label:this.label})}async isResizable(){return s("plugin:window|is_resizable",{label:this.label})}async isMaximizable(){return s("plugin:window|is_maximizable",{label:this.label})}async isMinimizable(){return s("plugin:window|is_minimizable",{label:this.label})}async isClosable(){return s("plugin:window|is_closable",{label:this.label})}async isVisible(){return s("plugin:window|is_visible",{label:this.label})}async title(){return s("plugin:window|title",{label:this.label})}async theme(){return s("plugin:window|theme",{label:this.label})}async center(){return s("plugin:window|center",{label:this.label})}async requestUserAttention(e){let t=null;return e&&(t=e===n.Critical?{type:"Critical"}:{type:"Informational"}),s("plugin:window|request_user_attention",{label:this.label,value:t})}async setResizable(e){return s("plugin:window|set_resizable",{label:this.label,value:e})}async setEnabled(e){return s("plugin:window|set_enabled",{label:this.label,value:e})}async isEnabled(){return s("plugin:window|is_enabled",{label:this.label})}async setMaximizable(e){return s("plugin:window|set_maximizable",{label:this.label,value:e})}async setMinimizable(e){return s("plugin:window|set_minimizable",{label:this.label,value:e})}async setClosable(e){return s("plugin:window|set_closable",{label:this.label,value:e})}async setTitle(e){return s("plugin:window|set_title",{label:this.label,value:e})}async maximize(){return s("plugin:window|maximize",{label:this.label})}async unmaximize(){return s("plugin:window|unmaximize",{label:this.label})}async toggleMaximize(){return s("plugin:window|toggle_maximize",{label:this.label})}async minimize(){return s("plugin:window|minimize",{label:this.label})}async unminimize(){return s("plugin:window|unminimize",{label:this.label})}async show(){return s("plugin:window|show",{label:this.label})}async hide(){return s("plugin:window|hide",{label:this.label})}async close(){return s("plugin:window|close",{label:this.label})}async destroy(){return s("plugin:window|destroy",{label:this.label})}async setDecorations(e){return s("plugin:window|set_decorations",{label:this.label,value:e})}async setShadow(e){return s("plugin:window|set_shadow",{label:this.label,value:e})}async setEffects(e){return s("plugin:window|set_effects",{label:this.label,value:e})}async clearEffects(){return s("plugin:window|set_effects",{label:this.label,value:null})}async setAlwaysOnTop(e){return s("plugin:window|set_always_on_top",{label:this.label,value:e})}async setAlwaysOnBottom(e){return s("plugin:window|set_always_on_bottom",{label:this.label,value:e})}async setContentProtected(e){return s("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");const t={};return t[`${e.type}`]={width:e.width,height:e.height},s("plugin:window|set_size",{label:this.label,value:t})}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");let t=null;return e&&(t={},t[`${e.type}`]={width:e.width,height:e.height}),s("plugin:window|set_min_size",{label:this.label,value:t})}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");let t=null;return e&&(t={},t[`${e.type}`]={width:e.width,height:e.height}),s("plugin:window|set_max_size",{label:this.label,value:t})}async setSizeConstraints(e){function t(e){return e?{Logical:e}:null}return s("plugin:window|set_size_constraints",{label:this.label,value:{minWidth:t(null==e?void 0:e.minWidth),minHeight:t(null==e?void 0:e.minHeight),maxWidth:t(null==e?void 0:e.maxWidth),maxHeight:t(null==e?void 0:e.maxHeight)}})}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");const t={};return t[`${e.type}`]={x:e.x,y:e.y},s("plugin:window|set_position",{label:this.label,value:t})}async setFullscreen(e){return s("plugin:window|set_fullscreen",{label:this.label,value:e})}async setFocus(){return s("plugin:window|set_focus",{label:this.label})}async setIcon(e){return s("plugin:window|set_icon",{label:this.label,value:y(e)})}async setSkipTaskbar(e){return s("plugin:window|set_skip_taskbar",{label:this.label,value:e})}async setCursorGrab(e){return s("plugin:window|set_cursor_grab",{label:this.label,value:e})}async setCursorVisible(e){return s("plugin:window|set_cursor_visible",{label:this.label,value:e})}async setCursorIcon(e){return s("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");const t={};return t[`${e.type}`]={x:e.x,y:e.y},s("plugin:window|set_cursor_position",{label:this.label,value:t})}async setIgnoreCursorEvents(e){return s("plugin:window|set_ignore_cursor_events",{label:this.label,value:e})}async startDragging(){return s("plugin:window|start_dragging",{label:this.label})}async startResizeDragging(e){return s("plugin:window|start_resize_dragging",{label:this.label,value:e})}async setProgressBar(e){return s("plugin:window|set_progress_bar",{label:this.label,value:e})}async setVisibleOnAllWorkspaces(e){return s("plugin:window|set_visible_on_all_workspaces",{label:this.label,value:e})}async setTitleBarStyle(e){return s("plugin:window|set_title_bar_style",{label:this.label,value:e})}async setTheme(e){return s("plugin:window|set_theme",{label:this.label,value:e})}async onResized(e){return this.listen(i.WINDOW_RESIZED,(t=>{var i;t.payload=(i=t.payload,new u(i.width,i.height)),e(t)}))}async onMoved(e){return this.listen(i.WINDOW_MOVED,(t=>{t.payload=I(t.payload),e(t)}))}async onCloseRequested(e){return this.listen(i.WINDOW_CLOSE_REQUESTED,(async t=>{const i=new p(t);await e(i),i.isPreventDefault()||await this.destroy()}))}async onDragDropEvent(e){const t=await this.listen(i.DRAG_ENTER,(t=>{e({...t,payload:{type:"enter",paths:t.payload.paths,position:I(t.payload.position)}})})),n=await this.listen(i.DRAG_OVER,(t=>{e({...t,payload:{type:"over",position:I(t.payload.position)}})})),a=await this.listen(i.DRAG_DROP,(t=>{e({...t,payload:{type:"drop",paths:t.payload.paths,position:I(t.payload.position)}})})),l=await this.listen(i.DRAG_LEAVE,(t=>{e({...t,payload:{type:"leave"}})}));return()=>{t(),a(),n(),l()}}async onFocusChanged(e){const t=await this.listen(i.WINDOW_FOCUS,(t=>{e({...t,payload:!0})})),n=await this.listen(i.WINDOW_BLUR,(t=>{e({...t,payload:!1})}));return()=>{t(),n()}}async onScaleChanged(e){return this.listen(i.WINDOW_SCALE_FACTOR_CHANGED,e)}async onThemeChanged(e){return this.listen(i.WINDOW_THEME_CHANGED,e)}}var f,E,D;function I(e){return new d(e.x,e.y)}async function S(e,t){await s("plugin:window-state|restore_state",{label:e,flags:t})}return function(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"}(f||(f={})),function(e){e.FollowsWindowActiveState="followsWindowActiveState",e.Active="active",e.Inactive="inactive"}(E||(E={})),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.filename=async function(){return await s("plugin:window-state|filename")},e.restoreState=S,e.restoreStateCurrent=async function(e){await S(g().label,e)},e.saveWindowState=async function(e){await s("plugin:window-state|save_window_state",{flags:e})},e}({});Object.defineProperty(window.__TAURI__,"windowState",{value:__TAURI_PLUGIN_WINDOW_STATE__})}