From 3245d14b9eb256a5c5675c7030bac7082855df47 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Mon, 8 May 2023 06:29:36 -0700 Subject: [PATCH] refactor(core): remove `app` module (#6895) --- .changes/move-app.md | 6 ++ core/tauri/scripts/bundle.global.js | 6 +- core/tauri/src/endpoints.rs | 8 -- core/tauri/src/endpoints/app.rs | 58 ------------ core/tauri/src/lib.rs | 3 + core/tauri/src/path/mod.rs | 4 +- core/tauri/src/scope/ipc.rs | 80 ++++++++-------- examples/api/src/views/App.svelte | 33 ------- examples/api/src/views/Welcome.svelte | 6 -- tooling/api/docs/js-api.json | 2 +- tooling/api/src/app.ts | 129 -------------------------- tooling/api/src/index.ts | 3 +- 12 files changed, 53 insertions(+), 285 deletions(-) create mode 100644 .changes/move-app.md delete mode 100644 core/tauri/src/endpoints/app.rs delete mode 100644 examples/api/src/views/App.svelte delete mode 100644 tooling/api/src/app.ts diff --git a/.changes/move-app.md b/.changes/move-app.md new file mode 100644 index 00000000000..8bc5d10af4c --- /dev/null +++ b/.changes/move-app.md @@ -0,0 +1,6 @@ +--- +"api": patch +"tauri": patch +--- + +Moved the `app` feature to its own plugin in the plugins-workspace repository. diff --git a/core/tauri/scripts/bundle.global.js b/core/tauri/scripts/bundle.global.js index 03f133263ea..aee96c49497 100644 --- a/core/tauri/scripts/bundle.global.js +++ b/core/tauri/scripts/bundle.global.js @@ -1,5 +1,5 @@ -"use strict";var __TAURI_IIFE__=(()=>{var A=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var d=(t,e)=>{for(var n in e)A(t,n,{get:e[n],enumerable:!0})},J=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of Z(e))!Y.call(t,l)&&l!==n&&A(t,l,{get:()=>e[l],enumerable:!(o=Q(e,l))||o.enumerable});return t};var X=t=>J(A({},"__esModule",{value:!0}),t);var et={};d(et,{app:()=>C,event:()=>x,invoke:()=>Be,os:()=>N,path:()=>L,process:()=>O,tauri:()=>T,updater:()=>I,window:()=>z});var C={};d(C,{getName:()=>ne,getTauriVersion:()=>ie,getVersion:()=>te,hide:()=>re,show:()=>ae});var T={};d(T,{convertFileSrc:()=>ee,invoke:()=>r,transformCallback:()=>g});function B(){return window.crypto.getRandomValues(new Uint32Array(1))[0]}function g(t,e=!1){let n=B(),o=`_${n}`;return Object.defineProperty(window,o,{value:l=>(e&&Reflect.deleteProperty(window,o),t?.(l)),writable:!1,configurable:!0}),n}async function r(t,e={}){return new Promise((n,o)=>{let l=g(u=>{n(u),Reflect.deleteProperty(window,`_${s}`)},!0),s=g(u=>{o(u),Reflect.deleteProperty(window,`_${l}`)},!0);window.__TAURI_IPC__({cmd:t,callback:l,error:s,...e})})}function ee(t,e="asset"){let n=encodeURIComponent(t);return navigator.userAgent.includes("Windows")?`https://${e}.localhost/${n}`:`${e}://localhost/${n}`}async function i(t){return r("tauri",t)}async function te(){return i({__tauriModule:"App",message:{cmd:"getAppVersion"}})}async function ne(){return i({__tauriModule:"App",message:{cmd:"getAppName"}})}async function ie(){return i({__tauriModule:"App",message:{cmd:"getTauriVersion"}})}async function ae(){return i({__tauriModule:"App",message:{cmd:"show"}})}async function re(){return i({__tauriModule:"App",message:{cmd:"hide"}})}var x={};d(x,{TauriEvent:()=>w,emit:()=>f,listen:()=>S,once:()=>U});async function V(t,e){return i({__tauriModule:"Event",message:{cmd:"unlisten",event:t,eventId:e}})}async function _(t,e,n){await i({__tauriModule:"Event",message:{cmd:"emit",event:t,windowLabel:e,payload:n}})}async function h(t,e,n){return i({__tauriModule:"Event",message:{cmd:"listen",event:t,windowLabel:e,handler:g(n)}}).then(o=>async()=>V(t,o))}async function P(t,e,n){return h(t,e,o=>{n(o),V(t,o.id).catch(()=>{})})}var w=(c=>(c.WINDOW_RESIZED="tauri://resize",c.WINDOW_MOVED="tauri://move",c.WINDOW_CLOSE_REQUESTED="tauri://close-requested",c.WINDOW_CREATED="tauri://window-created",c.WINDOW_DESTROYED="tauri://destroyed",c.WINDOW_FOCUS="tauri://focus",c.WINDOW_BLUR="tauri://blur",c.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",c.WINDOW_THEME_CHANGED="tauri://theme-changed",c.WINDOW_FILE_DROP="tauri://file-drop",c.WINDOW_FILE_DROP_HOVER="tauri://file-drop-hover",c.WINDOW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled",c.MENU="tauri://menu",c.CHECK_UPDATE="tauri://update",c.UPDATE_AVAILABLE="tauri://update-available",c.INSTALL_UPDATE="tauri://update-install",c.STATUS_UPDATE="tauri://update-status",c.DOWNLOAD_PROGRESS="tauri://update-download-progress",c))(w||{});async function S(t,e){return h(t,null,e)}async function U(t,e){return P(t,null,e)}async function f(t,e){return _(t,void 0,e)}var L={};d(L,{BaseDirectory:()=>H,appCacheDir:()=>ce,appConfigDir:()=>se,appDataDir:()=>le,appLocalDataDir:()=>ue,appLogDir:()=>Ce,audioDir:()=>de,basename:()=>Fe,cacheDir:()=>me,configDir:()=>pe,dataDir:()=>ye,delimiter:()=>Ue,desktopDir:()=>ge,dirname:()=>Re,documentDir:()=>he,downloadDir:()=>be,executableDir:()=>_e,extname:()=>Ie,fontDir:()=>Pe,homeDir:()=>we,isAbsolute:()=>ke,join:()=>Oe,localDataDir:()=>fe,normalize:()=>Le,pictureDir:()=>ve,publicDir:()=>We,resolve:()=>xe,resolveResource:()=>Ee,resourceDir:()=>Me,runtimeDir:()=>De,sep:()=>Se,templateDir:()=>Ae,videoDir:()=>Te});function b(){return navigator.appVersion.includes("Win")}var H=(a=>(a[a.Audio=1]="Audio",a[a.Cache=2]="Cache",a[a.Config=3]="Config",a[a.Data=4]="Data",a[a.LocalData=5]="LocalData",a[a.Document=6]="Document",a[a.Download=7]="Download",a[a.Picture=8]="Picture",a[a.Public=9]="Public",a[a.Video=10]="Video",a[a.Resource=11]="Resource",a[a.Temp=12]="Temp",a[a.AppConfig=13]="AppConfig",a[a.AppData=14]="AppData",a[a.AppLocalData=15]="AppLocalData",a[a.AppCache=16]="AppCache",a[a.AppLog=17]="AppLog",a[a.Desktop=18]="Desktop",a[a.Executable=19]="Executable",a[a.Font=20]="Font",a[a.Home=21]="Home",a[a.Runtime=22]="Runtime",a[a.Template=23]="Template",a))(H||{});async function se(){return r("plugin:path|resolve_directory",{directory:13})}async function le(){return r("plugin:path|resolve_directory",{directory:14})}async function ue(){return r("plugin:path|resolve_directory",{directory:15})}async function ce(){return r("plugin:path|resolve_directory",{directory:16})}async function de(){return r("plugin:path|resolve_directory",{directory:1})}async function me(){return r("plugin:path|resolve_directory",{directory:2})}async function pe(){return r("plugin:path|resolve_directory",{directory:3})}async function ye(){return r("plugin:path|resolve_directory",{directory:4})}async function ge(){return r("plugin:path|resolve_directory",{directory:18})}async function he(){return r("plugin:path|resolve_directory",{directory:6})}async function be(){return r("plugin:path|resolve_directory",{directory:7})}async function _e(){return r("plugin:path|resolve_directory",{directory:19})}async function Pe(){return r("plugin:path|resolve_directory",{directory:20})}async function we(){return r("plugin:path|resolve_directory",{directory:21})}async function fe(){return r("plugin:path|resolve_directory",{directory:5})}async function ve(){return r("plugin:path|resolve_directory",{directory:8})}async function We(){return r("plugin:path|resolve_directory",{directory:9})}async function Me(){return r("plugin:path|resolve_directory",{directory:11})}async function Ee(t){return r("plugin:path|resolve_directory",{directory:11,path:t})}async function De(){return r("plugin:path|resolve_directory",{directory:22})}async function Ae(){return r("plugin:path|resolve_directory",{directory:23})}async function Te(){return r("plugin:path|resolve_directory",{directory:10})}async function Ce(){return r("plugin:path|resolve_directory",{directory:17})}var Se=b()?"\\":"/",Ue=b()?";":":";async function xe(...t){return r("plugin:path|resolve",{paths:t})}async function Le(t){return r("plugin:path|normalize",{path:t})}async function Oe(...t){return r("plugin:path|join",{paths:t})}async function Re(t){return r("plugin:path|dirname",{path:t})}async function Ie(t){return r("plugin:path|extname",{path:t})}async function Fe(t,e){return r("plugin:path|basename",{path:t,ext:e})}async function ke(t){return r("plugin:path|isAbsolute",{path:t})}var O={};d(O,{exit:()=>ze,relaunch:()=>Ne});async function ze(t=0){return i({__tauriModule:"Process",message:{cmd:"exit",exitCode:t}})}async function Ne(){return i({__tauriModule:"Process",message:{cmd:"relaunch"}})}var I={};d(I,{checkUpdate:()=>He,installUpdate:()=>Ve,onUpdaterEvent:()=>R});async function R(t){return S("tauri://update-status",e=>{t(e?.payload)})}async function Ve(){let t;function e(){t&&t(),t=void 0}return new Promise((n,o)=>{function l(s){if(s.error){e(),o(s.error);return}s.status==="DONE"&&(e(),n())}R(l).then(s=>{t=s}).catch(s=>{throw e(),s}),f("tauri://update-install").catch(s=>{throw e(),s})})}async function He(){let t;function e(){t&&t(),t=void 0}return new Promise((n,o)=>{function l(u){e(),n({manifest:u,shouldUpdate:!0})}function s(u){if(u.error){e(),o(u.error);return}u.status==="UPTODATE"&&(e(),n({shouldUpdate:!1}))}U("tauri://update-available",u=>{l(u?.payload)}).catch(u=>{throw e(),u}),R(s).then(u=>{t=u}).catch(u=>{throw e(),u}),f("tauri://update").catch(u=>{throw e(),u})})}var z={};d(z,{CloseRequestedEvent:()=>D,LogicalPosition:()=>W,LogicalSize:()=>v,PhysicalPosition:()=>y,PhysicalSize:()=>p,UserAttentionType:()=>$,WebviewWindow:()=>m,WebviewWindowHandle:()=>M,WindowManager:()=>E,appWindow:()=>F,availableMonitors:()=>qe,currentMonitor:()=>$e,getAll:()=>j,getCurrent:()=>Ge,primaryMonitor:()=>je});var v=class{constructor(e,n){this.type="Logical";this.width=e,this.height=n}},p=class{constructor(e,n){this.type="Physical";this.width=e,this.height=n}toLogical(e){return new v(this.width/e,this.height/e)}},W=class{constructor(e,n){this.type="Logical";this.x=e,this.y=n}},y=class{constructor(e,n){this.type="Physical";this.x=e,this.y=n}toLogical(e){return new W(this.x/e,this.y/e)}},$=(n=>(n[n.Critical=1]="Critical",n[n.Informational=2]="Informational",n))($||{});function Ge(){return new m(window.__TAURI_METADATA__.__currentWindow.label,{skip:!0})}function j(){return window.__TAURI_METADATA__.__windows.map(t=>new m(t.label,{skip:!0}))}var G=["tauri://created","tauri://error"],M=class{constructor(e){this.label=e,this.listeners=Object.create(null)}async listen(e,n){return this._handleTauriEvent(e,n)?Promise.resolve(()=>{let o=this.listeners[e];o.splice(o.indexOf(n),1)}):h(e,this.label,n)}async once(e,n){return this._handleTauriEvent(e,n)?Promise.resolve(()=>{let o=this.listeners[e];o.splice(o.indexOf(n),1)}):P(e,this.label,n)}async emit(e,n){if(G.includes(e)){for(let o of this.listeners[e]||[])o({event:e,id:-1,windowLabel:this.label,payload:n});return Promise.resolve()}return _(e,this.label,n)}_handleTauriEvent(e,n){return G.includes(e)?(e in this.listeners?this.listeners[e].push(n):this.listeners[e]=[n],!0):!1}},E=class extends M{async scaleFactor(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"scaleFactor"}}}})}async innerPosition(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"innerPosition"}}}}).then(({x:e,y:n})=>new y(e,n))}async outerPosition(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"outerPosition"}}}}).then(({x:e,y:n})=>new y(e,n))}async innerSize(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"innerSize"}}}}).then(({width:e,height:n})=>new p(e,n))}async outerSize(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"outerSize"}}}}).then(({width:e,height:n})=>new p(e,n))}async isFullscreen(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isFullscreen"}}}})}async isMinimized(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isMinimized"}}}})}async isMaximized(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isMaximized"}}}})}async isDecorated(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isDecorated"}}}})}async isResizable(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isResizable"}}}})}async isVisible(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isVisible"}}}})}async title(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"title"}}}})}async theme(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"theme"}}}})}async center(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"center"}}}})}async requestUserAttention(e){let n=null;return e&&(e===1?n={type:"Critical"}:n={type:"Informational"}),i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"requestUserAttention",payload:n}}}})}async setResizable(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setResizable",payload:e}}}})}async setTitle(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setTitle",payload:e}}}})}async maximize(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"maximize"}}}})}async unmaximize(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"unmaximize"}}}})}async toggleMaximize(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"toggleMaximize"}}}})}async minimize(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"minimize"}}}})}async unminimize(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"unminimize"}}}})}async show(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"show"}}}})}async hide(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"hide"}}}})}async close(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"close"}}}})}async setDecorations(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setDecorations",payload:e}}}})}async setShadow(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setShadow",payload:e}}}})}async setAlwaysOnTop(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setAlwaysOnTop",payload:e}}}})}async setContentProtected(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setContentProtected",payload:e}}}})}async setSize(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setSize",payload:{type:e.type,data:{width:e.width,height:e.height}}}}}})}async setMinSize(e){if(e&&e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setMinSize",payload:e?{type:e.type,data:{width:e.width,height:e.height}}:null}}}})}async setMaxSize(e){if(e&&e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setMaxSize",payload:e?{type:e.type,data:{width:e.width,height:e.height}}:null}}}})}async setPosition(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setPosition",payload:{type:e.type,data:{x:e.x,y:e.y}}}}}})}async setFullscreen(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setFullscreen",payload:e}}}})}async setFocus(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setFocus"}}}})}async setIcon(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setIcon",payload:{icon:typeof e=="string"?e:Array.from(e)}}}}})}async setSkipTaskbar(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setSkipTaskbar",payload:e}}}})}async setCursorGrab(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setCursorGrab",payload:e}}}})}async setCursorVisible(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setCursorVisible",payload:e}}}})}async setCursorIcon(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setCursorIcon",payload:e}}}})}async setCursorPosition(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setCursorPosition",payload:{type:e.type,data:{x:e.x,y:e.y}}}}}})}async setIgnoreCursorEvents(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setIgnoreCursorEvents",payload:e}}}})}async startDragging(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"startDragging"}}}})}async onResized(e){return this.listen("tauri://resize",n=>{n.payload=K(n.payload),e(n)})}async onMoved(e){return this.listen("tauri://move",n=>{n.payload=q(n.payload),e(n)})}async onCloseRequested(e){return this.listen("tauri://close-requested",n=>{let o=new D(n);Promise.resolve(e(o)).then(()=>{if(!o.isPreventDefault())return this.close()})})}async onFocusChanged(e){let n=await this.listen("tauri://focus",l=>{e({...l,payload:!0})}),o=await this.listen("tauri://blur",l=>{e({...l,payload:!1})});return()=>{n(),o()}}async onScaleChanged(e){return this.listen("tauri://scale-change",e)}async onMenuClicked(e){return this.listen("tauri://menu",e)}async onFileDropEvent(e){let n=await this.listen("tauri://file-drop",s=>{e({...s,payload:{type:"drop",paths:s.payload}})}),o=await this.listen("tauri://file-drop-hover",s=>{e({...s,payload:{type:"hover",paths:s.payload}})}),l=await this.listen("tauri://file-drop-cancelled",s=>{e({...s,payload:{type:"cancel"}})});return()=>{n(),o(),l()}}async onThemeChanged(e){return this.listen("tauri://theme-changed",e)}},D=class{constructor(e){this._preventDefault=!1;this.event=e.event,this.windowLabel=e.windowLabel,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}},m=class extends E{constructor(e,n={}){super(e),n?.skip||i({__tauriModule:"Window",message:{cmd:"createWebview",data:{options:{label:e,...n}}}}).then(async()=>this.emit("tauri://created")).catch(async o=>this.emit("tauri://error",o))}static getByLabel(e){return j().some(n=>n.label===e)?new m(e,{skip:!0}):null}},F;"__TAURI_METADATA__"in window?F=new m(window.__TAURI_METADATA__.__currentWindow.label,{skip:!0}):(console.warn(`Could not find "window.__TAURI_METADATA__". The "appWindow" value will reference the "main" window label. -Note that this is not an issue if running this frontend on a browser instead of a Tauri window.`),F=new m("main",{skip:!0}));function k(t){return t===null?null:{name:t.name,scaleFactor:t.scaleFactor,position:q(t.position),size:K(t.size)}}function q(t){return new y(t.x,t.y)}function K(t){return new p(t.width,t.height)}async function $e(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{cmd:{type:"currentMonitor"}}}}).then(k)}async function je(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{cmd:{type:"primaryMonitor"}}}}).then(k)}async function qe(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{cmd:{type:"availableMonitors"}}}}).then(t=>t.map(k))}var N={};d(N,{EOL:()=>Ke,arch:()=>Je,platform:()=>Qe,tempdir:()=>Xe,type:()=>Ye,version:()=>Ze});var Ke=b()?`\r +"use strict";var __TAURI_IIFE__=(()=>{var T=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var Z=Object.prototype.hasOwnProperty;var m=(t,e)=>{for(var n in e)T(t,n,{get:e[n],enumerable:!0})},Y=(t,e,n,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of Q(e))!Z.call(t,l)&&l!==n&&T(t,l,{get:()=>e[l],enumerable:!(o=K(e,l))||o.enumerable});return t};var J=t=>Y(T({},"__esModule",{value:!0}),t);var Qe={};m(Qe,{event:()=>U,invoke:()=>Ke,os:()=>k,path:()=>x,process:()=>L,tauri:()=>C,updater:()=>R,window:()=>z});var U={};m(U,{TauriEvent:()=>w,emit:()=>f,listen:()=>A,once:()=>S});var C={};m(C,{convertFileSrc:()=>B,invoke:()=>r,transformCallback:()=>g});function X(){return window.crypto.getRandomValues(new Uint32Array(1))[0]}function g(t,e=!1){let n=X(),o=`_${n}`;return Object.defineProperty(window,o,{value:l=>(e&&Reflect.deleteProperty(window,o),t?.(l)),writable:!1,configurable:!0}),n}async function r(t,e={}){return new Promise((n,o)=>{let l=g(u=>{n(u),Reflect.deleteProperty(window,`_${s}`)},!0),s=g(u=>{o(u),Reflect.deleteProperty(window,`_${l}`)},!0);window.__TAURI_IPC__({cmd:t,callback:l,error:s,...e})})}function B(t,e="asset"){let n=encodeURIComponent(t);return navigator.userAgent.includes("Windows")?`https://${e}.localhost/${n}`:`${e}://localhost/${n}`}async function i(t){return r("tauri",t)}async function N(t,e){return i({__tauriModule:"Event",message:{cmd:"unlisten",event:t,eventId:e}})}async function _(t,e,n){await i({__tauriModule:"Event",message:{cmd:"emit",event:t,windowLabel:e,payload:n}})}async function h(t,e,n){return i({__tauriModule:"Event",message:{cmd:"listen",event:t,windowLabel:e,handler:g(n)}}).then(o=>async()=>N(t,o))}async function P(t,e,n){return h(t,e,o=>{n(o),N(t,o.id).catch(()=>{})})}var w=(c=>(c.WINDOW_RESIZED="tauri://resize",c.WINDOW_MOVED="tauri://move",c.WINDOW_CLOSE_REQUESTED="tauri://close-requested",c.WINDOW_CREATED="tauri://window-created",c.WINDOW_DESTROYED="tauri://destroyed",c.WINDOW_FOCUS="tauri://focus",c.WINDOW_BLUR="tauri://blur",c.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",c.WINDOW_THEME_CHANGED="tauri://theme-changed",c.WINDOW_FILE_DROP="tauri://file-drop",c.WINDOW_FILE_DROP_HOVER="tauri://file-drop-hover",c.WINDOW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled",c.MENU="tauri://menu",c.CHECK_UPDATE="tauri://update",c.UPDATE_AVAILABLE="tauri://update-available",c.INSTALL_UPDATE="tauri://update-install",c.STATUS_UPDATE="tauri://update-status",c.DOWNLOAD_PROGRESS="tauri://update-download-progress",c))(w||{});async function A(t,e){return h(t,null,e)}async function S(t,e){return P(t,null,e)}async function f(t,e){return _(t,void 0,e)}var x={};m(x,{BaseDirectory:()=>V,appCacheDir:()=>ae,appConfigDir:()=>te,appDataDir:()=>ne,appLocalDataDir:()=>ie,appLogDir:()=>We,audioDir:()=>re,basename:()=>Ue,cacheDir:()=>oe,configDir:()=>se,dataDir:()=>le,delimiter:()=>Ee,desktopDir:()=>ue,dirname:()=>Ae,documentDir:()=>ce,downloadDir:()=>de,executableDir:()=>me,extname:()=>Se,fontDir:()=>pe,homeDir:()=>ye,isAbsolute:()=>xe,join:()=>Ce,localDataDir:()=>ge,normalize:()=>Te,pictureDir:()=>he,publicDir:()=>be,resolve:()=>De,resolveResource:()=>Pe,resourceDir:()=>_e,runtimeDir:()=>we,sep:()=>Me,templateDir:()=>fe,videoDir:()=>ve});function b(){return navigator.appVersion.includes("Win")}var V=(a=>(a[a.Audio=1]="Audio",a[a.Cache=2]="Cache",a[a.Config=3]="Config",a[a.Data=4]="Data",a[a.LocalData=5]="LocalData",a[a.Document=6]="Document",a[a.Download=7]="Download",a[a.Picture=8]="Picture",a[a.Public=9]="Public",a[a.Video=10]="Video",a[a.Resource=11]="Resource",a[a.Temp=12]="Temp",a[a.AppConfig=13]="AppConfig",a[a.AppData=14]="AppData",a[a.AppLocalData=15]="AppLocalData",a[a.AppCache=16]="AppCache",a[a.AppLog=17]="AppLog",a[a.Desktop=18]="Desktop",a[a.Executable=19]="Executable",a[a.Font=20]="Font",a[a.Home=21]="Home",a[a.Runtime=22]="Runtime",a[a.Template=23]="Template",a))(V||{});async function te(){return r("plugin:path|resolve_directory",{directory:13})}async function ne(){return r("plugin:path|resolve_directory",{directory:14})}async function ie(){return r("plugin:path|resolve_directory",{directory:15})}async function ae(){return r("plugin:path|resolve_directory",{directory:16})}async function re(){return r("plugin:path|resolve_directory",{directory:1})}async function oe(){return r("plugin:path|resolve_directory",{directory:2})}async function se(){return r("plugin:path|resolve_directory",{directory:3})}async function le(){return r("plugin:path|resolve_directory",{directory:4})}async function ue(){return r("plugin:path|resolve_directory",{directory:18})}async function ce(){return r("plugin:path|resolve_directory",{directory:6})}async function de(){return r("plugin:path|resolve_directory",{directory:7})}async function me(){return r("plugin:path|resolve_directory",{directory:19})}async function pe(){return r("plugin:path|resolve_directory",{directory:20})}async function ye(){return r("plugin:path|resolve_directory",{directory:21})}async function ge(){return r("plugin:path|resolve_directory",{directory:5})}async function he(){return r("plugin:path|resolve_directory",{directory:8})}async function be(){return r("plugin:path|resolve_directory",{directory:9})}async function _e(){return r("plugin:path|resolve_directory",{directory:11})}async function Pe(t){return r("plugin:path|resolve_directory",{directory:11,path:t})}async function we(){return r("plugin:path|resolve_directory",{directory:22})}async function fe(){return r("plugin:path|resolve_directory",{directory:23})}async function ve(){return r("plugin:path|resolve_directory",{directory:10})}async function We(){return r("plugin:path|resolve_directory",{directory:17})}var Me=b()?"\\":"/",Ee=b()?";":":";async function De(...t){return r("plugin:path|resolve",{paths:t})}async function Te(t){return r("plugin:path|normalize",{path:t})}async function Ce(...t){return r("plugin:path|join",{paths:t})}async function Ae(t){return r("plugin:path|dirname",{path:t})}async function Se(t){return r("plugin:path|extname",{path:t})}async function Ue(t,e){return r("plugin:path|basename",{path:t,ext:e})}async function xe(t){return r("plugin:path|isAbsolute",{path:t})}var L={};m(L,{exit:()=>Le,relaunch:()=>Oe});async function Le(t=0){return i({__tauriModule:"Process",message:{cmd:"exit",exitCode:t}})}async function Oe(){return i({__tauriModule:"Process",message:{cmd:"relaunch"}})}var R={};m(R,{checkUpdate:()=>Ie,installUpdate:()=>Re,onUpdaterEvent:()=>O});async function O(t){return A("tauri://update-status",e=>{t(e?.payload)})}async function Re(){let t;function e(){t&&t(),t=void 0}return new Promise((n,o)=>{function l(s){if(s.error){e(),o(s.error);return}s.status==="DONE"&&(e(),n())}O(l).then(s=>{t=s}).catch(s=>{throw e(),s}),f("tauri://update-install").catch(s=>{throw e(),s})})}async function Ie(){let t;function e(){t&&t(),t=void 0}return new Promise((n,o)=>{function l(u){e(),n({manifest:u,shouldUpdate:!0})}function s(u){if(u.error){e(),o(u.error);return}u.status==="UPTODATE"&&(e(),n({shouldUpdate:!1}))}S("tauri://update-available",u=>{l(u?.payload)}).catch(u=>{throw e(),u}),O(s).then(u=>{t=u}).catch(u=>{throw e(),u}),f("tauri://update").catch(u=>{throw e(),u})})}var z={};m(z,{CloseRequestedEvent:()=>D,LogicalPosition:()=>W,LogicalSize:()=>v,PhysicalPosition:()=>y,PhysicalSize:()=>p,UserAttentionType:()=>G,WebviewWindow:()=>d,WebviewWindowHandle:()=>M,WindowManager:()=>E,appWindow:()=>I,availableMonitors:()=>Ne,currentMonitor:()=>ze,getAll:()=>$,getCurrent:()=>Fe,primaryMonitor:()=>ke});var v=class{constructor(e,n){this.type="Logical";this.width=e,this.height=n}},p=class{constructor(e,n){this.type="Physical";this.width=e,this.height=n}toLogical(e){return new v(this.width/e,this.height/e)}},W=class{constructor(e,n){this.type="Logical";this.x=e,this.y=n}},y=class{constructor(e,n){this.type="Physical";this.x=e,this.y=n}toLogical(e){return new W(this.x/e,this.y/e)}},G=(n=>(n[n.Critical=1]="Critical",n[n.Informational=2]="Informational",n))(G||{});function Fe(){return new d(window.__TAURI_METADATA__.__currentWindow.label,{skip:!0})}function $(){return window.__TAURI_METADATA__.__windows.map(t=>new d(t.label,{skip:!0}))}var H=["tauri://created","tauri://error"],M=class{constructor(e){this.label=e,this.listeners=Object.create(null)}async listen(e,n){return this._handleTauriEvent(e,n)?Promise.resolve(()=>{let o=this.listeners[e];o.splice(o.indexOf(n),1)}):h(e,this.label,n)}async once(e,n){return this._handleTauriEvent(e,n)?Promise.resolve(()=>{let o=this.listeners[e];o.splice(o.indexOf(n),1)}):P(e,this.label,n)}async emit(e,n){if(H.includes(e)){for(let o of this.listeners[e]||[])o({event:e,id:-1,windowLabel:this.label,payload:n});return Promise.resolve()}return _(e,this.label,n)}_handleTauriEvent(e,n){return H.includes(e)?(e in this.listeners?this.listeners[e].push(n):this.listeners[e]=[n],!0):!1}},E=class extends M{async scaleFactor(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"scaleFactor"}}}})}async innerPosition(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"innerPosition"}}}}).then(({x:e,y:n})=>new y(e,n))}async outerPosition(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"outerPosition"}}}}).then(({x:e,y:n})=>new y(e,n))}async innerSize(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"innerSize"}}}}).then(({width:e,height:n})=>new p(e,n))}async outerSize(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"outerSize"}}}}).then(({width:e,height:n})=>new p(e,n))}async isFullscreen(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isFullscreen"}}}})}async isMinimized(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isMinimized"}}}})}async isMaximized(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isMaximized"}}}})}async isDecorated(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isDecorated"}}}})}async isResizable(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isResizable"}}}})}async isVisible(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"isVisible"}}}})}async title(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"title"}}}})}async theme(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"theme"}}}})}async center(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"center"}}}})}async requestUserAttention(e){let n=null;return e&&(e===1?n={type:"Critical"}:n={type:"Informational"}),i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"requestUserAttention",payload:n}}}})}async setResizable(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setResizable",payload:e}}}})}async setTitle(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setTitle",payload:e}}}})}async maximize(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"maximize"}}}})}async unmaximize(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"unmaximize"}}}})}async toggleMaximize(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"toggleMaximize"}}}})}async minimize(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"minimize"}}}})}async unminimize(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"unminimize"}}}})}async show(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"show"}}}})}async hide(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"hide"}}}})}async close(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"close"}}}})}async setDecorations(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setDecorations",payload:e}}}})}async setShadow(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setShadow",payload:e}}}})}async setAlwaysOnTop(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setAlwaysOnTop",payload:e}}}})}async setContentProtected(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setContentProtected",payload:e}}}})}async setSize(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setSize",payload:{type:e.type,data:{width:e.width,height:e.height}}}}}})}async setMinSize(e){if(e&&e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setMinSize",payload:e?{type:e.type,data:{width:e.width,height:e.height}}:null}}}})}async setMaxSize(e){if(e&&e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setMaxSize",payload:e?{type:e.type,data:{width:e.width,height:e.height}}:null}}}})}async setPosition(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setPosition",payload:{type:e.type,data:{x:e.x,y:e.y}}}}}})}async setFullscreen(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setFullscreen",payload:e}}}})}async setFocus(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setFocus"}}}})}async setIcon(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setIcon",payload:{icon:typeof e=="string"?e:Array.from(e)}}}}})}async setSkipTaskbar(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setSkipTaskbar",payload:e}}}})}async setCursorGrab(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setCursorGrab",payload:e}}}})}async setCursorVisible(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setCursorVisible",payload:e}}}})}async setCursorIcon(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setCursorIcon",payload:e}}}})}async setCursorPosition(e){if(!e||e.type!=="Logical"&&e.type!=="Physical")throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setCursorPosition",payload:{type:e.type,data:{x:e.x,y:e.y}}}}}})}async setIgnoreCursorEvents(e){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"setIgnoreCursorEvents",payload:e}}}})}async startDragging(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{label:this.label,cmd:{type:"startDragging"}}}})}async onResized(e){return this.listen("tauri://resize",n=>{n.payload=q(n.payload),e(n)})}async onMoved(e){return this.listen("tauri://move",n=>{n.payload=j(n.payload),e(n)})}async onCloseRequested(e){return this.listen("tauri://close-requested",n=>{let o=new D(n);Promise.resolve(e(o)).then(()=>{if(!o.isPreventDefault())return this.close()})})}async onFocusChanged(e){let n=await this.listen("tauri://focus",l=>{e({...l,payload:!0})}),o=await this.listen("tauri://blur",l=>{e({...l,payload:!1})});return()=>{n(),o()}}async onScaleChanged(e){return this.listen("tauri://scale-change",e)}async onMenuClicked(e){return this.listen("tauri://menu",e)}async onFileDropEvent(e){let n=await this.listen("tauri://file-drop",s=>{e({...s,payload:{type:"drop",paths:s.payload}})}),o=await this.listen("tauri://file-drop-hover",s=>{e({...s,payload:{type:"hover",paths:s.payload}})}),l=await this.listen("tauri://file-drop-cancelled",s=>{e({...s,payload:{type:"cancel"}})});return()=>{n(),o(),l()}}async onThemeChanged(e){return this.listen("tauri://theme-changed",e)}},D=class{constructor(e){this._preventDefault=!1;this.event=e.event,this.windowLabel=e.windowLabel,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}},d=class extends E{constructor(e,n={}){super(e),n?.skip||i({__tauriModule:"Window",message:{cmd:"createWebview",data:{options:{label:e,...n}}}}).then(async()=>this.emit("tauri://created")).catch(async o=>this.emit("tauri://error",o))}static getByLabel(e){return $().some(n=>n.label===e)?new d(e,{skip:!0}):null}},I;"__TAURI_METADATA__"in window?I=new d(window.__TAURI_METADATA__.__currentWindow.label,{skip:!0}):(console.warn(`Could not find "window.__TAURI_METADATA__". The "appWindow" value will reference the "main" window label. +Note that this is not an issue if running this frontend on a browser instead of a Tauri window.`),I=new d("main",{skip:!0}));function F(t){return t===null?null:{name:t.name,scaleFactor:t.scaleFactor,position:j(t.position),size:q(t.size)}}function j(t){return new y(t.x,t.y)}function q(t){return new p(t.width,t.height)}async function ze(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{cmd:{type:"currentMonitor"}}}}).then(F)}async function ke(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{cmd:{type:"primaryMonitor"}}}}).then(F)}async function Ne(){return i({__tauriModule:"Window",message:{cmd:"manage",data:{cmd:{type:"availableMonitors"}}}}).then(t=>t.map(F))}var k={};m(k,{EOL:()=>Ve,arch:()=>je,platform:()=>He,tempdir:()=>qe,type:()=>$e,version:()=>Ge});var Ve=b()?`\r `:` -`;async function Qe(){return i({__tauriModule:"Os",message:{cmd:"platform"}})}async function Ze(){return i({__tauriModule:"Os",message:{cmd:"version"}})}async function Ye(){return i({__tauriModule:"Os",message:{cmd:"osType"}})}async function Je(){return i({__tauriModule:"Os",message:{cmd:"arch"}})}async function Xe(){return i({__tauriModule:"Os",message:{cmd:"tempdir"}})}var Be=r;return X(et);})(); +`;async function He(){return i({__tauriModule:"Os",message:{cmd:"platform"}})}async function Ge(){return i({__tauriModule:"Os",message:{cmd:"version"}})}async function $e(){return i({__tauriModule:"Os",message:{cmd:"osType"}})}async function je(){return i({__tauriModule:"Os",message:{cmd:"arch"}})}async function qe(){return i({__tauriModule:"Os",message:{cmd:"tempdir"}})}var Ke=r;return J(Qe);})(); window.__TAURI__ = __TAURI_IIFE__ diff --git a/core/tauri/src/endpoints.rs b/core/tauri/src/endpoints.rs index ed57ffd4052..d71b7bac954 100644 --- a/core/tauri/src/endpoints.rs +++ b/core/tauri/src/endpoints.rs @@ -12,7 +12,6 @@ use serde_json::Value as JsonValue; use std::sync::Arc; -mod app; mod event; #[cfg(os_any)] mod operating_system; @@ -54,7 +53,6 @@ impl From for InvokeResponse { #[derive(Deserialize)] #[serde(tag = "module", content = "message")] enum Module { - App(app::Cmd), #[cfg(process_any)] Process(process::Cmd), #[cfg(os_any)] @@ -77,12 +75,6 @@ impl Module { package_info, }; match self { - Self::App(cmd) => resolver.respond_async(async move { - cmd - .run(context) - .and_then(|r| r.json) - .map_err(InvokeError::from_anyhow) - }), #[cfg(process_any)] Self::Process(cmd) => resolver.respond_async(async move { cmd diff --git a/core/tauri/src/endpoints/app.rs b/core/tauri/src/endpoints/app.rs deleted file mode 100644 index ef1ecdd2524..00000000000 --- a/core/tauri/src/endpoints/app.rs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2019-2023 Tauri Programme within The Commons Conservancy -// SPDX-License-Identifier: Apache-2.0 -// SPDX-License-Identifier: MIT - -use super::InvokeContext; -use crate::Runtime; -use serde::Deserialize; -use tauri_macros::{command_enum, module_command_handler, CommandModule}; - -/// The API descriptor. -#[command_enum] -#[derive(Deserialize, CommandModule)] -#[serde(tag = "cmd", rename_all = "camelCase")] -#[allow(clippy::enum_variant_names)] -pub enum Cmd { - /// Get Application Version - GetAppVersion, - /// Get Application Name - GetAppName, - /// Get Tauri Version - GetTauriVersion, - /// Shows the application on macOS. - #[cmd(app_show, "app > show")] - Show, - /// Hides the application on macOS. - #[cmd(app_hide, "app > hide")] - Hide, -} - -impl Cmd { - fn get_app_version(context: InvokeContext) -> super::Result { - Ok(context.package_info.version.to_string()) - } - - fn get_app_name(context: InvokeContext) -> super::Result { - Ok(context.package_info.name) - } - - fn get_tauri_version(_context: InvokeContext) -> super::Result<&'static str> { - Ok(env!("CARGO_PKG_VERSION")) - } - - #[module_command_handler(app_show)] - #[allow(unused_variables)] - fn show(context: InvokeContext) -> super::Result<()> { - #[cfg(target_os = "macos")] - context.window.app_handle.show()?; - Ok(()) - } - - #[module_command_handler(app_hide)] - #[allow(unused_variables)] - fn hide(context: InvokeContext) -> super::Result<()> { - #[cfg(target_os = "macos")] - context.window.app_handle.hide()?; - Ok(()) - } -} diff --git a/core/tauri/src/lib.rs b/core/tauri/src/lib.rs index 0599a7f6b94..22aff414c58 100644 --- a/core/tauri/src/lib.rs +++ b/core/tauri/src/lib.rs @@ -303,6 +303,9 @@ pub use { scope::*, }; +/// The Tauri version. +pub const VERSION: &str = env!("CARGO_PKG_VERSION"); + #[cfg(target_os = "ios")] #[doc(hidden)] pub fn log_stdout() { diff --git a/core/tauri/src/path/mod.rs b/core/tauri/src/path/mod.rs index d962d53cdac..a0b0cf82351 100644 --- a/core/tauri/src/path/mod.rs +++ b/core/tauri/src/path/mod.rs @@ -15,7 +15,7 @@ use crate::{ use serde::{de::Error as DeError, Deserialize, Deserializer}; use serde_repr::{Deserialize_repr, Serialize_repr}; -#[cfg(path_all)] +#[cfg(any(path_all, test))] mod commands; mod error; pub use error::*; @@ -340,7 +340,7 @@ pub(crate) fn init() -> TauriPlugin { #[allow(unused_mut)] let mut builder = Builder::new("path"); - #[cfg(path_all)] + #[cfg(any(path_all, test))] { builder = builder.invoke_handler(crate::generate_handler![ commands::resolve_directory, diff --git a/core/tauri/src/scope/ipc.rs b/core/tauri/src/scope/ipc.rs index 8d5c3f73702..7837120d1c2 100644 --- a/core/tauri/src/scope/ipc.rs +++ b/core/tauri/src/scope/ipc.rs @@ -170,6 +170,8 @@ impl Scope { #[cfg(test)] mod tests { + use serde::Serialize; + use super::RemoteDomainAccessScope; use crate::{api::ipc::CallbackFn, test::MockRuntime, App, InvokePayload, Manager, Window}; @@ -186,10 +188,10 @@ mod tests { (app, window) } - fn assert_ipc_response( + fn assert_ipc_response( window: &Window, payload: InvokePayload, - expected: Result<&str, &str>, + expected: Result, ) { let callback = payload.callback; let error = payload.error; @@ -208,8 +210,8 @@ mod tests { } }; let (expected_response, fn_name) = match expected { - Ok(payload) => (payload, callback), - Err(payload) => (payload, error), + Ok(payload) => (serde_json::to_value(payload).unwrap(), callback), + Err(payload) => (serde_json::to_value(payload).unwrap(), error), }; let expected = format!( "window[\"_{}\"]({})", @@ -224,21 +226,19 @@ mod tests { assert!(evaluated_script.contains(&expected)); } - fn app_version_payload() -> InvokePayload { + fn path_is_absolute_payload() -> InvokePayload { let callback = CallbackFn(0); let error = CallbackFn(1); let mut payload = serde_json::Map::new(); - let mut msg = serde_json::Map::new(); - msg.insert( - "cmd".into(), - serde_json::Value::String("getAppVersion".into()), + payload.insert( + "path".into(), + serde_json::Value::String(std::env::current_dir().unwrap().display().to_string()), ); - payload.insert("message".into(), serde_json::Value::Object(msg)); InvokePayload { - cmd: "".into(), - tauri_module: Some("App".into()), + cmd: "plugin:path|is_absolute".into(), + tauri_module: None, callback, error, inner: serde_json::Value::Object(payload), @@ -262,12 +262,13 @@ mod tests { fn scope_not_defined() { let (_app, window) = test_context(vec![RemoteDomainAccessScope::new("app.tauri.app") .add_window("other") + .add_plugin("path") .enable_tauri_api()]); window.navigate("https://tauri.app".parse().unwrap()); - assert_ipc_response( + assert_ipc_response::<()>( &window, - app_version_payload(), + path_is_absolute_payload(), Err(&crate::window::ipc_scope_not_found_error_message( "main", "https://tauri.app/", @@ -279,12 +280,13 @@ mod tests { fn scope_not_defined_for_window() { let (_app, window) = test_context(vec![RemoteDomainAccessScope::new("tauri.app") .add_window("second") + .add_plugin("path") .enable_tauri_api()]); window.navigate("https://tauri.app".parse().unwrap()); - assert_ipc_response( + assert_ipc_response::<()>( &window, - app_version_payload(), + path_is_absolute_payload(), Err(&crate::window::ipc_scope_window_error_message("main")), ); } @@ -293,12 +295,13 @@ mod tests { fn scope_not_defined_for_url() { let (_app, window) = test_context(vec![RemoteDomainAccessScope::new("github.com") .add_window("main") + .add_plugin("path") .enable_tauri_api()]); window.navigate("https://tauri.app".parse().unwrap()); - assert_ipc_response( + assert_ipc_response::<()>( &window, - app_version_payload(), + path_is_absolute_payload(), Err(&crate::window::ipc_scope_domain_error_message( "https://tauri.app/", )), @@ -307,43 +310,37 @@ mod tests { #[test] fn subdomain_is_not_allowed() { - let (app, mut window) = test_context(vec![ + let (_app, mut window) = test_context(vec![ RemoteDomainAccessScope::new("tauri.app") .add_window("main") + .add_plugin("path") .enable_tauri_api(), RemoteDomainAccessScope::new("sub.tauri.app") .add_window("main") + .add_plugin("path") .enable_tauri_api(), ]); window.navigate("https://tauri.app".parse().unwrap()); - assert_ipc_response( - &window, - app_version_payload(), - Ok(app.package_info().version.to_string().as_str()), - ); + assert_ipc_response(&window, path_is_absolute_payload(), Ok(true)); window.navigate("https://blog.tauri.app".parse().unwrap()); - assert_ipc_response( + assert_ipc_response::<()>( &window, - app_version_payload(), + path_is_absolute_payload(), Err(&crate::window::ipc_scope_domain_error_message( "https://blog.tauri.app/", )), ); window.navigate("https://sub.tauri.app".parse().unwrap()); - assert_ipc_response( - &window, - app_version_payload(), - Ok(app.package_info().version.to_string().as_str()), - ); + assert_ipc_response(&window, path_is_absolute_payload(), Ok(true)); window.window.label = "test".into(); window.navigate("https://dev.tauri.app".parse().unwrap()); - assert_ipc_response( + assert_ipc_response::<()>( &window, - app_version_payload(), + path_is_absolute_payload(), Err(&crate::window::ipc_scope_not_found_error_message( "test", "https://dev.tauri.app/", @@ -353,16 +350,13 @@ mod tests { #[test] fn subpath_is_allowed() { - let (app, window) = test_context(vec![RemoteDomainAccessScope::new("tauri.app") + let (_app, window) = test_context(vec![RemoteDomainAccessScope::new("tauri.app") .add_window("main") + .add_plugin("path") .enable_tauri_api()]); window.navigate("https://tauri.app/inner/path".parse().unwrap()); - assert_ipc_response( - &window, - app_version_payload(), - Ok(app.package_info().version.to_string().as_str()), - ); + assert_ipc_response(&window, path_is_absolute_payload(), Ok(true)); } #[test] @@ -372,9 +366,9 @@ mod tests { ]); window.navigate("https://tauri.app".parse().unwrap()); - assert_ipc_response( + assert_ipc_response::<()>( &window, - app_version_payload(), + path_is_absolute_payload(), Err(crate::window::IPC_SCOPE_DOES_NOT_ALLOW), ); } @@ -386,7 +380,7 @@ mod tests { .add_plugin(PLUGIN_NAME)]); window.navigate("https://tauri.app".parse().unwrap()); - assert_ipc_response( + assert_ipc_response::<()>( &window, plugin_test_payload(), Err(&format!("plugin {PLUGIN_NAME} not found")), @@ -400,7 +394,7 @@ mod tests { ]); window.navigate("https://tauri.app".parse().unwrap()); - assert_ipc_response( + assert_ipc_response::<()>( &window, plugin_test_payload(), Err(crate::window::IPC_SCOPE_DOES_NOT_ALLOW), diff --git a/examples/api/src/views/App.svelte b/examples/api/src/views/App.svelte deleted file mode 100644 index 760590f0c58..00000000000 --- a/examples/api/src/views/App.svelte +++ /dev/null @@ -1,33 +0,0 @@ - - -
- - -
diff --git a/examples/api/src/views/Welcome.svelte b/examples/api/src/views/Welcome.svelte index 7906d2982bb..67eb5df1ef4 100644 --- a/examples/api/src/views/Welcome.svelte +++ b/examples/api/src/views/Welcome.svelte @@ -1,5 +1,4 @@