Fix invoke calls in dialog & shell init scripts (#675)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
MoandLucas Nogueira authored and GitHub committed 2023-10-22 10:09:40 -03:00
1 parent 5c137365c6
commit beb6b139eb
14 files changed
+112 -66

No files matched your search

+2 -14
View File
@@ -3,19 +3,7 @@
// SPDX-License-Identifier: MIT
import { invoke } from "@tauri-apps/api/primitives";
interface WindowDef {
label: string;
}
declare global {
interface Window {
__TAURI_METADATA__: {
__windows: WindowDef[];
__currentWindow: WindowDef;
};
}
}
import { getCurrent } from "@tauri-apps/api/window";
export enum StateFlags {
SIZE = 1 << 0,
@@ -50,7 +38,7 @@ async function restoreState(label: string, flags: StateFlags): Promise<void> {
* Restore the state for the current window from disk.
*/
async function restoreStateCurrent(flags: StateFlags): Promise<void> {
return restoreState(window.__TAURI_METADATA__.__currentWindow.label, flags);
return restoreState(getCurrent().label, flags);
}
export { restoreState, restoreStateCurrent, saveWindowState };
+1 -1
View File
@@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_WINDOWSTATE__=function(e){"use strict";var t=Object.defineProperty,n=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},r=(e,t,r)=>(n(e,t,"read from private field"),r?r.call(e):t.get(e));function a(e,t=!1){return window.__TAURI_INTERNALS__.transformCallback(e,t)}((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})({},{Channel:()=>s,PluginListener:()=>o,addPluginListener:()=>l,convertFileSrc:()=>u,invoke:()=>c,transformCallback:()=>a});var i,s=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)})(this,i,(()=>{})),this.id=a((e=>{r(this,i).call(this,e)}))}set onmessage(e){var t,r,a,s;a=e,n(t=this,r=i,"write to private field"),s?s.call(t,a):r.set(t,a)}get onmessage(){return r(this,i)}toJSON(){return`__CHANNEL__:${this.id}`}};i=new WeakMap;var _,o=class{constructor(e,t,n){this.plugin=e,this.event=t,this.channelId=n}async unregister(){return c(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function l(e,t,n){let r=new s;return r.onmessage=n,c(`plugin:${e}|register_listener`,{event:t,handler:r}).then((()=>new o(e,t,r.id)))}async function c(e,t={},n){return window.__TAURI_INTERNALS__.invoke(e,t,n)}function u(e,t="asset"){return window.__TAURI_INTERNALS__.convertFileSrc(e,t)}async function I(e,t){return c("plugin:window-state|restore_state",{label:e,flags:t})}return e.StateFlags=void 0,(_=e.StateFlags||(e.StateFlags={}))[_.SIZE=1]="SIZE",_[_.POSITION=2]="POSITION",_[_.MAXIMIZED=4]="MAXIMIZED",_[_.VISIBLE=8]="VISIBLE",_[_.DECORATIONS=16]="DECORATIONS",_[_.FULLSCREEN=32]="FULLSCREEN",_[_.ALL=63]="ALL",e.restoreState=I,e.restoreStateCurrent=async function(e){return I(window.__TAURI_METADATA__.__currentWindow.label,e)},e.saveWindowState=async function(e){return c("plugin:window-state|save_window_state",{flags:e})},e}({});Object.defineProperty(window.__TAURI__,"windowState",{value:__TAURI_WINDOWSTATE__})}
if("__TAURI__"in window){var __TAURI_WINDOWSTATE__=function(e){"use strict";var t=Object.defineProperty,i=(e,i)=>{for(var n in i)t(e,n,{get:i[n],enumerable:!0})},n=(e,t,i)=>{if(!t.has(e))throw TypeError("Cannot "+i)},a=(e,t,i)=>(n(e,t,"read from private field"),i?i.call(e):t.get(e));function l(e,t=!1){return window.__TAURI_INTERNALS__.transformCallback(e,t)}i({},{Channel:()=>r,PluginListener:()=>o,addPluginListener:()=>u,convertFileSrc:()=>h,invoke:()=>c,transformCallback:()=>l});var s,r=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,t,i)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,i)})(this,s,(()=>{})),this.id=l((e=>{a(this,s).call(this,e)}))}set onmessage(e){((e,t,i,a)=>{n(e,t,"write to private field"),a?a.call(e,i):t.set(e,i)})(this,s,e)}get onmessage(){return a(this,s)}toJSON(){return`__CHANNEL__:${this.id}`}};s=new WeakMap;var o=class{constructor(e,t,i){this.plugin=e,this.event=t,this.channelId=i}async unregister(){return c(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function u(e,t,i){let n=new r;return n.onmessage=i,c(`plugin:${e}|register_listener`,{event:t,handler:n}).then((()=>new o(e,t,n.id)))}async function c(e,t={},i){return window.__TAURI_INTERNALS__.invoke(e,t,i)}function h(e,t="asset"){return window.__TAURI_INTERNALS__.convertFileSrc(e,t)}i({},{LogicalPosition:()=>b,LogicalSize:()=>d,PhysicalPosition:()=>p,PhysicalSize:()=>w});var d=class{constructor(e,t){this.type="Logical",this.width=e,this.height=t}},w=class{constructor(e,t){this.type="Physical",this.width=e,this.height=t}toLogical(e){return new d(this.width/e,this.height/e)}},b=class{constructor(e,t){this.type="Logical",this.x=e,this.y=t}},p=class{constructor(e,t){this.type="Physical",this.x=e,this.y=t}toLogical(e){return new b(this.x/e,this.y/e)}};i({},{TauriEvent:()=>g,emit:()=>v,listen:()=>_,once:()=>m});var g=(e=>(e.WINDOW_RESIZED="tauri://resize",e.WINDOW_MOVED="tauri://move",e.WINDOW_CLOSE_REQUESTED="tauri://close-requested",e.WINDOW_CREATED="tauri://window-created",e.WINDOW_DESTROYED="tauri://destroyed",e.WINDOW_FOCUS="tauri://focus",e.WINDOW_BLUR="tauri://blur",e.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",e.WINDOW_THEME_CHANGED="tauri://theme-changed",e.WINDOW_FILE_DROP="tauri://file-drop",e.WINDOW_FILE_DROP_HOVER="tauri://file-drop-hover",e.WINDOW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled",e.MENU="tauri://menu",e))(g||{});async function y(e,t){await c("plugin:event|unlisten",{event:e,eventId:t})}async function _(e,t,i){return c("plugin:event|listen",{event:e,windowLabel:i?.target,handler:l(t)}).then((t=>async()=>y(e,t)))}async function m(e,t,i){return _(e,(i=>{t(i),y(e,i.id).catch((()=>{}))}),i)}async function v(e,t,i){await c("plugin:event|emit",{event:e,windowLabel:i?.target,payload:t})}i({},{CloseRequestedEvent:()=>I,Effect:()=>C,EffectState:()=>N,LogicalPosition:()=>b,LogicalSize:()=>d,PhysicalPosition:()=>p,PhysicalSize:()=>w,ProgressBarStatus:()=>S,UserAttentionType:()=>E,Window:()=>T,availableMonitors:()=>M,currentMonitor:()=>k,getAll:()=>z,getCurrent:()=>L,primaryMonitor:()=>x});var f,E=((f=E||{})[f.Critical=1]="Critical",f[f.Informational=2]="Informational",f),I=class{constructor(e){this._preventDefault=!1,this.event=e.event,this.windowLabel=e.windowLabel,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}},S=(e=>(e.None="none",e.Normal="normal",e.Indeterminate="indeterminate",e.Paused="paused",e.Error="error",e))(S||{});function L(){return new T(window.__TAURI_INTERNALS__.metadata.currentWindow.label,{skip:!0})}function z(){return window.__TAURI_INTERNALS__.metadata.windows.map((e=>new T(e.label,{skip:!0})))}var P,D,A=["tauri://created","tauri://error"],T=class e{constructor(e,t={}){this.label=e,this.listeners=Object.create(null),t?.skip||c("plugin:window|create",{options:{...t,label:e}}).then((async()=>this.emit("tauri://created"))).catch((async e=>this.emit("tauri://error",e)))}static getByLabel(t){return z().some((e=>e.label===t))?new e(t,{skip:!0}):null}static getCurrent(){return L()}static getAll(){return z()}static async getFocusedWindow(){for(let e of z())if(await e.isFocused())return e;return null}async listen(e,t){return this._handleTauriEvent(e,t)?Promise.resolve((()=>{let i=this.listeners[e];i.splice(i.indexOf(t),1)})):_(e,t,{target:this.label})}async once(e,t){return this._handleTauriEvent(e,t)?Promise.resolve((()=>{let i=this.listeners[e];i.splice(i.indexOf(t),1)})):m(e,t,{target:this.label})}async emit(e,t){if(A.includes(e)){for(let i of this.listeners[e]||[])i({event:e,id:-1,windowLabel:this.label,payload:t});return Promise.resolve()}return v(e,t,{target:this.label})}_handleTauriEvent(e,t){return!!A.includes(e)&&(e in this.listeners?this.listeners[e].push(t):this.listeners[e]=[t],!0)}async scaleFactor(){return c("plugin:window|scale_factor",{label:this.label})}async innerPosition(){return c("plugin:window|iLine truncated