diff --git a/.changes/tauri-image.md b/.changes/tauri-image.md index 48bd95596..0b72a4306 100644 --- a/.changes/tauri-image.md +++ b/.changes/tauri-image.md @@ -1,5 +1,6 @@ --- 'tauri': 'minor:feat' +'@tauri-apps/api': 'minor:feat' --- -Add `Image` type. +Add a new `Image` type in Rust and JS. diff --git a/Cargo.lock b/Cargo.lock index d71912ae9..3ba5b6dd8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3418,12 +3418,6 @@ dependencies = [ "loom", ] -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - [[package]] name = "string_cache" version = "0.8.7" @@ -3630,7 +3624,6 @@ dependencies = [ "serde_repr", "serialize-to-javascript", "state", - "static_assertions", "swift-rs", "tauri", "tauri-build", diff --git a/core/tauri/Cargo.toml b/core/tauri/Cargo.toml index 607bb6254..5f5a7ba8b 100644 --- a/core/tauri/Cargo.toml +++ b/core/tauri/Cargo.toml @@ -72,7 +72,6 @@ png = { version = "0.17", optional = true } ico = { version = "0.3.0", optional = true } http-range = { version = "0.1.5", optional = true } tracing = { version = "0.1", optional = true } -static_assertions = "1" heck = "0.4" [target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\", target_os = \"windows\", target_os = \"macos\"))".dependencies] diff --git a/core/tauri/build.rs b/core/tauri/build.rs index ff8d81b6a..964f68803 100644 --- a/core/tauri/build.rs +++ b/core/tauri/build.rs @@ -137,6 +137,19 @@ const PLUGINS: &[(&str, &[(&str, bool)])] = &[ ("app_hide", false), ], ), + ( + "image", + &[ + ("new", true), + ("from_bytes", true), + ("from_png_bytes", true), + ("from_ico_bytes", true), + ("from_path", true), + ("rgba", true), + ("width", true), + ("height", true), + ], + ), ("resources", &[("close", true)]), ( "menu", diff --git a/core/tauri/permissions/image/autogenerated/reference.md b/core/tauri/permissions/image/autogenerated/reference.md new file mode 100644 index 000000000..c42f15337 --- /dev/null +++ b/core/tauri/permissions/image/autogenerated/reference.md @@ -0,0 +1,19 @@ +| Permission | Description | +|------|-----| +|`allow-from-bytes`|Enables the from_bytes command without any pre-configured scope.| +|`deny-from-bytes`|Denies the from_bytes command without any pre-configured scope.| +|`allow-from-ico-bytes`|Enables the from_ico_bytes command without any pre-configured scope.| +|`deny-from-ico-bytes`|Denies the from_ico_bytes command without any pre-configured scope.| +|`allow-from-path`|Enables the from_path command without any pre-configured scope.| +|`deny-from-path`|Denies the from_path command without any pre-configured scope.| +|`allow-from-png-bytes`|Enables the from_png_bytes command without any pre-configured scope.| +|`deny-from-png-bytes`|Denies the from_png_bytes command without any pre-configured scope.| +|`allow-height`|Enables the height command without any pre-configured scope.| +|`deny-height`|Denies the height command without any pre-configured scope.| +|`allow-new`|Enables the new command without any pre-configured scope.| +|`deny-new`|Denies the new command without any pre-configured scope.| +|`allow-rgba`|Enables the rgba command without any pre-configured scope.| +|`deny-rgba`|Denies the rgba command without any pre-configured scope.| +|`allow-width`|Enables the width command without any pre-configured scope.| +|`deny-width`|Denies the width command without any pre-configured scope.| +|`default`|Default permissions for the plugin.| diff --git a/core/tauri/scripts/bundle.global.js b/core/tauri/scripts/bundle.global.js index 86986601f..e8bb8d338 100644 --- a/core/tauri/scripts/bundle.global.js +++ b/core/tauri/scripts/bundle.global.js @@ -1 +1 @@ -var __TAURI_IIFE__=function(e){"use strict";function t(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)}function n(e,t,n,i,r){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?r.call(e,n):r?r.value=n:t.set(e,n),n}var i,r;function a(e,t=!1){return window.__TAURI_INTERNALS__.transformCallback(e,t)}"function"==typeof SuppressedError&&SuppressedError;class s{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,i.set(this,(()=>{})),this.id=a((e=>{t(this,i,"f").call(this,e)}))}set onmessage(e){n(this,i,e,"f")}get onmessage(){return t(this,i,"f")}toJSON(){return`__CHANNEL__:${this.id}`}}i=new WeakMap;class l{constructor(e,t,n){this.plugin=e,this.event=t,this.channelId=n}async unregister(){return o(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}}async function o(e,t={},n){return window.__TAURI_INTERNALS__.invoke(e,t,n)}class u{get rid(){return t(this,r,"f")}constructor(e){r.set(this,void 0),n(this,r,e,"f")}async close(){return o("plugin:resources|close",{rid:this.rid})}}r=new WeakMap;var c=Object.freeze({__proto__:null,Channel:s,PluginListener:l,Resource:u,addPluginListener:async function(e,t,n){const i=new s;return i.onmessage=n,o(`plugin:${e}|register_listener`,{event:t,handler:i}).then((()=>new l(e,t,i.id)))},convertFileSrc:function(e,t="asset"){return window.__TAURI_INTERNALS__.convertFileSrc(e,t)},invoke:o,transformCallback:a});var d,p=Object.freeze({__proto__:null,getName:async function(){return o("plugin:app|name")},getTauriVersion:async function(){return o("plugin:app|tauri_version")},getVersion:async function(){return o("plugin:app|version")},hide:async function(){return o("plugin:app|app_hide")},show:async function(){return o("plugin:app|app_show")}});async function h(e,t){await o("plugin:event|unlisten",{event:e,eventId:t})}async function y(e,t,n){const i="string"==typeof n?.target?{kind:"AnyLabel",label:n.target}:n?.target??{kind:"Any"};return o("plugin:event|listen",{event:e,target:i,handler:a(t)}).then((t=>async()=>h(e,t)))}async function w(e,t,n){return y(e,(n=>{t(n),h(e,n.id).catch((()=>{}))}),n)}async function g(e,t){await o("plugin:event|emit",{event:e,payload:t})}async function b(e,t,n){const i="string"==typeof e?{kind:"AnyLabel",label:e}:e;await o("plugin:event|emit_to",{target:i,event:t,payload:n})}!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.WEBVIEW_CREATED="tauri://webview-created",e.FILE_DROP="tauri://file-drop",e.FILE_DROP_HOVER="tauri://file-drop-hover",e.FILE_DROP_CANCELLED="tauri://file-drop-cancelled"}(d||(d={}));var _=Object.freeze({__proto__:null,get TauriEvent(){return d},emit:g,emitTo:b,listen:y,once:w});class m{constructor(e,t){this.type="Logical",this.width=e,this.height=t}}class f{constructor(e,t){this.type="Physical",this.width=e,this.height=t}toLogical(e){return new m(this.width/e,this.height/e)}}class v{constructor(e,t){this.type="Logical",this.x=e,this.y=t}}class k{constructor(e,t){this.type="Physical",this.x=e,this.y=t}toLogical(e){return new v(this.x/e,this.y/e)}}var A,E,D=Object.freeze({__proto__:null,LogicalPosition:v,LogicalSize:m,PhysicalPosition:k,PhysicalSize:f});!function(e){e[e.Critical=1]="Critical",e[e.Informational=2]="Informational"}(A||(A={}));class L{constructor(e){this._preventDefault=!1,this.event=e.event,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}}function P(){return new T(window.__TAURI_INTERNALS__.metadata.currentWindow.label,{skip:!0})}function I(){return window.__TAURI_INTERNALS__.metadata.windows.map((e=>new T(e.label,{skip:!0})))}!function(e){e.None="none",e.Normal="normal",e.Indeterminate="indeterminate",e.Paused="paused",e.Error="error"}(E||(E={}));const S=["tauri://created","tauri://error"];class T{constructor(e,t={}){this.label=e,this.listeners=Object.create(null),t?.skip||o("plugin:window|create",{options:{...t,parent:"string"==typeof t.parent?t.parent:t.parent?.label,label:e}}).then((async()=>this.emit("tauri://created"))).catch((async e=>this.emit("tauri://error",e)))}static getByLabel(e){return I().find((t=>t.label===e))??null}static getCurrent(){return P()}static getAll(){return I()}static async getFocusedWindow(){for(const e of I())if(await e.isFocused())return e;return null}async listen(e,t){return this._handleTauriEvent(e,t)?Promise.resolve((()=>{const n=this.listeners[e];n.splice(n.indexOf(t),1)})):y(e,t,{target:{kind:"Window",label:this.label}})}async once(e,t){return this._handleTauriEvent(e,t)?Promise.resolve((()=>{const n=this.listeners[e];n.splice(n.indexOf(t),1)})):w(e,t,{target:{kind:"Window",label:this.label}})}async emit(e,t){if(S.includes(e)){for(const n of this.listeners[e]||[])n({event:e,id:-1,payload:t});return Promise.resolve()}return g(e,t)}async emitTo(e,t,n){if(S.includes(t)){for(const e of this.listeners[t]||[])e({event:t,id:-1,payload:n});return Promise.resolve()}return b(e,t,n)}_handleTauriEvent(e,t){return!!S.includes(e)&&(e in this.listeners?this.listeners[e].push(t):this.listeners[e]=[t],!0)}async scaleFactor(){return o("plugin:window|scale_factor",{label:this.label})}async innerPosition(){return o("plugin:window|inner_position",{label:this.label}).then((({x:e,y:t})=>new k(e,t)))}async outerPosition(){return o("plugin:window|outer_position",{label:this.label}).then((({x:e,y:t})=>new k(e,t)))}async innerSize(){return o("plugin:window|inner_size",{label:this.label}).then((({width:e,height:t})=>new f(e,t)))}async outerSize(){return o("plugin:window|outer_size",{label:this.label}).then((({width:e,height:t})=>new f(e,t)))}async isFullscreen(){return o("plugin:window|is_fullscreen",{label:this.label})}async isMinimized(){return o("plugin:window|is_minimized",{label:this.label})}async isMaximized(){return o("plugin:window|is_maximized",{label:this.label})}async isFocused(){return o("plugin:window|is_focused",{label:this.label})}async isDecorated(){return o("plugin:window|is_decorated",{label:this.label})}async isResizable(){return o("plugin:window|is_resizable",{label:this.label})}async isMaximizable(){return o("plugin:window|is_maximizable",{label:this.label})}async isMinimizable(){return o("plugin:window|is_minimizable",{label:this.label})}async isClosable(){return o("plugin:window|is_closable",{label:this.label})}async isVisible(){return o("plugin:window|is_visible",{label:this.label})}async title(){return o("plugin:window|title",{label:this.label})}async theme(){return o("plugin:window|theme",{label:this.label})}async center(){return o("plugin:window|center",{label:this.label})}async requestUserAttention(e){let t=null;return e&&(t=e===A.Critical?{type:"Critical"}:{type:"Informational"}),o("plugin:window|request_user_attention",{label:this.label,value:t})}async setResizable(e){return o("plugin:window|set_resizable",{label:this.label,value:e})}async setMaximizable(e){return o("plugin:window|set_maximizable",{label:this.label,value:e})}async setMinimizable(e){return o("plugin:window|set_minimizable",{label:this.label,value:e})}async setClosable(e){return o("plugin:window|set_closable",{label:this.label,value:e})}async setTitle(e){return o("plugin:window|set_title",{label:this.label,value:e})}async maximize(){return o("plugin:window|maximize",{label:this.label})}async unmaximize(){return o("plugin:window|unmaximize",{label:this.label})}async toggleMaximize(){return o("plugin:window|toggle_maximize",{label:this.label})}async minimize(){return o("plugin:window|minimize",{label:this.label})}async unminimize(){return o("plugin:window|unminimize",{label:this.label})}async show(){return o("plugin:window|show",{label:this.label})}async hide(){return o("plugin:window|hide",{label:this.label})}async close(){return o("plugin:window|close",{label:this.label})}async destroy(){return o("plugin:window|destroy",{label:this.label})}async setDecorations(e){return o("plugin:window|set_decorations",{label:this.label,value:e})}async setShadow(e){return o("plugin:window|set_shadow",{label:this.label,value:e})}async setEffects(e){return o("plugin:window|set_effects",{label:this.label,value:e})}async clearEffects(){return o("plugin:window|set_effects",{label:this.label,value:null})}async setAlwaysOnTop(e){return o("plugin:window|set_always_on_top",{label:this.label,value:e})}async setAlwaysOnBottom(e){return o("plugin:window|set_always_on_bottom",{label:this.label,value:e})}async setContentProtected(e){return o("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 o("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 o("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 o("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 o("plugin:window|set_position",{label:this.label,value:{type:e.type,data:{x:e.x,y:e.y}}})}async setFullscreen(e){return o("plugin:window|set_fullscreen",{label:this.label,value:e})}async setFocus(){return o("plugin:window|set_focus",{label:this.label})}async setIcon(e){return o("plugin:window|set_icon",{label:this.label,value:"string"==typeof e?e:Array.from(e)})}async setSkipTaskbar(e){return o("plugin:window|set_skip_taskbar",{label:this.label,value:e})}async setCursorGrab(e){return o("plugin:window|set_cursor_grab",{label:this.label,value:e})}async setCursorVisible(e){return o("plugin:window|set_cursor_visible",{label:this.label,value:e})}async setCursorIcon(e){return o("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 o("plugin:window|set_cursor_position",{label:this.label,value:{type:e.type,data:{x:e.x,y:e.y}}})}async setIgnoreCursorEvents(e){return o("plugin:window|set_ignore_cursor_events",{label:this.label,value:e})}async startDragging(){return o("plugin:window|start_dragging",{label:this.label})}async startResizeDragging(e){return o("plugin:window|start_resize_dragging",{label:this.label,value:e})}async setProgressBar(e){return o("plugin:window|set_progress_bar",{label:this.label,value:e})}async setVisibleOnAllWorkspaces(e){return o("plugin:window|set_visible_on_all_workspaces",{label:this.label,value:e})}async onResized(e){return this.listen(d.WINDOW_RESIZED,(t=>{t.payload=F(t.payload),e(t)}))}async onMoved(e){return this.listen(d.WINDOW_MOVED,(t=>{t.payload=z(t.payload),e(t)}))}async onCloseRequested(e){return this.listen(d.WINDOW_CLOSE_REQUESTED,(t=>{const n=new L(t);Promise.resolve(e(n)).then((()=>{if(!n.isPreventDefault())return this.destroy()}))}))}async onFileDropEvent(e){const t=await this.listen(d.FILE_DROP,(t=>{e({...t,payload:{type:"drop",paths:t.payload.paths,position:z(t.payload.position)}})})),n=await this.listen(d.FILE_DROP_HOVER,(t=>{e({...t,payload:{type:"hover",paths:t.payload.paths,position:z(t.payload.position)}})})),i=await this.listen(d.FILE_DROP_CANCELLED,(t=>{e({...t,payload:{type:"cancel"}})}));return()=>{t(),n(),i()}}async onFocusChanged(e){const t=await this.listen(d.WINDOW_FOCUS,(t=>{e({...t,payload:!0})})),n=await this.listen(d.WINDOW_BLUR,(t=>{e({...t,payload:!1})}));return()=>{t(),n()}}async onScaleChanged(e){return this.listen(d.WINDOW_SCALE_FACTOR_CHANGED,e)}async onThemeChanged(e){return this.listen(d.WINDOW_THEME_CHANGED,e)}}var C,x;function R(e){return null===e?null:{name:e.name,scaleFactor:e.scaleFactor,position:z(e.position),size:F(e.size)}}function z(e){return new k(e.x,e.y)}function F(e){return new f(e.width,e.height)}!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"}(C||(C={})),function(e){e.FollowsWindowActiveState="followsWindowActiveState",e.Active="active",e.Inactive="inactive"}(x||(x={}));var O=Object.freeze({__proto__:null,CloseRequestedEvent:L,get Effect(){return C},get EffectState(){return x},LogicalPosition:v,LogicalSize:m,PhysicalPosition:k,PhysicalSize:f,get ProgressBarStatus(){return E},get UserAttentionType(){return A},Window:T,availableMonitors:async function(){return o("plugin:window|available_monitors").then((e=>e.map(R)))},currentMonitor:async function(){return o("plugin:window|current_monitor").then(R)},getAll:I,getCurrent:P,primaryMonitor:async function(){return o("plugin:window|primary_monitor").then(R)}});function W(){return new U(P(),window.__TAURI_INTERNALS__.metadata.currentWebview.label,{skip:!0})}function N(){return window.__TAURI_INTERNALS__.metadata.webviews.map((e=>new U(T.getByLabel(e.windowLabel),e.label,{skip:!0})))}const M=["tauri://created","tauri://error"];class U{constructor(e,t,n){this.window=e,this.label=t,this.listeners=Object.create(null),n?.skip||o("plugin:webview|create_webview",{windowLabel:e.label,label:t,options:n}).then((async()=>this.emit("tauri://created"))).catch((async e=>this.emit("tauri://error",e)))}static getByLabel(e){return N().find((t=>t.label===e))??null}static getCurrent(){return W()}static getAll(){return N()}async listen(e,t){return this._handleTauriEvent(e,t)?Promise.resolve((()=>{const n=this.listeners[e];n.splice(n.indexOf(t),1)})):y(e,t,{target:{kind:"Webview",label:this.label}})}async once(e,t){return this._handleTauriEvent(e,t)?Promise.resolve((()=>{const n=this.listeners[e];n.splice(n.indexOf(t),1)})):w(e,t,{target:{kind:"Webview",label:this.label}})}async emit(e,t){if(M.includes(e)){for(const n of this.listeners[e]||[])n({event:e,id:-1,payload:t});return Promise.resolve()}return g(e,t)}async emitTo(e,t,n){if(M.includes(t)){for(const e of this.listeners[t]||[])e({event:t,id:-1,payload:n});return Promise.resolve()}return b(e,t,n)}_handleTauriEvent(e,t){return!!M.includes(e)&&(e in this.listeners?this.listeners[e].push(t):this.listeners[e]=[t],!0)}async position(){return o("plugin:webview|webview_position",{label:this.label}).then((({x:e,y:t})=>new k(e,t)))}async size(){return o("plugin:webview|webview_size",{label:this.label}).then((({width:e,height:t})=>new f(e,t)))}async close(){return o("plugin:webview|close",{label:this.label})}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 o("plugin:webview|set_webview_size",{label:this.label,value:{type:e.type,data:{width:e.width,height:e.height}}})}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 o("plugin:webview|set_webview_position",{label:this.label,value:{type:e.type,data:{x:e.x,y:e.y}}})}async setFocus(){return o("plugin:webview|set_webview_focus",{label:this.label})}async reparent(e){return o("plugin:webview|set_webview_focus",{label:this.label,window:"string"==typeof e?e:e.label})}async onFileDropEvent(e){const t=await this.listen(d.FILE_DROP,(t=>{e({...t,payload:{type:"drop",paths:t.payload.paths,position:B(t.payload.position)}})})),n=await this.listen(d.FILE_DROP_HOVER,(t=>{e({...t,payload:{type:"hover",paths:t.payload.paths,position:B(t.payload.position)}})})),i=await this.listen(d.FILE_DROP_CANCELLED,(t=>{e({...t,payload:{type:"cancel"}})}));return()=>{t(),n(),i()}}}function B(e){return new k(e.x,e.y)}var V,j,H=Object.freeze({__proto__:null,Webview:U,getAll:N,getCurrent:W});function G(){const e=W();return new Q(e.label,{skip:!0})}function q(){return window.__TAURI_INTERNALS__.metadata.webviews.map((e=>new Q(e.label,{skip:!0})))}class Q{constructor(e,t={}){this.label=e,this.listeners=Object.create(null),t?.skip||o("plugin:webview|create_webview_window",{options:{...t,parent:"string"==typeof t.parent?t.parent:t.parent?.label,label:e}}).then((async()=>this.emit("tauri://created"))).catch((async e=>this.emit("tauri://error",e)))}static getByLabel(e){const t=q().find((t=>t.label===e))??null;return t?new Q(t.label,{skip:!0}):null}static getCurrent(){return G()}static getAll(){return q().map((e=>new Q(e.label,{skip:!0})))}async listen(e,t){return this._handleTauriEvent(e,t)?Promise.resolve((()=>{const n=this.listeners[e];n.splice(n.indexOf(t),1)})):y(e,t,{target:{kind:"WebviewWindow",label:this.label}})}async once(e,t){return this._handleTauriEvent(e,t)?Promise.resolve((()=>{const n=this.listeners[e];n.splice(n.indexOf(t),1)})):w(e,t,{target:{kind:"WebviewWindow",label:this.label}})}}V=Q,j=[T,U],(Array.isArray(j)?j:[j]).forEach((e=>{Object.getOwnPropertyNames(e.prototype).forEach((t=>{"object"==typeof V.prototype&&V.prototype&&t in V.prototype||Object.defineProperty(V.prototype,t,Object.getOwnPropertyDescriptor(e.prototype,t)??Object.create(null))}))}));var $,Z=Object.freeze({__proto__:null,WebviewWindow:Q,getAll:q,getCurrent:G});!function(e){e[e.Audio=1]="Audio",e[e.Cache=2]="Cache",e[e.Config=3]="Config",e[e.Data=4]="Data",e[e.LocalData=5]="LocalData",e[e.Document=6]="Document",e[e.Download=7]="Download",e[e.Picture=8]="Picture",e[e.Public=9]="Public",e[e.Video=10]="Video",e[e.Resource=11]="Resource",e[e.Temp=12]="Temp",e[e.AppConfig=13]="AppConfig",e[e.AppData=14]="AppData",e[e.AppLocalData=15]="AppLocalData",e[e.AppCache=16]="AppCache",e[e.AppLog=17]="AppLog",e[e.Desktop=18]="Desktop",e[e.Executable=19]="Executable",e[e.Font=20]="Font",e[e.Home=21]="Home",e[e.Runtime=22]="Runtime",e[e.Template=23]="Template"}($||($={}));var J=Object.freeze({__proto__:null,get BaseDirectory(){return $},appCacheDir:async function(){return o("plugin:path|resolve_directory",{directory:$.AppCache})},appConfigDir:async function(){return o("plugin:path|resolve_directory",{directory:$.AppConfig})},appDataDir:async function(){return o("plugin:path|resolve_directory",{directory:$.AppData})},appLocalDataDir:async function(){return o("plugin:path|resolve_directory",{directory:$.AppLocalData})},appLogDir:async function(){return o("plugin:path|resolve_directory",{directory:$.AppLog})},audioDir:async function(){return o("plugin:path|resolve_directory",{directory:$.Audio})},basename:async function(e,t){return o("plugin:path|basename",{path:e,ext:t})},cacheDir:async function(){return o("plugin:path|resolve_directory",{directory:$.Cache})},configDir:async function(){return o("plugin:path|resolve_directory",{directory:$.Config})},dataDir:async function(){return o("plugin:path|resolve_directory",{directory:$.Data})},delimiter:function(){return window.__TAURI_INTERNALS__.plugins.path.delimiter},desktopDir:async function(){return o("plugin:path|resolve_directory",{directory:$.Desktop})},dirname:async function(e){return o("plugin:path|dirname",{path:e})},documentDir:async function(){return o("plugin:path|resolve_directory",{directory:$.Document})},downloadDir:async function(){return o("plugin:path|resolve_directory",{directory:$.Download})},executableDir:async function(){return o("plugin:path|resolve_directory",{directory:$.Executable})},extname:async function(e){return o("plugin:path|extname",{path:e})},fontDir:async function(){return o("plugin:path|resolve_directory",{directory:$.Font})},homeDir:async function(){return o("plugin:path|resolve_directory",{directory:$.Home})},isAbsolute:async function(e){return o("plugin:path|isAbsolute",{path:e})},join:async function(...e){return o("plugin:path|join",{paths:e})},localDataDir:async function(){return o("plugin:path|resolve_directory",{directory:$.LocalData})},normalize:async function(e){return o("plugin:path|normalize",{path:e})},pictureDir:async function(){return o("plugin:path|resolve_directory",{directory:$.Picture})},publicDir:async function(){return o("plugin:path|resolve_directory",{directory:$.Public})},resolve:async function(...e){return o("plugin:path|resolve",{paths:e})},resolveResource:async function(e){return o("plugin:path|resolve_directory",{directory:$.Resource,path:e})},resourceDir:async function(){return o("plugin:path|resolve_directory",{directory:$.Resource})},runtimeDir:async function(){return o("plugin:path|resolve_directory",{directory:$.Runtime})},sep:function(){return window.__TAURI_INTERNALS__.plugins.path.sep},tempDir:async function(){return o("plugin:path|resolve_directory",{directory:$.Temp})},templateDir:async function(){return o("plugin:path|resolve_directory",{directory:$.Template})},videoDir:async function(){return o("plugin:path|resolve_directory",{directory:$.Video})}});class K extends u{constructor(e,t){super(e),this.id=t}static async new(e){e?.menu&&(e.menu=[e.menu.rid,e.menu.kind]),e?.icon&&(e.icon="string"==typeof e.icon?e.icon:Array.from(e.icon));const t=new s;return e?.action&&(t.onmessage=e.action,delete e.action),o("plugin:tray|new",{options:e??{},handler:t}).then((([e,t])=>new K(e,t)))}async setIcon(e){let t=null;return e&&(t="string"==typeof e?e:Array.from(e)),o("plugin:tray|set_icon",{rid:this.rid,icon:t})}async setMenu(e){return e&&(e=[e.rid,e.kind]),o("plugin:tray|set_menu",{rid:this.rid,menu:e})}async setTooltip(e){return o("plugin:tray|set_tooltip",{rid:this.rid,tooltip:e})}async setTitle(e){return o("plugin:tray|set_title",{rid:this.rid,title:e})}async setVisible(e){return o("plugin:tray|set_visible",{rid:this.rid,visible:e})}async setTempDirPath(e){return o("plugin:tray|set_temp_dir_path",{rid:this.rid,path:e})}async setIconAsTemplate(e){return o("plugin:tray|set_icon_as_template",{rid:this.rid,asTemplate:e})}async setMenuOnLeftClick(e){return o("plugin:tray|set_show_menu_on_left_click",{rid:this.rid,onLeft:e})}}var Y,X,ee,te=Object.freeze({__proto__:null,TrayIcon:K});function ne(e){if("items"in e)e.items=e.items?.map((e=>"rid"in e?e:ne(e)));else if("action"in e&&e.action){const t=new s;return t.onmessage=e.action,delete e.action,{...e,handler:t}}return e}async function ie(e,t){const n=new s;let i=null;return t&&"object"==typeof t&&("action"in t&&t.action&&(n.onmessage=t.action,delete t.action),"items"in t&&t.items&&(i=t.items.map((e=>"rid"in e?[e.rid,e.kind]:ne(e))))),o("plugin:menu|new",{kind:e,options:t?{...t,items:i}:void 0,handler:n})}class re extends u{get id(){return t(this,Y,"f")}get kind(){return t(this,X,"f")}constructor(e,t,i){super(e),Y.set(this,void 0),X.set(this,void 0),n(this,Y,t,"f"),n(this,X,i,"f")}}Y=new WeakMap,X=new WeakMap;class ae extends re{constructor(e,t){super(e,t,"MenuItem")}static async new(e){return ie("MenuItem",e).then((([e,t])=>new ae(e,t)))}async text(){return o("plugin:menu|text",{rid:this.rid,kind:this.kind})}async setText(e){return o("plugin:menu|set_text",{rid:this.rid,kind:this.kind,text:e})}async isEnabled(){return o("plugin:menu|is_enabled",{rid:this.rid,kind:this.kind})}async setEnabled(e){return o("plugin:menu|set_enabled",{rid:this.rid,kind:this.kind,enabled:e})}async setAccelerator(e){return o("plugin:menu|set_accelerator",{rid:this.rid,kind:this.kind,accelerator:e})}}class se extends re{constructor(e,t){super(e,t,"Check")}static async new(e){return ie("Check",e).then((([e,t])=>new se(e,t)))}async text(){return o("plugin:menu|text",{rid:this.rid,kind:this.kind})}async setText(e){return o("plugin:menu|set_text",{rid:this.rid,kind:this.kind,text:e})}async isEnabled(){return o("plugin:menu|is_enabled",{rid:this.rid,kind:this.kind})}async setEnabled(e){return o("plugin:menu|set_enabled",{rid:this.rid,kind:this.kind,enabled:e})}async setAccelerator(e){return o("plugin:menu|set_accelerator",{rid:this.rid,kind:this.kind,accelerator:e})}async isChecked(){return o("plugin:menu|is_checked",{rid:this.rid})}async setChecked(e){return o("plugin:menu|set_checked",{rid:this.rid,checked:e})}}!function(e){e.Add="Add",e.Advanced="Advanced",e.Bluetooth="Bluetooth",e.Bookmarks="Bookmarks",e.Caution="Caution",e.ColorPanel="ColorPanel",e.ColumnView="ColumnView",e.Computer="Computer",e.EnterFullScreen="EnterFullScreen",e.Everyone="Everyone",e.ExitFullScreen="ExitFullScreen",e.FlowView="FlowView",e.Folder="Folder",e.FolderBurnable="FolderBurnable",e.FolderSmart="FolderSmart",e.FollowLinkFreestanding="FollowLinkFreestanding",e.FontPanel="FontPanel",e.GoLeft="GoLeft",e.GoRight="GoRight",e.Home="Home",e.IChatTheater="IChatTheater",e.IconView="IconView",e.Info="Info",e.InvalidDataFreestanding="InvalidDataFreestanding",e.LeftFacingTriangle="LeftFacingTriangle",e.ListView="ListView",e.LockLocked="LockLocked",e.LockUnlocked="LockUnlocked",e.MenuMixedState="MenuMixedState",e.MenuOnState="MenuOnState",e.MobileMe="MobileMe",e.MultipleDocuments="MultipleDocuments",e.Network="Network",e.Path="Path",e.PreferencesGeneral="PreferencesGeneral",e.QuickLook="QuickLook",e.RefreshFreestanding="RefreshFreestanding",e.Refresh="Refresh",e.Remove="Remove",e.RevealFreestanding="RevealFreestanding",e.RightFacingTriangle="RightFacingTriangle",e.Share="Share",e.Slideshow="Slideshow",e.SmartBadge="SmartBadge",e.StatusAvailable="StatusAvailable",e.StatusNone="StatusNone",e.StatusPartiallyAvailable="StatusPartiallyAvailable",e.StatusUnavailable="StatusUnavailable",e.StopProgressFreestanding="StopProgressFreestanding",e.StopProgress="StopProgress",e.TrashEmpty="TrashEmpty",e.TrashFull="TrashFull",e.User="User",e.UserAccounts="UserAccounts",e.UserGroup="UserGroup",e.UserGuest="UserGuest"}(ee||(ee={}));class le extends re{constructor(e,t){super(e,t,"Icon")}static async new(e){return ie("Icon",e).then((([e,t])=>new le(e,t)))}async text(){return o("plugin:menu|text",{rid:this.rid,kind:this.kind})}async setText(e){return o("plugin:menu|set_text",{rid:this.rid,kind:this.kind,text:e})}async isEnabled(){return o("plugin:menu|is_enabled",{rid:this.rid,kind:this.kind})}async setEnabled(e){return o("plugin:menu|set_enabled",{rid:this.rid,kind:this.kind,enabled:e})}async setAccelerator(e){return o("plugin:menu|set_accelerator",{rid:this.rid,kind:this.kind,accelerator:e})}async setIcon(e){return o("plugin:menu|set_icon",{rid:this.rid,icon:e})}}class oe extends re{constructor(e,t){super(e,t,"Predefined")}static async new(e){return ie("Predefined",e).then((([e,t])=>new oe(e,t)))}async text(){return o("plugin:menu|text",{rid:this.rid,kind:this.kind})}async setText(e){return o("plugin:menu|set_text",{rid:this.rid,kind:this.kind,text:e})}}function ue([e,t,n]){switch(n){case"Submenu":return new ce(e,t);case"Predefined":return new oe(e,t);case"Check":return new se(e,t);case"Icon":return new le(e,t);default:return new ae(e,t)}}class ce extends re{constructor(e,t){super(e,t,"Submenu")}static async new(e){return ie("Submenu",e).then((([e,t])=>new ce(e,t)))}async text(){return o("plugin:menu|text",{rid:this.rid,kind:this.kind})}async setText(e){return o("plugin:menu|set_text",{rid:this.rid,kind:this.kind,text:e})}async isEnabled(){return o("plugin:menu|is_enabled",{rid:this.rid,kind:this.kind})}async setEnabled(e){return o("plugin:menu|set_enabled",{rid:this.rid,kind:this.kind,enabled:e})}async append(e){return o("plugin:menu|append",{rid:this.rid,kind:this.kind,items:(Array.isArray(e)?e:[e]).map((e=>"rid"in e?[e.rid,e.kind]:e))})}async prepend(e){return o("plugin:menu|prepend",{rid:this.rid,kind:this.kind,items:(Array.isArray(e)?e:[e]).map((e=>"rid"in e?[e.rid,e.kind]:e))})}async insert(e,t){return o("plugin:menu|insert",{rid:this.rid,kind:this.kind,items:(Array.isArray(e)?e:[e]).map((e=>"rid"in e?[e.rid,e.kind]:e)),position:t})}async remove(e){return o("plugin:menu|remove",{rid:this.rid,kind:this.kind,item:[e.rid,e.kind]})}async removeAt(e){return o("plugin:menu|remove_at",{rid:this.rid,kind:this.kind,position:e}).then(ue)}async items(){return o("plugin:menu|items",{rid:this.rid,kind:this.kind}).then((e=>e.map(ue)))}async get(e){return o("plugin:menu|get",{rid:this.rid,kind:this.kind,id:e}).then((e=>e?ue(e):null))}async popup(e,t){let n=null;return e&&(n={type:e instanceof k?"Physical":"Logical",data:e}),o("plugin:menu|popup",{rid:this.rid,kind:this.kind,window:t?.label??null,at:n})}async setAsWindowsMenuForNSApp(){return o("plugin:menu|set_as_windows_menu_for_nsapp",{rid:this.rid})}async setAsHelpMenuForNSApp(){return o("plugin:menu|set_as_help_menu_for_nsapp",{rid:this.rid})}}function de([e,t,n]){switch(n){case"Submenu":return new ce(e,t);case"Predefined":return new oe(e,t);case"Check":return new se(e,t);case"Icon":return new le(e,t);default:return new ae(e,t)}}class pe extends re{constructor(e,t){super(e,t,"Menu")}static async new(e){return ie("Menu",e).then((([e,t])=>new pe(e,t)))}static async default(){return o("plugin:menu|create_default").then((([e,t])=>new pe(e,t)))}async append(e){return o("plugin:menu|append",{rid:this.rid,kind:this.kind,items:(Array.isArray(e)?e:[e]).map((e=>"rid"in e?[e.rid,e.kind]:e))})}async prepend(e){return o("plugin:menu|prepend",{rid:this.rid,kind:this.kind,items:(Array.isArray(e)?e:[e]).map((e=>"rid"in e?[e.rid,e.kind]:e))})}async insert(e,t){return o("plugin:menu|insert",{rid:this.rid,kind:this.kind,items:(Array.isArray(e)?e:[e]).map((e=>"rid"in e?[e.rid,e.kind]:e)),position:t})}async remove(e){return o("plugin:menu|remove",{rid:this.rid,kind:this.kind,item:[e.rid,e.kind]})}async removeAt(e){return o("plugin:menu|remove_at",{rid:this.rid,kind:this.kind,position:e}).then(de)}async items(){return o("plugin:menu|items",{rid:this.rid,kind:this.kind}).then((e=>e.map(de)))}async get(e){return o("plugin:menu|get",{rid:this.rid,kind:this.kind,id:e}).then((e=>e?de(e):null))}async popup(e,t){let n=null;return e&&(n={type:e instanceof k?"Physical":"Logical",data:e}),o("plugin:menu|popup",{rid:this.rid,kind:this.kind,window:t?.label??null,at:n})}async setAsAppMenu(){return o("plugin:menu|set_as_app_menu",{rid:this.rid}).then((e=>e?new pe(e[0],e[1]):null))}async setAsWindowMenu(e){return o("plugin:menu|set_as_window_menu",{rid:this.rid,window:e?.label??null}).then((e=>e?new pe(e[0],e[1]):null))}}var he=Object.freeze({__proto__:null,CheckMenuItem:se,IconMenuItem:le,Menu:pe,MenuItem:ae,get NativeIcon(){return ee},PredefinedMenuItem:oe,Submenu:ce});return e.app=p,e.core=c,e.dpi=D,e.event=_,e.menu=he,e.path=J,e.tray=te,e.webview=H,e.webviewWindow=Z,e.window=O,e}({});window.__TAURI__=__TAURI_IIFE__; +var __TAURI_IIFE__=function(e){"use strict";function t(e,t,n,i){if("a"===n&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!i:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===n?i:"a"===n?i.call(e):i?i.value:t.get(e)}function n(e,t,n,i,r){if("m"===i)throw new TypeError("Private method is not writable");if("a"===i&&!r)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!r:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===i?r.call(e,n):r?r.value=n:t.set(e,n),n}var i,r;function a(e,t=!1){return window.__TAURI_INTERNALS__.transformCallback(e,t)}"function"==typeof SuppressedError&&SuppressedError;class s{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,i.set(this,(()=>{})),this.id=a((e=>{t(this,i,"f").call(this,e)}))}set onmessage(e){n(this,i,e,"f")}get onmessage(){return t(this,i,"f")}toJSON(){return`__CHANNEL__:${this.id}`}}i=new WeakMap;class l{constructor(e,t,n){this.plugin=e,this.event=t,this.channelId=n}async unregister(){return o(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}}async function o(e,t={},n){return window.__TAURI_INTERNALS__.invoke(e,t,n)}class u{get rid(){return t(this,r,"f")}constructor(e){r.set(this,void 0),n(this,r,e,"f")}async close(){return o("plugin:resources|close",{rid:this.rid})}}r=new WeakMap;var c=Object.freeze({__proto__:null,Channel:s,PluginListener:l,Resource:u,addPluginListener:async function(e,t,n){const i=new s;return i.onmessage=n,o(`plugin:${e}|register_listener`,{event:t,handler:i}).then((()=>new l(e,t,i.id)))},convertFileSrc:function(e,t="asset"){return window.__TAURI_INTERNALS__.convertFileSrc(e,t)},invoke:o,transformCallback:a});var d,p=Object.freeze({__proto__:null,getName:async function(){return o("plugin:app|name")},getTauriVersion:async function(){return o("plugin:app|tauri_version")},getVersion:async function(){return o("plugin:app|version")},hide:async function(){return o("plugin:app|app_hide")},show:async function(){return o("plugin:app|app_show")}});async function h(e,t){await o("plugin:event|unlisten",{event:e,eventId:t})}async function y(e,t,n){const i="string"==typeof n?.target?{kind:"AnyLabel",label:n.target}:n?.target??{kind:"Any"};return o("plugin:event|listen",{event:e,target:i,handler:a(t)}).then((t=>async()=>h(e,t)))}async function w(e,t,n){return y(e,(n=>{t(n),h(e,n.id).catch((()=>{}))}),n)}async function g(e,t){await o("plugin:event|emit",{event:e,payload:t})}async function b(e,t,n){const i="string"==typeof e?{kind:"AnyLabel",label:e}:e;await o("plugin:event|emit_to",{target:i,event:t,payload:n})}!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.WEBVIEW_CREATED="tauri://webview-created",e.FILE_DROP="tauri://file-drop",e.FILE_DROP_HOVER="tauri://file-drop-hover",e.FILE_DROP_CANCELLED="tauri://file-drop-cancelled"}(d||(d={}));var _=Object.freeze({__proto__:null,get TauriEvent(){return d},emit:g,emitTo:b,listen:y,once:w});class m{constructor(e,t){this.type="Logical",this.width=e,this.height=t}}class f{constructor(e,t){this.type="Physical",this.width=e,this.height=t}toLogical(e){return new m(this.width/e,this.height/e)}}class v{constructor(e,t){this.type="Logical",this.x=e,this.y=t}}class k{constructor(e,t){this.type="Physical",this.x=e,this.y=t}toLogical(e){return new v(this.x/e,this.y/e)}}var A=Object.freeze({__proto__:null,LogicalPosition:v,LogicalSize:m,PhysicalPosition:k,PhysicalSize:f});class E extends u{constructor(e){super(e)}static async new(e,t,n){return o("plugin:image|new",{rgba:D(e),width:t,height:n}).then((e=>new E(e)))}static async fromBytes(e){return o("plugin:image|from_bytes",{bytes:D(e)}).then((e=>new E(e)))}static async fromPngBytes(e){return o("plugin:image|from_png_bytes",{bytes:D(e)}).then((e=>new E(e)))}static async fromIcoBytes(e){return o("plugin:image|from_ico_bytes",{bytes:D(e)}).then((e=>new E(e)))}static async fromPath(e){return o("plugin:image|from_path",{path:e}).then((e=>new E(e)))}async rgba(){return o("plugin:image|rgba",{rid:this.rid})}async width(){return o("plugin:image|width",{rid:this.rid})}async height(){return o("plugin:image|height",{rid:this.rid})}}function D(e){return null==e?null:"string"==typeof e?e:e instanceof Uint8Array?Array.from(e):e instanceof ArrayBuffer?Array.from(new Uint8Array(e)):e instanceof E?e.rid:e}var P,L,I=Object.freeze({__proto__:null,Image:E,transformImage:D});!function(e){e[e.Critical=1]="Critical",e[e.Informational=2]="Informational"}(P||(P={}));class S{constructor(e){this._preventDefault=!1,this.event=e.event,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}}function T(){return new z(window.__TAURI_INTERNALS__.metadata.currentWindow.label,{skip:!0})}function C(){return window.__TAURI_INTERNALS__.metadata.windows.map((e=>new z(e.label,{skip:!0})))}!function(e){e.None="none",e.Normal="normal",e.Indeterminate="indeterminate",e.Paused="paused",e.Error="error"}(L||(L={}));const x=["tauri://created","tauri://error"];class z{constructor(e,t={}){this.label=e,this.listeners=Object.create(null),t?.skip||o("plugin:window|create",{options:{...t,parent:"string"==typeof t.parent?t.parent:t.parent?.label,label:e}}).then((async()=>this.emit("tauri://created"))).catch((async e=>this.emit("tauri://error",e)))}static getByLabel(e){return C().find((t=>t.label===e))??null}static getCurrent(){return T()}static getAll(){return C()}static async getFocusedWindow(){for(const e of C())if(await e.isFocused())return e;return null}async listen(e,t){return this._handleTauriEvent(e,t)?Promise.resolve((()=>{const n=this.listeners[e];n.splice(n.indexOf(t),1)})):y(e,t,{target:{kind:"Window",label:this.label}})}async once(e,t){return this._handleTauriEvent(e,t)?Promise.resolve((()=>{const n=this.listeners[e];n.splice(n.indexOf(t),1)})):w(e,t,{target:{kind:"Window",label:this.label}})}async emit(e,t){if(x.includes(e)){for(const n of this.listeners[e]||[])n({event:e,id:-1,payload:t});return Promise.resolve()}return g(e,t)}async emitTo(e,t,n){if(x.includes(t)){for(const e of this.listeners[t]||[])e({event:t,id:-1,payload:n});return Promise.resolve()}return b(e,t,n)}_handleTauriEvent(e,t){return!!x.includes(e)&&(e in this.listeners?this.listeners[e].push(t):this.listeners[e]=[t],!0)}async scaleFactor(){return o("plugin:window|scale_factor",{label:this.label})}async innerPosition(){return o("plugin:window|inner_position",{label:this.label}).then((({x:e,y:t})=>new k(e,t)))}async outerPosition(){return o("plugin:window|outer_position",{label:this.label}).then((({x:e,y:t})=>new k(e,t)))}async innerSize(){return o("plugin:window|inner_size",{label:this.label}).then((({width:e,height:t})=>new f(e,t)))}async outerSize(){return o("plugin:window|outer_size",{label:this.label}).then((({width:e,height:t})=>new f(e,t)))}async isFullscreen(){return o("plugin:window|is_fullscreen",{label:this.label})}async isMinimized(){return o("plugin:window|is_minimized",{label:this.label})}async isMaximized(){return o("plugin:window|is_maximized",{label:this.label})}async isFocused(){return o("plugin:window|is_focused",{label:this.label})}async isDecorated(){return o("plugin:window|is_decorated",{label:this.label})}async isResizable(){return o("plugin:window|is_resizable",{label:this.label})}async isMaximizable(){return o("plugin:window|is_maximizable",{label:this.label})}async isMinimizable(){return o("plugin:window|is_minimizable",{label:this.label})}async isClosable(){return o("plugin:window|is_closable",{label:this.label})}async isVisible(){return o("plugin:window|is_visible",{label:this.label})}async title(){return o("plugin:window|title",{label:this.label})}async theme(){return o("plugin:window|theme",{label:this.label})}async center(){return o("plugin:window|center",{label:this.label})}async requestUserAttention(e){let t=null;return e&&(t=e===P.Critical?{type:"Critical"}:{type:"Informational"}),o("plugin:window|request_user_attention",{label:this.label,value:t})}async setResizable(e){return o("plugin:window|set_resizable",{label:this.label,value:e})}async setMaximizable(e){return o("plugin:window|set_maximizable",{label:this.label,value:e})}async setMinimizable(e){return o("plugin:window|set_minimizable",{label:this.label,value:e})}async setClosable(e){return o("plugin:window|set_closable",{label:this.label,value:e})}async setTitle(e){return o("plugin:window|set_title",{label:this.label,value:e})}async maximize(){return o("plugin:window|maximize",{label:this.label})}async unmaximize(){return o("plugin:window|unmaximize",{label:this.label})}async toggleMaximize(){return o("plugin:window|toggle_maximize",{label:this.label})}async minimize(){return o("plugin:window|minimize",{label:this.label})}async unminimize(){return o("plugin:window|unminimize",{label:this.label})}async show(){return o("plugin:window|show",{label:this.label})}async hide(){return o("plugin:window|hide",{label:this.label})}async close(){return o("plugin:window|close",{label:this.label})}async destroy(){return o("plugin:window|destroy",{label:this.label})}async setDecorations(e){return o("plugin:window|set_decorations",{label:this.label,value:e})}async setShadow(e){return o("plugin:window|set_shadow",{label:this.label,value:e})}async setEffects(e){return o("plugin:window|set_effects",{label:this.label,value:e})}async clearEffects(){return o("plugin:window|set_effects",{label:this.label,value:null})}async setAlwaysOnTop(e){return o("plugin:window|set_always_on_top",{label:this.label,value:e})}async setAlwaysOnBottom(e){return o("plugin:window|set_always_on_bottom",{label:this.label,value:e})}async setContentProtected(e){return o("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 o("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 o("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 o("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 o("plugin:window|set_position",{label:this.label,value:{type:e.type,data:{x:e.x,y:e.y}}})}async setFullscreen(e){return o("plugin:window|set_fullscreen",{label:this.label,value:e})}async setFocus(){return o("plugin:window|set_focus",{label:this.label})}async setIcon(e){return o("plugin:window|set_icon",{label:this.label,value:D(e)})}async setSkipTaskbar(e){return o("plugin:window|set_skip_taskbar",{label:this.label,value:e})}async setCursorGrab(e){return o("plugin:window|set_cursor_grab",{label:this.label,value:e})}async setCursorVisible(e){return o("plugin:window|set_cursor_visible",{label:this.label,value:e})}async setCursorIcon(e){return o("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 o("plugin:window|set_cursor_position",{label:this.label,value:{type:e.type,data:{x:e.x,y:e.y}}})}async setIgnoreCursorEvents(e){return o("plugin:window|set_ignore_cursor_events",{label:this.label,value:e})}async startDragging(){return o("plugin:window|start_dragging",{label:this.label})}async startResizeDragging(e){return o("plugin:window|start_resize_dragging",{label:this.label,value:e})}async setProgressBar(e){return o("plugin:window|set_progress_bar",{label:this.label,value:e})}async setVisibleOnAllWorkspaces(e){return o("plugin:window|set_visible_on_all_workspaces",{label:this.label,value:e})}async onResized(e){return this.listen(d.WINDOW_RESIZED,(t=>{t.payload=N(t.payload),e(t)}))}async onMoved(e){return this.listen(d.WINDOW_MOVED,(t=>{t.payload=W(t.payload),e(t)}))}async onCloseRequested(e){return this.listen(d.WINDOW_CLOSE_REQUESTED,(t=>{const n=new S(t);Promise.resolve(e(n)).then((()=>{if(!n.isPreventDefault())return this.destroy()}))}))}async onFileDropEvent(e){const t=await this.listen(d.FILE_DROP,(t=>{e({...t,payload:{type:"drop",paths:t.payload.paths,position:W(t.payload.position)}})})),n=await this.listen(d.FILE_DROP_HOVER,(t=>{e({...t,payload:{type:"hover",paths:t.payload.paths,position:W(t.payload.position)}})})),i=await this.listen(d.FILE_DROP_CANCELLED,(t=>{e({...t,payload:{type:"cancel"}})}));return()=>{t(),n(),i()}}async onFocusChanged(e){const t=await this.listen(d.WINDOW_FOCUS,(t=>{e({...t,payload:!0})})),n=await this.listen(d.WINDOW_BLUR,(t=>{e({...t,payload:!1})}));return()=>{t(),n()}}async onScaleChanged(e){return this.listen(d.WINDOW_SCALE_FACTOR_CHANGED,e)}async onThemeChanged(e){return this.listen(d.WINDOW_THEME_CHANGED,e)}}var R,F;function O(e){return null===e?null:{name:e.name,scaleFactor:e.scaleFactor,position:W(e.position),size:N(e.size)}}function W(e){return new k(e.x,e.y)}function N(e){return new f(e.width,e.height)}!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"}(R||(R={})),function(e){e.FollowsWindowActiveState="followsWindowActiveState",e.Active="active",e.Inactive="inactive"}(F||(F={}));var M=Object.freeze({__proto__:null,CloseRequestedEvent:S,get Effect(){return R},get EffectState(){return F},LogicalPosition:v,LogicalSize:m,PhysicalPosition:k,PhysicalSize:f,get ProgressBarStatus(){return L},get UserAttentionType(){return P},Window:z,availableMonitors:async function(){return o("plugin:window|available_monitors").then((e=>e.map(O)))},currentMonitor:async function(){return o("plugin:window|current_monitor").then(O)},getAll:C,getCurrent:T,primaryMonitor:async function(){return o("plugin:window|primary_monitor").then(O)}});function U(){return new V(T(),window.__TAURI_INTERNALS__.metadata.currentWebview.label,{skip:!0})}function B(){return window.__TAURI_INTERNALS__.metadata.webviews.map((e=>new V(z.getByLabel(e.windowLabel),e.label,{skip:!0})))}const j=["tauri://created","tauri://error"];class V{constructor(e,t,n){this.window=e,this.label=t,this.listeners=Object.create(null),n?.skip||o("plugin:webview|create_webview",{windowLabel:e.label,label:t,options:n}).then((async()=>this.emit("tauri://created"))).catch((async e=>this.emit("tauri://error",e)))}static getByLabel(e){return B().find((t=>t.label===e))??null}static getCurrent(){return U()}static getAll(){return B()}async listen(e,t){return this._handleTauriEvent(e,t)?Promise.resolve((()=>{const n=this.listeners[e];n.splice(n.indexOf(t),1)})):y(e,t,{target:{kind:"Webview",label:this.label}})}async once(e,t){return this._handleTauriEvent(e,t)?Promise.resolve((()=>{const n=this.listeners[e];n.splice(n.indexOf(t),1)})):w(e,t,{target:{kind:"Webview",label:this.label}})}async emit(e,t){if(j.includes(e)){for(const n of this.listeners[e]||[])n({event:e,id:-1,payload:t});return Promise.resolve()}return g(e,t)}async emitTo(e,t,n){if(j.includes(t)){for(const e of this.listeners[t]||[])e({event:t,id:-1,payload:n});return Promise.resolve()}return b(e,t,n)}_handleTauriEvent(e,t){return!!j.includes(e)&&(e in this.listeners?this.listeners[e].push(t):this.listeners[e]=[t],!0)}async position(){return o("plugin:webview|webview_position",{label:this.label}).then((({x:e,y:t})=>new k(e,t)))}async size(){return o("plugin:webview|webview_size",{label:this.label}).then((({width:e,height:t})=>new f(e,t)))}async close(){return o("plugin:webview|close",{label:this.label})}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 o("plugin:webview|set_webview_size",{label:this.label,value:{type:e.type,data:{width:e.width,height:e.height}}})}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 o("plugin:webview|set_webview_position",{label:this.label,value:{type:e.type,data:{x:e.x,y:e.y}}})}async setFocus(){return o("plugin:webview|set_webview_focus",{label:this.label})}async reparent(e){return o("plugin:webview|set_webview_focus",{label:this.label,window:"string"==typeof e?e:e.label})}async onFileDropEvent(e){const t=await this.listen(d.FILE_DROP,(t=>{e({...t,payload:{type:"drop",paths:t.payload.paths,position:H(t.payload.position)}})})),n=await this.listen(d.FILE_DROP_HOVER,(t=>{e({...t,payload:{type:"hover",paths:t.payload.paths,position:H(t.payload.position)}})})),i=await this.listen(d.FILE_DROP_CANCELLED,(t=>{e({...t,payload:{type:"cancel"}})}));return()=>{t(),n(),i()}}}function H(e){return new k(e.x,e.y)}var G,q,Q=Object.freeze({__proto__:null,Webview:V,getAll:B,getCurrent:U});function $(){const e=U();return new J(e.label,{skip:!0})}function Z(){return window.__TAURI_INTERNALS__.metadata.webviews.map((e=>new J(e.label,{skip:!0})))}class J{constructor(e,t={}){this.label=e,this.listeners=Object.create(null),t?.skip||o("plugin:webview|create_webview_window",{options:{...t,parent:"string"==typeof t.parent?t.parent:t.parent?.label,label:e}}).then((async()=>this.emit("tauri://created"))).catch((async e=>this.emit("tauri://error",e)))}static getByLabel(e){const t=Z().find((t=>t.label===e))??null;return t?new J(t.label,{skip:!0}):null}static getCurrent(){return $()}static getAll(){return Z().map((e=>new J(e.label,{skip:!0})))}async listen(e,t){return this._handleTauriEvent(e,t)?Promise.resolve((()=>{const n=this.listeners[e];n.splice(n.indexOf(t),1)})):y(e,t,{target:{kind:"WebviewWindow",label:this.label}})}async once(e,t){return this._handleTauriEvent(e,t)?Promise.resolve((()=>{const n=this.listeners[e];n.splice(n.indexOf(t),1)})):w(e,t,{target:{kind:"WebviewWindow",label:this.label}})}}G=J,q=[z,V],(Array.isArray(q)?q:[q]).forEach((e=>{Object.getOwnPropertyNames(e.prototype).forEach((t=>{"object"==typeof G.prototype&&G.prototype&&t in G.prototype||Object.defineProperty(G.prototype,t,Object.getOwnPropertyDescriptor(e.prototype,t)??Object.create(null))}))}));var K,Y=Object.freeze({__proto__:null,WebviewWindow:J,getAll:Z,getCurrent:$});!function(e){e[e.Audio=1]="Audio",e[e.Cache=2]="Cache",e[e.Config=3]="Config",e[e.Data=4]="Data",e[e.LocalData=5]="LocalData",e[e.Document=6]="Document",e[e.Download=7]="Download",e[e.Picture=8]="Picture",e[e.Public=9]="Public",e[e.Video=10]="Video",e[e.Resource=11]="Resource",e[e.Temp=12]="Temp",e[e.AppConfig=13]="AppConfig",e[e.AppData=14]="AppData",e[e.AppLocalData=15]="AppLocalData",e[e.AppCache=16]="AppCache",e[e.AppLog=17]="AppLog",e[e.Desktop=18]="Desktop",e[e.Executable=19]="Executable",e[e.Font=20]="Font",e[e.Home=21]="Home",e[e.Runtime=22]="Runtime",e[e.Template=23]="Template"}(K||(K={}));var X=Object.freeze({__proto__:null,get BaseDirectory(){return K},appCacheDir:async function(){return o("plugin:path|resolve_directory",{directory:K.AppCache})},appConfigDir:async function(){return o("plugin:path|resolve_directory",{directory:K.AppConfig})},appDataDir:async function(){return o("plugin:path|resolve_directory",{directory:K.AppData})},appLocalDataDir:async function(){return o("plugin:path|resolve_directory",{directory:K.AppLocalData})},appLogDir:async function(){return o("plugin:path|resolve_directory",{directory:K.AppLog})},audioDir:async function(){return o("plugin:path|resolve_directory",{directory:K.Audio})},basename:async function(e,t){return o("plugin:path|basename",{path:e,ext:t})},cacheDir:async function(){return o("plugin:path|resolve_directory",{directory:K.Cache})},configDir:async function(){return o("plugin:path|resolve_directory",{directory:K.Config})},dataDir:async function(){return o("plugin:path|resolve_directory",{directory:K.Data})},delimiter:function(){return window.__TAURI_INTERNALS__.plugins.path.delimiter},desktopDir:async function(){return o("plugin:path|resolve_directory",{directory:K.Desktop})},dirname:async function(e){return o("plugin:path|dirname",{path:e})},documentDir:async function(){return o("plugin:path|resolve_directory",{directory:K.Document})},downloadDir:async function(){return o("plugin:path|resolve_directory",{directory:K.Download})},executableDir:async function(){return o("plugin:path|resolve_directory",{directory:K.Executable})},extname:async function(e){return o("plugin:path|extname",{path:e})},fontDir:async function(){return o("plugin:path|resolve_directory",{directory:K.Font})},homeDir:async function(){return o("plugin:path|resolve_directory",{directory:K.Home})},isAbsolute:async function(e){return o("plugin:path|isAbsolute",{path:e})},join:async function(...e){return o("plugin:path|join",{paths:e})},localDataDir:async function(){return o("plugin:path|resolve_directory",{directory:K.LocalData})},normalize:async function(e){return o("plugin:path|normalize",{path:e})},pictureDir:async function(){return o("plugin:path|resolve_directory",{directory:K.Picture})},publicDir:async function(){return o("plugin:path|resolve_directory",{directory:K.Public})},resolve:async function(...e){return o("plugin:path|resolve",{paths:e})},resolveResource:async function(e){return o("plugin:path|resolve_directory",{directory:K.Resource,path:e})},resourceDir:async function(){return o("plugin:path|resolve_directory",{directory:K.Resource})},runtimeDir:async function(){return o("plugin:path|resolve_directory",{directory:K.Runtime})},sep:function(){return window.__TAURI_INTERNALS__.plugins.path.sep},tempDir:async function(){return o("plugin:path|resolve_directory",{directory:K.Temp})},templateDir:async function(){return o("plugin:path|resolve_directory",{directory:K.Template})},videoDir:async function(){return o("plugin:path|resolve_directory",{directory:K.Video})}});class ee extends u{constructor(e,t){super(e),this.id=t}static async new(e){e?.menu&&(e.menu=[e.menu.rid,e.menu.kind]),e?.icon&&(e.icon=D(e.icon));const t=new s;return e?.action&&(t.onmessage=e.action,delete e.action),o("plugin:tray|new",{options:e??{},handler:t}).then((([e,t])=>new ee(e,t)))}async setIcon(e){let t=null;return e&&(t=D(e)),o("plugin:tray|set_icon",{rid:this.rid,icon:t})}async setMenu(e){return e&&(e=[e.rid,e.kind]),o("plugin:tray|set_menu",{rid:this.rid,menu:e})}async setTooltip(e){return o("plugin:tray|set_tooltip",{rid:this.rid,tooltip:e})}async setTitle(e){return o("plugin:tray|set_title",{rid:this.rid,title:e})}async setVisible(e){return o("plugin:tray|set_visible",{rid:this.rid,visible:e})}async setTempDirPath(e){return o("plugin:tray|set_temp_dir_path",{rid:this.rid,path:e})}async setIconAsTemplate(e){return o("plugin:tray|set_icon_as_template",{rid:this.rid,asTemplate:e})}async setMenuOnLeftClick(e){return o("plugin:tray|set_show_menu_on_left_click",{rid:this.rid,onLeft:e})}}var te,ne,ie,re=Object.freeze({__proto__:null,TrayIcon:ee});function ae(e){if("items"in e)e.items=e.items?.map((e=>"rid"in e?e:ae(e)));else if("action"in e&&e.action){const t=new s;return t.onmessage=e.action,delete e.action,{...e,handler:t}}return e}async function se(e,t){const n=new s;let i=null;return t&&"object"==typeof t&&("action"in t&&t.action&&(n.onmessage=t.action,delete t.action),"items"in t&&t.items&&(i=t.items.map((e=>"rid"in e?[e.rid,e.kind]:("item"in e&&"object"==typeof e.item&&e.item.About?.icon&&(e.item.About.icon=D(e.item.About.icon)),"icon"in e&&e.icon&&(e.icon=D(e.icon)),ae(e)))))),o("plugin:menu|new",{kind:e,options:t?{...t,items:i}:void 0,handler:n})}class le extends u{get id(){return t(this,te,"f")}get kind(){return t(this,ne,"f")}constructor(e,t,i){super(e),te.set(this,void 0),ne.set(this,void 0),n(this,te,t,"f"),n(this,ne,i,"f")}}te=new WeakMap,ne=new WeakMap;class oe extends le{constructor(e,t){super(e,t,"MenuItem")}static async new(e){return se("MenuItem",e).then((([e,t])=>new oe(e,t)))}async text(){return o("plugin:menu|text",{rid:this.rid,kind:this.kind})}async setText(e){return o("plugin:menu|set_text",{rid:this.rid,kind:this.kind,text:e})}async isEnabled(){return o("plugin:menu|is_enabled",{rid:this.rid,kind:this.kind})}async setEnabled(e){return o("plugin:menu|set_enabled",{rid:this.rid,kind:this.kind,enabled:e})}async setAccelerator(e){return o("plugin:menu|set_accelerator",{rid:this.rid,kind:this.kind,accelerator:e})}}class ue extends le{constructor(e,t){super(e,t,"Check")}static async new(e){return se("Check",e).then((([e,t])=>new ue(e,t)))}async text(){return o("plugin:menu|text",{rid:this.rid,kind:this.kind})}async setText(e){return o("plugin:menu|set_text",{rid:this.rid,kind:this.kind,text:e})}async isEnabled(){return o("plugin:menu|is_enabled",{rid:this.rid,kind:this.kind})}async setEnabled(e){return o("plugin:menu|set_enabled",{rid:this.rid,kind:this.kind,enabled:e})}async setAccelerator(e){return o("plugin:menu|set_accelerator",{rid:this.rid,kind:this.kind,accelerator:e})}async isChecked(){return o("plugin:menu|is_checked",{rid:this.rid})}async setChecked(e){return o("plugin:menu|set_checked",{rid:this.rid,checked:e})}}!function(e){e.Add="Add",e.Advanced="Advanced",e.Bluetooth="Bluetooth",e.Bookmarks="Bookmarks",e.Caution="Caution",e.ColorPanel="ColorPanel",e.ColumnView="ColumnView",e.Computer="Computer",e.EnterFullScreen="EnterFullScreen",e.Everyone="Everyone",e.ExitFullScreen="ExitFullScreen",e.FlowView="FlowView",e.Folder="Folder",e.FolderBurnable="FolderBurnable",e.FolderSmart="FolderSmart",e.FollowLinkFreestanding="FollowLinkFreestanding",e.FontPanel="FontPanel",e.GoLeft="GoLeft",e.GoRight="GoRight",e.Home="Home",e.IChatTheater="IChatTheater",e.IconView="IconView",e.Info="Info",e.InvalidDataFreestanding="InvalidDataFreestanding",e.LeftFacingTriangle="LeftFacingTriangle",e.ListView="ListView",e.LockLocked="LockLocked",e.LockUnlocked="LockUnlocked",e.MenuMixedState="MenuMixedState",e.MenuOnState="MenuOnState",e.MobileMe="MobileMe",e.MultipleDocuments="MultipleDocuments",e.Network="Network",e.Path="Path",e.PreferencesGeneral="PreferencesGeneral",e.QuickLook="QuickLook",e.RefreshFreestanding="RefreshFreestanding",e.Refresh="Refresh",e.Remove="Remove",e.RevealFreestanding="RevealFreestanding",e.RightFacingTriangle="RightFacingTriangle",e.Share="Share",e.Slideshow="Slideshow",e.SmartBadge="SmartBadge",e.StatusAvailable="StatusAvailable",e.StatusNone="StatusNone",e.StatusPartiallyAvailable="StatusPartiallyAvailable",e.StatusUnavailable="StatusUnavailable",e.StopProgressFreestanding="StopProgressFreestanding",e.StopProgress="StopProgress",e.TrashEmpty="TrashEmpty",e.TrashFull="TrashFull",e.User="User",e.UserAccounts="UserAccounts",e.UserGroup="UserGroup",e.UserGuest="UserGuest"}(ie||(ie={}));class ce extends le{constructor(e,t){super(e,t,"Icon")}static async new(e){return se("Icon",e).then((([e,t])=>new ce(e,t)))}async text(){return o("plugin:menu|text",{rid:this.rid,kind:this.kind})}async setText(e){return o("plugin:menu|set_text",{rid:this.rid,kind:this.kind,text:e})}async isEnabled(){return o("plugin:menu|is_enabled",{rid:this.rid,kind:this.kind})}async setEnabled(e){return o("plugin:menu|set_enabled",{rid:this.rid,kind:this.kind,enabled:e})}async setAccelerator(e){return o("plugin:menu|set_accelerator",{rid:this.rid,kind:this.kind,accelerator:e})}async setIcon(e){return o("plugin:menu|set_icon",{rid:this.rid,icon:D(e)})}}class de extends le{constructor(e,t){super(e,t,"Predefined")}static async new(e){return se("Predefined",e).then((([e,t])=>new de(e,t)))}async text(){return o("plugin:menu|text",{rid:this.rid,kind:this.kind})}async setText(e){return o("plugin:menu|set_text",{rid:this.rid,kind:this.kind,text:e})}}function pe([e,t,n]){switch(n){case"Submenu":return new he(e,t);case"Predefined":return new de(e,t);case"Check":return new ue(e,t);case"Icon":return new ce(e,t);default:return new oe(e,t)}}class he extends le{constructor(e,t){super(e,t,"Submenu")}static async new(e){return se("Submenu",e).then((([e,t])=>new he(e,t)))}async text(){return o("plugin:menu|text",{rid:this.rid,kind:this.kind})}async setText(e){return o("plugin:menu|set_text",{rid:this.rid,kind:this.kind,text:e})}async isEnabled(){return o("plugin:menu|is_enabled",{rid:this.rid,kind:this.kind})}async setEnabled(e){return o("plugin:menu|set_enabled",{rid:this.rid,kind:this.kind,enabled:e})}async append(e){return o("plugin:menu|append",{rid:this.rid,kind:this.kind,items:(Array.isArray(e)?e:[e]).map((e=>"rid"in e?[e.rid,e.kind]:e))})}async prepend(e){return o("plugin:menu|prepend",{rid:this.rid,kind:this.kind,items:(Array.isArray(e)?e:[e]).map((e=>"rid"in e?[e.rid,e.kind]:e))})}async insert(e,t){return o("plugin:menu|insert",{rid:this.rid,kind:this.kind,items:(Array.isArray(e)?e:[e]).map((e=>"rid"in e?[e.rid,e.kind]:e)),position:t})}async remove(e){return o("plugin:menu|remove",{rid:this.rid,kind:this.kind,item:[e.rid,e.kind]})}async removeAt(e){return o("plugin:menu|remove_at",{rid:this.rid,kind:this.kind,position:e}).then(pe)}async items(){return o("plugin:menu|items",{rid:this.rid,kind:this.kind}).then((e=>e.map(pe)))}async get(e){return o("plugin:menu|get",{rid:this.rid,kind:this.kind,id:e}).then((e=>e?pe(e):null))}async popup(e,t){let n=null;return e&&(n={type:e instanceof k?"Physical":"Logical",data:e}),o("plugin:menu|popup",{rid:this.rid,kind:this.kind,window:t?.label??null,at:n})}async setAsWindowsMenuForNSApp(){return o("plugin:menu|set_as_windows_menu_for_nsapp",{rid:this.rid})}async setAsHelpMenuForNSApp(){return o("plugin:menu|set_as_help_menu_for_nsapp",{rid:this.rid})}}function ye([e,t,n]){switch(n){case"Submenu":return new he(e,t);case"Predefined":return new de(e,t);case"Check":return new ue(e,t);case"Icon":return new ce(e,t);default:return new oe(e,t)}}class we extends le{constructor(e,t){super(e,t,"Menu")}static async new(e){return se("Menu",e).then((([e,t])=>new we(e,t)))}static async default(){return o("plugin:menu|create_default").then((([e,t])=>new we(e,t)))}async append(e){return o("plugin:menu|append",{rid:this.rid,kind:this.kind,items:(Array.isArray(e)?e:[e]).map((e=>"rid"in e?[e.rid,e.kind]:e))})}async prepend(e){return o("plugin:menu|prepend",{rid:this.rid,kind:this.kind,items:(Array.isArray(e)?e:[e]).map((e=>"rid"in e?[e.rid,e.kind]:e))})}async insert(e,t){return o("plugin:menu|insert",{rid:this.rid,kind:this.kind,items:(Array.isArray(e)?e:[e]).map((e=>"rid"in e?[e.rid,e.kind]:e)),position:t})}async remove(e){return o("plugin:menu|remove",{rid:this.rid,kind:this.kind,item:[e.rid,e.kind]})}async removeAt(e){return o("plugin:menu|remove_at",{rid:this.rid,kind:this.kind,position:e}).then(ye)}async items(){return o("plugin:menu|items",{rid:this.rid,kind:this.kind}).then((e=>e.map(ye)))}async get(e){return o("plugin:menu|get",{rid:this.rid,kind:this.kind,id:e}).then((e=>e?ye(e):null))}async popup(e,t){let n=null;return e&&(n={type:e instanceof k?"Physical":"Logical",data:e}),o("plugin:menu|popup",{rid:this.rid,kind:this.kind,window:t?.label??null,at:n})}async setAsAppMenu(){return o("plugin:menu|set_as_app_menu",{rid:this.rid}).then((e=>e?new we(e[0],e[1]):null))}async setAsWindowMenu(e){return o("plugin:menu|set_as_window_menu",{rid:this.rid,window:e?.label??null}).then((e=>e?new we(e[0],e[1]):null))}}var ge=Object.freeze({__proto__:null,CheckMenuItem:ue,IconMenuItem:ce,Menu:we,MenuItem:oe,get NativeIcon(){return ie},PredefinedMenuItem:de,Submenu:he});return e.app=p,e.core=c,e.dpi=A,e.event=_,e.image=I,e.menu=ge,e.path=X,e.tray=re,e.webview=Q,e.webviewWindow=Y,e.window=M,e}({});window.__TAURI__=__TAURI_IIFE__; diff --git a/core/tauri/src/app.rs b/core/tauri/src/app.rs index 0d51b1a59..d8c9afe44 100644 --- a/core/tauri/src/app.rs +++ b/core/tauri/src/app.rs @@ -870,6 +870,7 @@ impl App { self.handle.plugin(crate::webview::plugin::init())?; self.handle.plugin(crate::app::plugin::init())?; self.handle.plugin(crate::resources::plugin::init())?; + self.handle.plugin(crate::image::plugin::init())?; #[cfg(desktop)] self.handle.plugin(crate::menu::plugin::init())?; #[cfg(all(desktop, feature = "tray-icon"))] diff --git a/core/tauri/src/image.rs b/core/tauri/src/image/mod.rs similarity index 77% rename from core/tauri/src/image.rs rename to core/tauri/src/image/mod.rs index 852ddf65a..ce8fdd3ea 100644 --- a/core/tauri/src/image.rs +++ b/core/tauri/src/image/mod.rs @@ -2,8 +2,13 @@ // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT +pub mod plugin; + use std::borrow::Cow; use std::io::{Error, ErrorKind}; +use std::sync::Arc; + +use crate::{Manager, Resource, ResourceId, Runtime}; /// An RGBA Image in row-major order from top to bottom. #[derive(Debug, Clone)] @@ -13,6 +18,21 @@ pub struct Image<'a> { height: u32, } +impl Resource for Image<'static> {} + +impl Image<'static> { + /// Creates a new Image using RGBA data, in row-major order from top to bottom, and with specified width and height. + /// + /// Similar to [`Self::new`] but avoids cloning the rgba data to get an owned Image. + pub const fn new_owned(rgba: Vec, width: u32, height: u32) -> Self { + Self { + rgba: Cow::Owned(rgba), + width, + height, + } + } +} + impl<'a> Image<'a> { /// Creates a new Image using RGBA data, in row-major order from top to bottom, and with specified width and height. pub const fn new(rgba: &'a [u8], width: u32, height: u32) -> Self { @@ -123,6 +143,19 @@ impl<'a> Image<'a> { pub fn height(&self) -> u32 { self.height } + + /// Convert into a 'static owned [`Image`]. + /// This will allocate. + pub fn to_owned(self) -> Image<'static> { + Image { + rgba: match self.rgba { + Cow::Owned(v) => Cow::Owned(v), + Cow::Borrowed(v) => Cow::Owned(v.to_vec()), + }, + height: self.height, + width: self.width, + } + } } impl<'a> From> for crate::runtime::Icon<'a> { @@ -153,12 +186,12 @@ impl TryFrom> for tray_icon::Icon { } } -#[cfg(desktop)] #[derive(serde::Deserialize)] #[serde(untagged)] -pub enum JsIcon<'a> { +pub enum JsImage<'a> { Path(std::path::PathBuf), Bytes(&'a [u8]), + Resource(ResourceId), Rgba { rgba: &'a [u8], width: u32, @@ -166,23 +199,24 @@ pub enum JsIcon<'a> { }, } -#[cfg(desktop)] -impl<'a> TryFrom> for Image<'a> { - type Error = crate::Error; - - fn try_from(img: JsIcon<'a>) -> Result { - match img { +impl<'a> JsImage<'a> { + pub fn into_img>(self, app: &M) -> crate::Result>> { + match self { + Self::Resource(rid) => { + let resources_table = app.resources_table(); + resources_table.get::>(rid) + } #[cfg(any(feature = "image-ico", feature = "image-png"))] - JsIcon::Path(path) => Self::from_path(path).map_err(Into::into), + Self::Path(path) => Image::from_path(path).map(Arc::new).map_err(Into::into), #[cfg(any(feature = "image-ico", feature = "image-png"))] - JsIcon::Bytes(bytes) => Self::from_bytes(bytes).map_err(Into::into), + Self::Bytes(bytes) => Image::from_bytes(bytes).map(Arc::new).map_err(Into::into), - JsIcon::Rgba { + Self::Rgba { rgba, width, height, - } => Ok(Self::new(rgba, width, height)), + } => Ok(Arc::new(Image::new(rgba, width, height))), #[cfg(not(any(feature = "image-ico", feature = "image-png")))] _ => Err( @@ -190,9 +224,9 @@ impl<'a> TryFrom> for Image<'a> { ErrorKind::InvalidInput, format!( "expected RGBA image data, found {}", - match img { - JsIcon::Path(_) => "a file path", - JsIcon::Bytes(_) => "raw bytes", + match self { + JsImage::Path(_) => "a file path", + JsImage::Bytes(_) => "raw bytes", _ => unreachable!(), } ), diff --git a/core/tauri/src/image/plugin.rs b/core/tauri/src/image/plugin.rs new file mode 100644 index 000000000..e604a3ff8 --- /dev/null +++ b/core/tauri/src/image/plugin.rs @@ -0,0 +1,116 @@ +// Copyright 2019-2024 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +use crate::plugin::{Builder, TauriPlugin}; +use crate::{command, AppHandle, Image, Manager, ResourceId, Runtime}; + +#[command(root = "crate")] +fn new( + app: AppHandle, + rgba: Vec, + width: u32, + height: u32, +) -> crate::Result { + let image = Image::new_owned(rgba, width, height); + let mut resources_table = app.resources_table(); + let rid = resources_table.add(image); + Ok(rid) +} + +#[cfg(any(feature = "image-ico", feature = "image-png"))] +#[command(root = "crate")] +fn from_bytes(app: AppHandle, bytes: Vec) -> crate::Result { + let image = Image::from_bytes(&bytes)?.to_owned(); + let mut resources_table = app.resources_table(); + let rid = resources_table.add(image); + Ok(rid) +} + +#[cfg(not(any(feature = "image-ico", feature = "image-png")))] +#[command(root = "crate")] +fn from_bytes() -> std::result::Result<(), &'static str> { + Err("from_bytes is only supported if the `image-ico` or `image-png` Cargo features are enabled") +} + +#[cfg(feature = "image-ico")] +#[command(root = "crate")] +fn from_ico_bytes(app: AppHandle, bytes: Vec) -> crate::Result { + let image = Image::from_ico_bytes(&bytes)?.to_owned(); + let mut resources_table = app.resources_table(); + let rid = resources_table.add(image); + Ok(rid) +} + +#[cfg(not(feature = "image-ico"))] +#[command(root = "crate")] +fn from_ico_bytes() -> std::result::Result<(), &'static str> { + Err("from_ico_bytes is only supported if the `image-ico` Cargo feature is enabled") +} + +#[cfg(feature = "image-png")] +#[command(root = "crate")] +fn from_png_bytes(app: AppHandle, bytes: Vec) -> crate::Result { + let image = Image::from_png_bytes(&bytes)?.to_owned(); + let mut resources_table = app.resources_table(); + let rid = resources_table.add(image); + Ok(rid) +} + +#[cfg(not(feature = "image-png"))] +#[command(root = "crate")] +fn from_png_bytes() -> std::result::Result<(), &'static str> { + Err("from_png_bytes is only supported if the `image-ico` Cargo feature is enabled") +} + +#[cfg(any(feature = "image-ico", feature = "image-png"))] +#[command(root = "crate")] +fn from_path(app: AppHandle, path: std::path::PathBuf) -> crate::Result { + let image = Image::from_path(path)?.to_owned(); + let mut resources_table = app.resources_table(); + let rid = resources_table.add(image); + Ok(rid) +} + +#[cfg(not(any(feature = "image-ico", feature = "image-png")))] +#[command(root = "crate")] +fn from_path() -> std::result::Result<(), &'static str> { + Err("from_path is only supported if the `image-ico` or `image-png` Cargo features are enabled") +} + +#[command(root = "crate")] +fn rgba(app: AppHandle, rid: ResourceId) -> crate::Result> { + let resources_table = app.resources_table(); + let image = resources_table.get::>(rid)?; + Ok(image.rgba().to_vec()) +} + +#[command(root = "crate")] +fn width(app: AppHandle, rid: ResourceId) -> crate::Result { + let resources_table = app.resources_table(); + let image = resources_table.get::>(rid)?; + Ok(image.width()) +} + +#[command(root = "crate")] +fn height(app: AppHandle, rid: ResourceId) -> crate::Result { + let resources_table = app.resources_table(); + let image = resources_table.get::>(rid)?; + Ok(image.height()) +} + +/// Initializes the plugin. +pub fn init() -> TauriPlugin { + Builder::new("image") + .invoke_handler(crate::generate_handler![ + new, + from_bytes, + from_ico_bytes, + from_png_bytes, + from_path, + rgba, + width, + height + ]) + .build() +} diff --git a/core/tauri/src/menu/plugin.rs b/core/tauri/src/menu/plugin.rs index 9ffb763d6..87d45881b 100644 --- a/core/tauri/src/menu/plugin.rs +++ b/core/tauri/src/menu/plugin.rs @@ -13,7 +13,7 @@ use tauri_runtime::window::dpi::Position; use super::{sealed::ContextMenuBase, *}; use crate::{ command, - image::JsIcon, + image::JsImage, ipc::{channel::JavaScriptChannelId, Channel}, plugin::{Builder, TauriPlugin}, resources::{ResourceId, ResourceTable}, @@ -46,29 +46,30 @@ pub(crate) struct AboutMetadata<'a> { pub website_label: Option, pub credits: Option, #[serde(borrow)] - pub icon: Option>, + pub icon: Option>, } -impl<'a> TryFrom> for super::AboutMetadata<'a> { - type Error = crate::Error; - - fn try_from(value: AboutMetadata<'a>) -> Result { - let icon = match value.icon { - Some(i) => Some(i.try_into()?), +impl<'a> AboutMetadata<'a> { + pub fn into_metdata>( + self, + app: &M, + ) -> crate::Result> { + let icon = match self.icon { + Some(i) => Some(i.into_img(app)?.as_ref().clone()), None => None, }; - Ok(Self { - name: value.name, - version: value.version, - short_version: value.short_version, - authors: value.authors, - comments: value.comments, - copyright: value.copyright, - license: value.license, - website: value.website, - website_label: value.website_label, - credits: value.credits, + Ok(super::AboutMetadata { + name: self.name, + version: self.version, + short_version: self.short_version, + authors: self.authors, + comments: self.comments, + copyright: self.copyright, + license: self.license, + website: self.website, + website_label: self.website_label, + credits: self.credits, icon, }) } @@ -173,7 +174,7 @@ impl CheckMenuItemPayload { enum Icon<'a> { Native(NativeIcon), #[serde(borrow)] - Icon(JsIcon<'a>), + Icon(JsImage<'a>), } #[derive(Deserialize)] @@ -203,7 +204,7 @@ impl<'a> IconMenuItemPayload<'a> { } builder = match self.icon { Icon::Native(native_icon) => builder.native_icon(native_icon), - Icon::Icon(icon) => builder.icon(icon.try_into()?), + Icon::Icon(icon) => builder.icon(icon.into_img(webview)?.as_ref().clone()), }; let item = builder.build(webview)?; @@ -291,7 +292,7 @@ impl<'a> PredefinedMenuItemPayload<'a> { Predefined::Quit => PredefinedMenuItem::quit(webview, self.text.as_deref()), Predefined::About(metadata) => { let metadata = match metadata { - Some(m) => Some(m.try_into()?), + Some(m) => Some(m.into_metdata(webview)?), None => None, }; PredefinedMenuItem::about(webview, self.text.as_deref(), metadata) @@ -852,7 +853,7 @@ fn set_icon( match icon { Some(Icon::Native(icon)) => icon_item.set_native_icon(Some(icon)), - Some(Icon::Icon(icon)) => icon_item.set_icon(Some(icon.try_into()?)), + Some(Icon::Icon(icon)) => icon_item.set_icon(Some(icon.into_img(&app)?.as_ref().clone())), None => { icon_item.set_icon(None)?; icon_item.set_native_icon(None)?; diff --git a/core/tauri/src/tray/plugin.rs b/core/tauri/src/tray/plugin.rs index 1547eb99a..89f606903 100644 --- a/core/tauri/src/tray/plugin.rs +++ b/core/tauri/src/tray/plugin.rs @@ -8,7 +8,7 @@ use serde::Deserialize; use crate::{ command, - image::JsIcon, + image::JsImage, ipc::Channel, menu::{plugin::ItemKind, Menu, Submenu}, plugin::{Builder, TauriPlugin}, @@ -25,7 +25,7 @@ struct TrayIconOptions<'a> { id: Option, menu: Option<(ResourceId, ItemKind)>, #[serde(borrow)] - icon: Option>, + icon: Option>, tooltip: Option, title: Option, temp_dir_path: Option, @@ -65,7 +65,7 @@ fn new( }; } if let Some(icon) = options.icon { - builder = builder.icon(icon.try_into()?); + builder = builder.icon(icon.into_img(&app)?.as_ref().clone()); } if let Some(tooltip) = options.tooltip { builder = builder.tooltip(tooltip); @@ -94,12 +94,12 @@ fn new( fn set_icon( app: AppHandle, rid: ResourceId, - icon: Option>, + icon: Option>, ) -> crate::Result<()> { let resources_table = app.resources_table(); let tray = resources_table.get::>(rid)?; let icon = match icon { - Some(i) => Some(i.try_into()?), + Some(i) => Some(i.into_img(&app)?.as_ref().clone()), None => None, }; tray.set_icon(icon) diff --git a/core/tauri/src/window/plugin.rs b/core/tauri/src/window/plugin.rs index 2a678dafd..f00aee9cd 100644 --- a/core/tauri/src/window/plugin.rs +++ b/core/tauri/src/window/plugin.rs @@ -134,10 +134,11 @@ mod desktop_commands { pub async fn set_icon( window: Window, label: Option, - value: crate::image::JsIcon<'_>, + value: crate::image::JsImage<'_>, ) -> crate::Result<()> { - get_window(window, label)? - .set_icon(value.try_into()?) + let window = get_window(window, label)?; + window + .set_icon(value.into_img(&window)?.as_ref().clone()) .map_err(Into::into) } diff --git a/examples/api/src-tauri/Cargo.lock b/examples/api/src-tauri/Cargo.lock index 051e55d2e..922ea887e 100644 --- a/examples/api/src-tauri/Cargo.lock +++ b/examples/api/src-tauri/Cargo.lock @@ -2975,12 +2975,6 @@ dependencies = [ "loom", ] -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - [[package]] name = "string_cache" version = "0.8.7" @@ -3182,7 +3176,6 @@ dependencies = [ "serde_repr", "serialize-to-javascript", "state", - "static_assertions", "swift-rs", "tauri-build", "tauri-macros", diff --git a/examples/api/src-tauri/capabilities/run-app.json b/examples/api/src-tauri/capabilities/run-app.json index a1f9743f4..c2150e890 100644 --- a/examples/api/src-tauri/capabilities/run-app.json +++ b/examples/api/src-tauri/capabilities/run-app.json @@ -2,10 +2,7 @@ "$schema": "../gen/schemas/desktop-schema.json", "identifier": "run-app", "description": "permissions to run the app", - "windows": [ - "main", - "main-*" - ], + "windows": ["main", "main-*"], "permissions": [ { "identifier": "allow-log-operation", @@ -24,6 +21,7 @@ "window:default", "app:default", "resources:default", + "image:default", "menu:default", "tray:default", "app:allow-app-hide", @@ -98,4 +96,4 @@ "tray:allow-set-icon-as-template", "tray:allow-set-show-menu-on-left-click" ] -} \ No newline at end of file +} diff --git a/tooling/api/src/image.ts b/tooling/api/src/image.ts new file mode 100644 index 000000000..708b3a89c --- /dev/null +++ b/tooling/api/src/image.ts @@ -0,0 +1,141 @@ +// Copyright 2019-2024 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +import { Resource, invoke } from './core' + +/** An RGBA Image in row-major order from top to bottom. */ +export class Image extends Resource { + private constructor(rid: number) { + super(rid) + } + + /** Creates a new Image using RGBA data, in row-major order from top to bottom, and with specified width and height. */ + static async new( + rgba: number[] | Uint8Array | ArrayBuffer, + width: number, + height: number + ): Promise { + return invoke('plugin:image|new', { + rgba: transformImage(rgba), + width, + height + }).then((rid) => new Image(rid)) + } + + /** + * Creates a new image using the provided bytes by inferring the file format. + * If the format is known, prefer [@link Image.fromPngBytes] or [@link Image.fromIcoBytes]. + * + * Only `ico` and `png` are supported (based on activated feature flag). + * + * Note that you need the `image-ico` or `image-png` Cargo features to use this API. + * To enable it, change your Cargo.toml file: + * ```toml + * [dependencies] + * tauri = { version = "...", features = ["...", "image-png"] } + * ``` + */ + static async fromBytes( + bytes: number[] | Uint8Array | ArrayBuffer + ): Promise { + return invoke('plugin:image|from_bytes', { + bytes: transformImage(bytes) + }).then((rid) => new Image(rid)) + } + + /** + * Creates a new image using the provided png bytes. + * + * Note that you need the `image-png` Cargo features to use this API. + * To enable it, change your Cargo.toml file: + * ```toml + * [dependencies] + * tauri = { version = "...", features = ["...", "image-png"] } + * ``` + */ + static async fromPngBytes( + bytes: number[] | Uint8Array | ArrayBuffer + ): Promise { + return invoke('plugin:image|from_png_bytes', { + bytes: transformImage(bytes) + }).then((rid) => new Image(rid)) + } + + /** + * Creates a new image using the provided ico bytes. + * + * Note that you need the `image-ico` Cargo features to use this API. + * To enable it, change your Cargo.toml file: + * ```toml + * [dependencies] + * tauri = { version = "...", features = ["...", "image-ico"] } + * ``` + */ + static async fromIcoBytes( + bytes: number[] | Uint8Array | ArrayBuffer + ): Promise { + return invoke('plugin:image|from_ico_bytes', { + bytes: transformImage(bytes) + }).then((rid) => new Image(rid)) + } + + /** + * Creates a new image using the provided path. + * + * Only `ico` and `png` are supported (based on activated feature flag). + * + * Note that you need the `image-ico` or `image-png` Cargo features to use this API. + * To enable it, change your Cargo.toml file: + * ```toml + * [dependencies] + * tauri = { version = "...", features = ["...", "image-png"] } + * ``` + */ + static async fromPath(path: string): Promise { + return invoke('plugin:image|from_path', { path }).then( + (rid) => new Image(rid) + ) + } + + /** Returns the RGBA data for this image, in row-major order from top to bottom. */ + async rgba(): Promise { + return invoke('plugin:image|rgba', { + rid: this.rid + }) + } + + /** Returns the width of this image. */ + async width() { + return invoke('plugin:image|width', { rid: this.rid }) + } + + /** Returns the height of this image. */ + async height() { + return invoke('plugin:image|height', { rid: this.rid }) + } +} + +/** + * Transforms image from various types into a type acceptable by Rust. Intended for internal use only. + * + * @ignore + */ +export function transformImage( + image: string | Image | Uint8Array | ArrayBuffer | number[] | null +): T { + const ret = + image == null + ? null + : typeof image === 'string' + ? image + : image instanceof Uint8Array + ? Array.from(image) + : image instanceof ArrayBuffer + ? Array.from(new Uint8Array(image)) + : image instanceof Image + ? image.rid + : image + + return ret as T +} diff --git a/tooling/api/src/index.ts b/tooling/api/src/index.ts index 5213f8d5c..ee01fc423 100644 --- a/tooling/api/src/index.ts +++ b/tooling/api/src/index.ts @@ -23,6 +23,7 @@ import * as path from './path' import * as dpi from './dpi' import * as tray from './tray' import * as menu from './menu' +import * as image from './image' export { app, @@ -34,5 +35,6 @@ export { webview, webviewWindow, tray, - menu + menu, + image } diff --git a/tooling/api/src/menu/base.ts b/tooling/api/src/menu/base.ts index f71968da7..41bdd81bb 100644 --- a/tooling/api/src/menu/base.ts +++ b/tooling/api/src/menu/base.ts @@ -3,6 +3,7 @@ // SPDX-License-Identifier: MIT import { Channel, invoke, Resource } from '../core' +import { transformImage } from '../image' import { CheckMenuItemOptions } from './checkMenuItem' import { IconMenuItemOptions } from './iconMenuItem' import { MenuItemOptions } from './menuItem' @@ -76,6 +77,15 @@ export async function newMenu( if ('rid' in i) { return [i.rid, i.kind] } + + if ('item' in i && typeof i.item === 'object' && i.item.About?.icon) { + i.item.About.icon = transformImage(i.item.About.icon) + } + + if ('icon' in i && i.icon) { + i.icon = transformImage(i.icon) + } + return injectChannel(i) }) } diff --git a/tooling/api/src/menu/iconMenuItem.ts b/tooling/api/src/menu/iconMenuItem.ts index 666a60c52..476b81491 100644 --- a/tooling/api/src/menu/iconMenuItem.ts +++ b/tooling/api/src/menu/iconMenuItem.ts @@ -5,6 +5,7 @@ import { MenuItemBase, newMenu } from './base' import { type MenuItemOptions } from '../menu' import { invoke } from '../core' +import { Image, transformImage } from '../image' /** * A native Icon to be used for the menu item @@ -133,7 +134,7 @@ export interface IconMenuItemOptions extends MenuItemOptions { /** * Icon to be used for the new icon menu item. */ - icon?: NativeIcon | string | Uint8Array + icon?: NativeIcon | string | Image | Uint8Array | ArrayBuffer | number[] } /** @@ -189,7 +190,19 @@ export class IconMenuItem extends MenuItemBase { } /** Sets an icon for this icon menu item */ - async setIcon(icon: NativeIcon | string | Uint8Array | null): Promise { - return invoke('plugin:menu|set_icon', { rid: this.rid, icon }) + async setIcon( + icon: + | NativeIcon + | string + | Image + | Uint8Array + | ArrayBuffer + | number[] + | null + ): Promise { + return invoke('plugin:menu|set_icon', { + rid: this.rid, + icon: transformImage(icon) + }) } } diff --git a/tooling/api/src/menu/predefinedMenuItem.ts b/tooling/api/src/menu/predefinedMenuItem.ts index 4f5a7de61..f01f04216 100644 --- a/tooling/api/src/menu/predefinedMenuItem.ts +++ b/tooling/api/src/menu/predefinedMenuItem.ts @@ -4,6 +4,7 @@ import { MenuItemBase, newMenu } from './base' import { invoke } from '../core' +import { Image } from '../image' /** A metadata for the about predefined menu item. */ export interface AboutMetadata { @@ -76,7 +77,7 @@ export interface AboutMetadata { * * - **Windows:** Unsupported. */ - icon?: string | Uint8Array + icon?: string | Uint8Array | ArrayBuffer | number[] | Image } /** Options for creating a new predefined menu item. */ diff --git a/tooling/api/src/tray.ts b/tooling/api/src/tray.ts index 6d98f0f9a..f958e80cf 100644 --- a/tooling/api/src/tray.ts +++ b/tooling/api/src/tray.ts @@ -4,6 +4,7 @@ import type { Menu, Submenu } from './menu' import { Channel, invoke, Resource } from './core' +import { Image, transformImage } from './image' /** * Describes a tray event emitted when a tray icon is clicked @@ -58,7 +59,7 @@ export interface TrayIconOptions { * tauri = { version = "...", features = ["...", "image-png"] } * ``` */ - icon?: string | Uint8Array | number[] + icon?: string | Uint8Array | ArrayBuffer | number[] | Image /** The tray icon tooltip */ tooltip?: string /** @@ -132,10 +133,7 @@ export class TrayIcon extends Resource { options.menu = [options.menu.rid, options.menu.kind] } if (options?.icon) { - options.icon = - typeof options.icon === 'string' - ? options.icon - : Array.from(options.icon) + options.icon = transformImage(options.icon) } const handler = new Channel() @@ -150,11 +148,22 @@ export class TrayIcon extends Resource { }).then(([rid, id]) => new TrayIcon(rid, id)) } - /** Sets a new tray icon. If `null` is provided, it will remove the icon. */ - async setIcon(icon: string | Uint8Array | null): Promise { + /** + * Sets a new tray icon. If `null` is provided, it will remove the icon. + * + * Note that you need the `image-ico` or `image-png` Cargo features to use this API. + * To enable it, change your Cargo.toml file: + * ```toml + * [dependencies] + * tauri = { version = "...", features = ["...", "image-png"] } + * ``` + */ + async setIcon( + icon: string | Image | Uint8Array | ArrayBuffer | number[] | null + ): Promise { let trayIcon = null if (icon) { - trayIcon = typeof icon === 'string' ? icon : Array.from(icon) + trayIcon = transformImage(icon) } return invoke('plugin:tray|set_icon', { rid: this.rid, icon: trayIcon }) } diff --git a/tooling/api/src/window.ts b/tooling/api/src/window.ts index 29f093f3b..3210107fe 100644 --- a/tooling/api/src/window.ts +++ b/tooling/api/src/window.ts @@ -36,6 +36,7 @@ import { import { invoke } from './core' import { WebviewWindow } from './webviewWindow' import type { FileDropEvent, FileDropPayload } from './webview' +import { Image, transformImage } from './image' /** * Allows you to retrieve information about a given monitor. @@ -1393,10 +1394,12 @@ class Window { * @param icon Icon bytes or path to the icon file. * @returns A promise indicating the success or failure of the operation. */ - async setIcon(icon: string | Uint8Array): Promise { + async setIcon( + icon: string | Image | Uint8Array | ArrayBuffer | number[] + ): Promise { return invoke('plugin:window|set_icon', { label: this.label, - value: typeof icon === 'string' ? icon : Array.from(icon) + value: transformImage(icon) }) } diff --git a/tooling/cli/templates/app/src-tauri/capabilities/default.json b/tooling/cli/templates/app/src-tauri/capabilities/default.json index e0c1510f4..9c58e495d 100644 --- a/tooling/cli/templates/app/src-tauri/capabilities/default.json +++ b/tooling/cli/templates/app/src-tauri/capabilities/default.json @@ -10,6 +10,7 @@ "webview:default", "app:default", "resources:default", + "image:default", "menu:default", "tray:default" ]