optimize bundle size

pull/383/head
Lucas Nogueira 2 years ago
parent 90a10a5f4f
commit 097b2c4191
No known key found for this signature in database
GPG Key ID: FFEA6C72E73482F1

@ -8,7 +8,11 @@
* @module
*/
import { invoke } from "@tauri-apps/api/tauri";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
}
}
/**
* Gets the application version.
@ -21,7 +25,7 @@ import { invoke } from "@tauri-apps/api/tauri";
* @since 1.0.0
*/
async function getVersion(): Promise<string> {
return invoke("plugin:app|version");
return window.__TAURI_INVOKE__("plugin:app|version");
}
/**
@ -35,7 +39,7 @@ async function getVersion(): Promise<string> {
* @since 1.0.0
*/
async function getName(): Promise<string> {
return invoke("plugin:app|name");
return window.__TAURI_INVOKE__("plugin:app|name");
}
/**
@ -50,7 +54,7 @@ async function getName(): Promise<string> {
* @since 1.0.0
*/
async function getTauriVersion(): Promise<string> {
return invoke("plugin:app|tauri_version");
return window.__TAURI_INVOKE__("plugin:app|tauri_version");
}
/**
@ -65,7 +69,7 @@ async function getTauriVersion(): Promise<string> {
* @since 1.2.0
*/
async function show(): Promise<void> {
return invoke("plugin:app|show");
return window.__TAURI_INVOKE__("plugin:app|show");
}
/**
@ -80,7 +84,7 @@ async function show(): Promise<void> {
* @since 1.2.0
*/
async function hide(): Promise<void> {
return invoke("plugin:app|hide");
return window.__TAURI_INVOKE__("plugin:app|hide");
}
export { getName, getVersion, getTauriVersion, show, hide };

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_APP__=function(e){"use strict";var n=Object.defineProperty,t=(e,n,t)=>{if(!n.has(e))throw TypeError("Cannot "+t)},r=(e,n,r)=>(t(e,n,"read from private field"),r?r.call(e):n.get(e)),i=(e,n,r,i)=>(t(e,n,"write to private field"),i?i.call(e,r):n.set(e,r),r);function a(e,n=!1){let t=window.crypto.getRandomValues(new Uint32Array(1))[0],r=`_${t}`;return Object.defineProperty(window,r,{value:t=>(n&&Reflect.deleteProperty(window,r),e?.(t)),writable:!1,configurable:!0}),t}((e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})})({},{Channel:()=>s,PluginListener:()=>l,addPluginListener:()=>c,convertFileSrc:()=>_,invoke:()=>u,transformCallback:()=>a});var o,s=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,n,t)=>{if(n.has(e))throw TypeError("Cannot add the same private member more than once");n instanceof WeakSet?n.add(e):n.set(e,t)})(this,o,(()=>{})),this.id=a((e=>{r(this,o).call(this,e)}))}set onmessage(e){i(this,o,e)}get onmessage(){return r(this,o)}toJSON(){return`__CHANNEL__:${this.id}`}};o=new WeakMap;var l=class{constructor(e,n,t){this.plugin=e,this.event=n,this.channelId=t}async unregister(){return u(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function c(e,n,t){let r=new s;return r.onmessage=t,u(`plugin:${e}|register_listener`,{event:n,handler:r}).then((()=>new l(e,n,r.id)))}async function u(e,n={}){return new Promise(((t,r)=>{let i=a((e=>{t(e),Reflect.deleteProperty(window,`_${o}`)}),!0),o=a((e=>{r(e),Reflect.deleteProperty(window,`_${i}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:i,error:o,...n})}))}function _(e,n="asset"){let t=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${n}.localhost/${t}`:`${n}://localhost/${t}`}return e.getName=async function(){return u("plugin:app|name")},e.getTauriVersion=async function(){return u("plugin:app|tauri_version")},e.getVersion=async function(){return u("plugin:app|version")},e.hide=async function(){return u("plugin:app|hide")},e.show=async function(){return u("plugin:app|show")},e}({});Object.defineProperty(window.__TAURI__,"app",{value:__TAURI_APP__})}
if("__TAURI__"in window){var __TAURI_APP__=function(_){"use strict";return _.getName=async function(){return window.__TAURI_INVOKE__("plugin:app|name")},_.getTauriVersion=async function(){return window.__TAURI_INVOKE__("plugin:app|tauri_version")},_.getVersion=async function(){return window.__TAURI_INVOKE__("plugin:app|version")},_.hide=async function(){return window.__TAURI_INVOKE__("plugin:app|hide")},_.show=async function(){return window.__TAURI_INVOKE__("plugin:app|show")},_}({});Object.defineProperty(window.__TAURI__,"app",{value:__TAURI_APP__})}

@ -1,12 +1,16 @@
import { invoke } from "@tauri-apps/api/tauri";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
}
}
export class Authenticator {
async init(): Promise<void> {
return await invoke("plugin:authenticator|init_auth");
return await window.__TAURI_INVOKE__("plugin:authenticator|init_auth");
}
async register(challenge: string, application: string): Promise<string> {
return await invoke("plugin:authenticator|register", {
return await window.__TAURI_INVOKE__("plugin:authenticator|register", {
timeout: 10000,
challenge,
application,
@ -19,12 +23,15 @@ export class Authenticator {
registerData: string,
clientData: string
): Promise<string> {
return await invoke("plugin:authenticator|verify_registration", {
challenge,
application,
registerData,
clientData,
});
return await window.__TAURI_INVOKE__(
"plugin:authenticator|verify_registration",
{
challenge,
application,
registerData,
clientData,
}
);
}
async sign(
@ -32,7 +39,7 @@ export class Authenticator {
application: string,
keyHandle: string
): Promise<string> {
return await invoke("plugin:authenticator|sign", {
return await window.__TAURI_INVOKE__("plugin:authenticator|sign", {
timeout: 10000,
challenge,
application,
@ -48,13 +55,16 @@ export class Authenticator {
keyHandle: string,
pubkey: string
): Promise<number> {
return await invoke("plugin:authenticator|verify_signature", {
challenge,
application,
signData,
clientData,
keyHandle,
pubkey,
});
return await window.__TAURI_INVOKE__(
"plugin:authenticator|verify_signature",
{
challenge,
application,
signData,
clientData,
keyHandle,
pubkey,
}
);
}
}

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_AUTHENTICATOR__=function(e){"use strict";var t=Object.defineProperty,n=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},i=(e,t,i)=>(n(e,t,"read from private field"),i?i.call(e):t.get(e)),r=(e,t,i,r)=>(n(e,t,"write to private field"),r?r.call(e,i):t.set(e,i),i);function a(e,t=!1){let n=window.crypto.getRandomValues(new Uint32Array(1))[0],i=`_${n}`;return Object.defineProperty(window,i,{value:n=>(t&&Reflect.deleteProperty(window,i),e?.(n)),writable:!1,configurable:!0}),n}((e,n)=>{for(var i in n)t(e,i,{get:n[i],enumerable:!0})})({},{Channel:()=>l,PluginListener:()=>s,addPluginListener:()=>c,convertFileSrc:()=>h,invoke:()=>u,transformCallback:()=>a});var o,l=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,o,(()=>{})),this.id=a((e=>{i(this,o).call(this,e)}))}set onmessage(e){r(this,o,e)}get onmessage(){return i(this,o)}toJSON(){return`__CHANNEL__:${this.id}`}};o=new WeakMap;var s=class{constructor(e,t,n){this.plugin=e,this.event=t,this.channelId=n}async unregister(){return u(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function c(e,t,n){let i=new l;return i.onmessage=n,u(`plugin:${e}|register_listener`,{event:t,handler:i}).then((()=>new s(e,t,i.id)))}async function u(e,t={}){return new Promise(((n,i)=>{let r=a((e=>{n(e),Reflect.deleteProperty(window,`_${o}`)}),!0),o=a((e=>{i(e),Reflect.deleteProperty(window,`_${r}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:r,error:o,...t})}))}function h(e,t="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${t}.localhost/${n}`:`${t}://localhost/${n}`}return e.Authenticator=class{async init(){return await u("plugin:authenticator|init_auth")}async register(e,t){return await u("plugin:authenticator|register",{timeout:1e4,challenge:e,application:t})}async verifyRegistration(e,t,n,i){return await u("plugin:authenticator|verify_registration",{challenge:e,application:t,registerData:n,clientData:i})}async sign(e,t,n){return await u("plugin:authenticator|sign",{timeout:1e4,challenge:e,application:t,keyHandle:n})}async verifySignature(e,t,n,i,r,a){return await u("plugin:authenticator|verify_signature",{challenge:e,application:t,signData:n,clientData:i,keyHandle:r,pubkey:a})}},e}({});Object.defineProperty(window.__TAURI__,"authenticator",{value:__TAURI_AUTHENTICATOR__})}
if("__TAURI__"in window){var __TAURI_AUTHENTICATOR__=function(t){"use strict";return t.Authenticator=class{async init(){return await window.__TAURI_INVOKE__("plugin:authenticator|init_auth")}async register(t,i){return await window.__TAURI_INVOKE__("plugin:authenticator|register",{timeout:1e4,challenge:t,application:i})}async verifyRegistration(t,i,a,n){return await window.__TAURI_INVOKE__("plugin:authenticator|verify_registration",{challenge:t,application:i,registerData:a,clientData:n})}async sign(t,i,a){return await window.__TAURI_INVOKE__("plugin:authenticator|sign",{timeout:1e4,challenge:t,application:i,keyHandle:a})}async verifySignature(t,i,a,n,e,_){return await window.__TAURI_INVOKE__("plugin:authenticator|verify_signature",{challenge:t,application:i,signData:a,clientData:n,keyHandle:e,pubkey:_})}},t}({});Object.defineProperty(window.__TAURI__,"authenticator",{value:__TAURI_AUTHENTICATOR__})}

@ -2,16 +2,20 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { invoke } from "@tauri-apps/api/tauri";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
}
}
export async function isEnabled(): Promise<boolean> {
return await invoke("plugin:autostart|is_enabled");
return await window.__TAURI_INVOKE__("plugin:autostart|is_enabled");
}
export async function enable(): Promise<void> {
await invoke("plugin:autostart|enable");
await window.__TAURI_INVOKE__("plugin:autostart|enable");
}
export async function disable(): Promise<void> {
await invoke("plugin:autostart|disable");
await window.__TAURI_INVOKE__("plugin:autostart|disable");
}

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_AUTOSTART__=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)),i=(e,t,r,i)=>(n(e,t,"write to private field"),i?i.call(e,r):t.set(e,r),r);function a(e,t=!1){let n=window.crypto.getRandomValues(new Uint32Array(1))[0],r=`_${n}`;return Object.defineProperty(window,r,{value:n=>(t&&Reflect.deleteProperty(window,r),e?.(n)),writable:!1,configurable:!0}),n}((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})({},{Channel:()=>o,PluginListener:()=>l,addPluginListener:()=>c,convertFileSrc:()=>d,invoke:()=>u,transformCallback:()=>a});var s,o=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,s,(()=>{})),this.id=a((e=>{r(this,s).call(this,e)}))}set onmessage(e){i(this,s,e)}get onmessage(){return r(this,s)}toJSON(){return`__CHANNEL__:${this.id}`}};s=new WeakMap;var l=class{constructor(e,t,n){this.plugin=e,this.event=t,this.channelId=n}async unregister(){return u(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function c(e,t,n){let r=new o;return r.onmessage=n,u(`plugin:${e}|register_listener`,{event:t,handler:r}).then((()=>new l(e,t,r.id)))}async function u(e,t={}){return new Promise(((n,r)=>{let i=a((e=>{n(e),Reflect.deleteProperty(window,`_${s}`)}),!0),s=a((e=>{r(e),Reflect.deleteProperty(window,`_${i}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:i,error:s,...t})}))}function d(e,t="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${t}.localhost/${n}`:`${t}://localhost/${n}`}return e.disable=async function(){await u("plugin:autostart|disable")},e.enable=async function(){await u("plugin:autostart|enable")},e.isEnabled=async function(){return await u("plugin:autostart|is_enabled")},e}({});Object.defineProperty(window.__TAURI__,"autostart",{value:__TAURI_AUTOSTART__})}
if("__TAURI__"in window){var __TAURI_AUTOSTART__=function(_){"use strict";return _.disable=async function(){await window.__TAURI_INVOKE__("plugin:autostart|disable")},_.enable=async function(){await window.__TAURI_INVOKE__("plugin:autostart|enable")},_.isEnabled=async function(){return await window.__TAURI_INVOKE__("plugin:autostart|is_enabled")},_}({});Object.defineProperty(window.__TAURI__,"autostart",{value:__TAURI_AUTOSTART__})}

@ -8,7 +8,11 @@
* @module
*/
import { invoke } from "@tauri-apps/api/tauri";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
}
}
/**
* @since 1.0.0
@ -64,7 +68,7 @@ interface CliMatches {
* @since 1.0.0
*/
async function getMatches(): Promise<CliMatches> {
return await invoke("plugin:cli|cli_matches");
return await window.__TAURI_INVOKE__("plugin:cli|cli_matches");
}
export type { ArgMatch, SubcommandMatch, CliMatches };

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_CLI__=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)),i=(e,t,r,i)=>(n(e,t,"write to private field"),i?i.call(e,r):t.set(e,r),r);function a(e,t=!1){let n=window.crypto.getRandomValues(new Uint32Array(1))[0],r=`_${n}`;return Object.defineProperty(window,r,{value:n=>(t&&Reflect.deleteProperty(window,r),e?.(n)),writable:!1,configurable:!0}),n}((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})({},{Channel:()=>s,PluginListener:()=>l,addPluginListener:()=>c,convertFileSrc:()=>d,invoke:()=>_,transformCallback:()=>a});var o,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,o,(()=>{})),this.id=a((e=>{r(this,o).call(this,e)}))}set onmessage(e){i(this,o,e)}get onmessage(){return r(this,o)}toJSON(){return`__CHANNEL__:${this.id}`}};o=new WeakMap;var l=class{constructor(e,t,n){this.plugin=e,this.event=t,this.channelId=n}async unregister(){return _(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function c(e,t,n){let r=new s;return r.onmessage=n,_(`plugin:${e}|register_listener`,{event:t,handler:r}).then((()=>new l(e,t,r.id)))}async function _(e,t={}){return new Promise(((n,r)=>{let i=a((e=>{n(e),Reflect.deleteProperty(window,`_${o}`)}),!0),o=a((e=>{r(e),Reflect.deleteProperty(window,`_${i}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:i,error:o,...t})}))}function d(e,t="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${t}.localhost/${n}`:`${t}://localhost/${n}`}return e.getMatches=async function(){return await _("plugin:cli|cli_matches")},e}({});Object.defineProperty(window.__TAURI__,"cli",{value:__TAURI_CLI__})}
if("__TAURI__"in window){var __TAURI_CLI__=function(_){"use strict";return _.getMatches=async function(){return await window.__TAURI_INVOKE__("plugin:cli|cli_matches")},_}({});Object.defineProperty(window.__TAURI__,"cli",{value:__TAURI_CLI__})}

@ -8,7 +8,11 @@
* @module
*/
import { invoke } from "@tauri-apps/api/tauri";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
}
}
interface Clip<K, T> {
kind: K;
@ -34,7 +38,7 @@ async function writeText(
text: string,
opts?: { label?: string }
): Promise<void> {
return invoke("plugin:clipboard|write", {
return window.__TAURI_INVOKE__("plugin:clipboard|write", {
data: {
kind: "PlainText",
options: {
@ -55,7 +59,9 @@ async function writeText(
* @since 1.0.0.
*/
async function readText(): Promise<string> {
const kind: ClipResponse = await invoke("plugin:clipboard|read");
const kind: ClipResponse = await window.__TAURI_INVOKE__(
"plugin:clipboard|read"
);
return kind.options;
}

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_CLIPBOARD__=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)),i=(e,t,r,i)=>(n(e,t,"write to private field"),i?i.call(e,r):t.set(e,r),r);function a(e,t=!1){let n=window.crypto.getRandomValues(new Uint32Array(1))[0],r=`_${n}`;return Object.defineProperty(window,r,{value:n=>(t&&Reflect.deleteProperty(window,r),e?.(n)),writable:!1,configurable:!0}),n}((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})({},{Channel:()=>l,PluginListener:()=>s,addPluginListener:()=>c,convertFileSrc:()=>_,invoke:()=>d,transformCallback:()=>a});var o,l=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,o,(()=>{})),this.id=a((e=>{r(this,o).call(this,e)}))}set onmessage(e){i(this,o,e)}get onmessage(){return r(this,o)}toJSON(){return`__CHANNEL__:${this.id}`}};o=new WeakMap;var s=class{constructor(e,t,n){this.plugin=e,this.event=t,this.channelId=n}async unregister(){return d(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function c(e,t,n){let r=new l;return r.onmessage=n,d(`plugin:${e}|register_listener`,{event:t,handler:r}).then((()=>new s(e,t,r.id)))}async function d(e,t={}){return new Promise(((n,r)=>{let i=a((e=>{n(e),Reflect.deleteProperty(window,`_${o}`)}),!0),o=a((e=>{r(e),Reflect.deleteProperty(window,`_${i}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:i,error:o,...t})}))}function _(e,t="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${t}.localhost/${n}`:`${t}://localhost/${n}`}return e.readText=async function(){return(await d("plugin:clipboard|read")).options},e.writeText=async function(e,t){return d("plugin:clipboard|write",{data:{kind:"PlainText",options:{label:null==t?void 0:t.label,text:e}}})},e}({});Object.defineProperty(window.__TAURI__,"clipboard",{value:__TAURI_CLIPBOARD__})}
if("__TAURI__"in window){var __TAURI_CLIPBOARD__=function(_){"use strict";return _.readText=async function(){return(await window.__TAURI_INVOKE__("plugin:clipboard|read")).options},_.writeText=async function(_,i){return window.__TAURI_INVOKE__("plugin:clipboard|write",{data:{kind:"PlainText",options:{label:null==i?void 0:i.label,text:_}}})},_}({});Object.defineProperty(window.__TAURI__,"clipboard",{value:__TAURI_CLIPBOARD__})}

@ -2,7 +2,11 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { invoke } from "@tauri-apps/api/tauri";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
}
}
interface FileResponse {
base64Data?: string;
@ -169,7 +173,7 @@ async function open(
Object.freeze(options);
}
return invoke("plugin:dialog|open", { options });
return window.__TAURI_INVOKE__("plugin:dialog|open", { options });
}
/**
@ -201,7 +205,7 @@ async function save(options: SaveDialogOptions = {}): Promise<string | null> {
Object.freeze(options);
}
return invoke("plugin:dialog|save", { options });
return window.__TAURI_INVOKE__("plugin:dialog|save", { options });
}
/**
@ -226,7 +230,7 @@ async function message(
options?: string | MessageDialogOptions
): Promise<void> {
const opts = typeof options === "string" ? { title: options } : options;
return invoke("plugin:dialog|message", {
return window.__TAURI_INVOKE__("plugin:dialog|message", {
message: message.toString(),
title: opts?.title?.toString(),
type_: opts?.type,
@ -255,7 +259,7 @@ async function ask(
options?: string | ConfirmDialogOptions
): Promise<boolean> {
const opts = typeof options === "string" ? { title: options } : options;
return invoke("plugin:dialog|ask", {
return window.__TAURI_INVOKE__("plugin:dialog|ask", {
message: message.toString(),
title: opts?.title?.toString(),
type_: opts?.type,
@ -285,7 +289,7 @@ async function confirm(
options?: string | ConfirmDialogOptions
): Promise<boolean> {
const opts = typeof options === "string" ? { title: options } : options;
return invoke("plugin:dialog|confirm", {
return window.__TAURI_INVOKE__("plugin:dialog|confirm", {
message: message.toString(),
title: opts?.title?.toString(),
type_: opts?.type,

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_DIALOG__=function(e){"use strict";var t=Object.defineProperty,n=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},i=(e,t,i)=>(n(e,t,"read from private field"),i?i.call(e):t.get(e)),o=(e,t,i,o)=>(n(e,t,"write to private field"),o?o.call(e,i):t.set(e,i),i);function l(e,t=!1){let n=window.crypto.getRandomValues(new Uint32Array(1))[0],i=`_${n}`;return Object.defineProperty(window,i,{value:n=>(t&&Reflect.deleteProperty(window,i),e?.(n)),writable:!1,configurable:!0}),n}((e,n)=>{for(var i in n)t(e,i,{get:n[i],enumerable:!0})})({},{Channel:()=>a,PluginListener:()=>s,addPluginListener:()=>u,convertFileSrc:()=>c,invoke:()=>d,transformCallback:()=>l});var r,a=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,r,(()=>{})),this.id=l((e=>{i(this,r).call(this,e)}))}set onmessage(e){o(this,r,e)}get onmessage(){return i(this,r)}toJSON(){return`__CHANNEL__:${this.id}`}};r=new WeakMap;var s=class{constructor(e,t,n){this.plugin=e,this.event=t,this.channelId=n}async unregister(){return d(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function u(e,t,n){let i=new a;return i.onmessage=n,d(`plugin:${e}|register_listener`,{event:t,handler:i}).then((()=>new s(e,t,i.id)))}async function d(e,t={}){return new Promise(((n,i)=>{let o=l((e=>{n(e),Reflect.deleteProperty(window,`_${r}`)}),!0),r=l((e=>{i(e),Reflect.deleteProperty(window,`_${o}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:o,error:r,...t})}))}function c(e,t="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${t}.localhost/${n}`:`${t}://localhost/${n}`}return e.ask=async function(e,t){var n,i,o,l,r;const a="string"==typeof t?{title:t}:t;return d("plugin:dialog|ask",{message:e.toString(),title:null===(n=null==a?void 0:a.title)||void 0===n?void 0:n.toString(),type_:null==a?void 0:a.type,okButtonLabel:null!==(o=null===(i=null==a?void 0:a.okLabel)||void 0===i?void 0:i.toString())&&void 0!==o?o:"Yes",cancelButtonLabel:null!==(r=null===(l=null==a?void 0:a.cancelLabel)||void 0===l?void 0:l.toString())&&void 0!==r?r:"No"})},e.confirm=async function(e,t){var n,i,o,l,r;const a="string"==typeof t?{title:t}:t;return d("plugin:dialog|confirm",{message:e.toString(),title:null===(n=null==a?void 0:a.title)||void 0===n?void 0:n.toString(),type_:null==a?void 0:a.type,okButtonLabel:null!==(o=null===(i=null==a?void 0:a.okLabel)||void 0===i?void 0:i.toString())&&void 0!==o?o:"Ok",cancelButtonLabel:null!==(r=null===(l=null==a?void 0:a.cancelLabel)||void 0===l?void 0:l.toString())&&void 0!==r?r:"Cancel"})},e.message=async function(e,t){var n,i;const o="string"==typeof t?{title:t}:t;return d("plugin:dialog|message",{message:e.toString(),title:null===(n=null==o?void 0:o.title)||void 0===n?void 0:n.toString(),type_:null==o?void 0:o.type,okButtonLabel:null===(i=null==o?void 0:o.okLabel)||void 0===i?void 0:i.toString()})},e.open=async function(e={}){return"object"==typeof e&&Object.freeze(e),d("plugin:dialog|open",{options:e})},e.save=async function(e={}){return"object"==typeof e&&Object.freeze(e),d("plugin:dialog|save",{options:e})},e}({});Object.defineProperty(window.__TAURI__,"dialog",{value:__TAURI_DIALOG__})}
if("__TAURI__"in window){var __TAURI_DIALOG__=function(n){"use strict";return n.ask=async function(n,o){var t,i,l,e,u;const _="string"==typeof o?{title:o}:o;return window.__TAURI_INVOKE__("plugin:dialog|ask",{message:n.toString(),title:null===(t=null==_?void 0:_.title)||void 0===t?void 0:t.toString(),type_:null==_?void 0:_.type,okButtonLabel:null!==(l=null===(i=null==_?void 0:_.okLabel)||void 0===i?void 0:i.toString())&&void 0!==l?l:"Yes",cancelButtonLabel:null!==(u=null===(e=null==_?void 0:_.cancelLabel)||void 0===e?void 0:e.toString())&&void 0!==u?u:"No"})},n.confirm=async function(n,o){var t,i,l,e,u;const _="string"==typeof o?{title:o}:o;return window.__TAURI_INVOKE__("plugin:dialog|confirm",{message:n.toString(),title:null===(t=null==_?void 0:_.title)||void 0===t?void 0:t.toString(),type_:null==_?void 0:_.type,okButtonLabel:null!==(l=null===(i=null==_?void 0:_.okLabel)||void 0===i?void 0:i.toString())&&void 0!==l?l:"Ok",cancelButtonLabel:null!==(u=null===(e=null==_?void 0:_.cancelLabel)||void 0===e?void 0:e.toString())&&void 0!==u?u:"Cancel"})},n.message=async function(n,o){var t,i;const l="string"==typeof o?{title:o}:o;return window.__TAURI_INVOKE__("plugin:dialog|message",{message:n.toString(),title:null===(t=null==l?void 0:l.title)||void 0===t?void 0:t.toString(),type_:null==l?void 0:l.type,okButtonLabel:null===(i=null==l?void 0:l.okLabel)||void 0===i?void 0:i.toString()})},n.open=async function(n={}){return"object"==typeof n&&Object.freeze(n),window.__TAURI_INVOKE__("plugin:dialog|open",{options:n})},n.save=async function(n={}){return"object"==typeof n&&Object.freeze(n),window.__TAURI_INVOKE__("plugin:dialog|save",{options:n})},n}({});Object.defineProperty(window.__TAURI__,"dialog",{value:__TAURI_DIALOG__})}

@ -45,9 +45,14 @@
* @module
*/
import { invoke } from "@tauri-apps/api/tauri";
import { BaseDirectory } from "@tauri-apps/api/path";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
}
}
interface Permissions {
/**
* `true` if these permissions describe a readonly (unwritable) file.
@ -226,7 +231,7 @@ async function readTextFile(
filePath: string,
options: FsOptions = {}
): Promise<string> {
return await invoke("plugin:fs|read_text_file", {
return await window.__TAURI_INVOKE__("plugin:fs|read_text_file", {
path: filePath,
options,
});
@ -247,7 +252,7 @@ async function readBinaryFile(
filePath: string,
options: FsOptions = {}
): Promise<Uint8Array> {
const arr = await invoke<number[]>("plugin:fs|read_file", {
const arr = await window.__TAURI_INVOKE__<number[]>("plugin:fs|read_file", {
path: filePath,
options,
});
@ -323,7 +328,7 @@ async function writeTextFile(
fileOptions = contents;
}
return await invoke("plugin:fs|write_file", {
return await window.__TAURI_INVOKE__("plugin:fs|write_file", {
path: file.path,
contents: Array.from(new TextEncoder().encode(file.contents)),
options: fileOptions,
@ -405,7 +410,7 @@ async function writeBinaryFile(
file.contents = contents ?? [];
}
return await invoke("plugin:fs|write_binary_file", {
return await window.__TAURI_INVOKE__("plugin:fs|write_binary_file", {
path: file.path,
contents: Array.from(
file.contents instanceof ArrayBuffer
@ -440,7 +445,7 @@ async function readDir(
dir: string,
options: FsDirOptions = {}
): Promise<FileEntry[]> {
return await invoke("plugin:fs|read_dir", {
return await window.__TAURI_INVOKE__("plugin:fs|read_dir", {
path: dir,
options,
});
@ -465,7 +470,7 @@ async function createDir(
dir: string,
options: FsDirOptions = {}
): Promise<void> {
return await invoke("plugin:fs|create_dir", {
return await window.__TAURI_INVOKE__("plugin:fs|create_dir", {
path: dir,
options,
});
@ -489,7 +494,7 @@ async function removeDir(
dir: string,
options: FsDirOptions = {}
): Promise<void> {
return await invoke("plugin:fs|remove_dir", {
return await window.__TAURI_INVOKE__("plugin:fs|remove_dir", {
path: dir,
options,
});
@ -513,7 +518,7 @@ async function copyFile(
destination: string,
options: FsOptions = {}
): Promise<void> {
return await invoke("plugin:fs|copy_file", {
return await window.__TAURI_INVOKE__("plugin:fs|copy_file", {
source,
destination,
options,
@ -537,7 +542,7 @@ async function removeFile(
file: string,
options: FsOptions = {}
): Promise<void> {
return await invoke("plugin:fs|remove_file", {
return await window.__TAURI_INVOKE__("plugin:fs|remove_file", {
path: file,
options,
});
@ -561,7 +566,7 @@ async function renameFile(
newPath: string,
options: FsOptions = {}
): Promise<void> {
return await invoke("plugin:fs|rename_file", {
return await window.__TAURI_INVOKE__("plugin:fs|rename_file", {
oldPath,
newPath,
options,
@ -580,7 +585,7 @@ async function renameFile(
* @since 1.0.0
*/
async function exists(path: string): Promise<boolean> {
return await invoke("plugin:fs|exists", { path });
return await window.__TAURI_INVOKE__("plugin:fs|exists", { path });
}
/**
@ -589,17 +594,19 @@ async function exists(path: string): Promise<boolean> {
* @since 1.0.0
*/
async function metadata(path: string): Promise<Metadata> {
return await invoke<BackendMetadata>("plugin:fs|metadata", {
path,
}).then((metadata) => {
const { accessedAtMs, createdAtMs, modifiedAtMs, ...data } = metadata;
return {
accessedAt: new Date(accessedAtMs),
createdAt: new Date(createdAtMs),
modifiedAt: new Date(modifiedAtMs),
...data,
};
});
return await window
.__TAURI_INVOKE__<BackendMetadata>("plugin:fs|metadata", {
path,
})
.then((metadata) => {
const { accessedAtMs, createdAtMs, modifiedAtMs, ...data } = metadata;
return {
accessedAt: new Date(accessedAtMs),
createdAt: new Date(createdAtMs),
modifiedAt: new Date(modifiedAtMs),
...data,
};
});
}
export type {

File diff suppressed because one or more lines are too long

@ -8,7 +8,14 @@
* @module
*/
import { invoke, transformCallback } from "@tauri-apps/api/tauri";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
__TAURI__: {
transformCallback: <T>(cb: (payload: T) => void) => number;
};
}
}
export type ShortcutHandler = (shortcut: string) => void;
@ -31,9 +38,9 @@ async function register(
shortcut: string,
handler: ShortcutHandler
): Promise<void> {
return await invoke("plugin:globalShortcut|register", {
return await window.__TAURI_INVOKE__("plugin:globalShortcut|register", {
shortcut,
handler: transformCallback(handler),
handler: window.__TAURI__.transformCallback(handler),
});
}
@ -56,9 +63,9 @@ async function registerAll(
shortcuts: string[],
handler: ShortcutHandler
): Promise<void> {
return await invoke("plugin:globalShortcut|register_all", {
return await window.__TAURI_INVOKE__("plugin:globalShortcut|register_all", {
shortcuts,
handler: transformCallback(handler),
handler: window.__TAURI__.transformCallback(handler),
});
}
@ -78,7 +85,7 @@ async function registerAll(
* @since 1.0.0
*/
async function isRegistered(shortcut: string): Promise<boolean> {
return await invoke("plugin:globalShortcut|is_registered", {
return await window.__TAURI_INVOKE__("plugin:globalShortcut|is_registered", {
shortcut,
});
}
@ -96,7 +103,7 @@ async function isRegistered(shortcut: string): Promise<boolean> {
* @since 1.0.0
*/
async function unregister(shortcut: string): Promise<void> {
return await invoke("plugin:globalShortcut|unregister", {
return await window.__TAURI_INVOKE__("plugin:globalShortcut|unregister", {
shortcut,
});
}
@ -112,7 +119,7 @@ async function unregister(shortcut: string): Promise<void> {
* @since 1.0.0
*/
async function unregisterAll(): Promise<void> {
return await invoke("plugin:globalShortcut|unregister_all");
return await window.__TAURI_INVOKE__("plugin:globalShortcut|unregister_all");
}
export { register, registerAll, isRegistered, unregister, unregisterAll };

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_GLOBALSHORTCUT__=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)),i=(e,t,r,i)=>(n(e,t,"write to private field"),i?i.call(e,r):t.set(e,r),r);function a(e,t=!1){let n=window.crypto.getRandomValues(new Uint32Array(1))[0],r=`_${n}`;return Object.defineProperty(window,r,{value:n=>(t&&Reflect.deleteProperty(window,r),e?.(n)),writable:!1,configurable:!0}),n}((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})({},{Channel:()=>s,PluginListener:()=>l,addPluginListener:()=>c,convertFileSrc:()=>h,invoke:()=>u,transformCallback:()=>a});var o,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,o,(()=>{})),this.id=a((e=>{r(this,o).call(this,e)}))}set onmessage(e){i(this,o,e)}get onmessage(){return r(this,o)}toJSON(){return`__CHANNEL__:${this.id}`}};o=new WeakMap;var l=class{constructor(e,t,n){this.plugin=e,this.event=t,this.channelId=n}async unregister(){return u(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function c(e,t,n){let r=new s;return r.onmessage=n,u(`plugin:${e}|register_listener`,{event:t,handler:r}).then((()=>new l(e,t,r.id)))}async function u(e,t={}){return new Promise(((n,r)=>{let i=a((e=>{n(e),Reflect.deleteProperty(window,`_${o}`)}),!0),o=a((e=>{r(e),Reflect.deleteProperty(window,`_${i}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:i,error:o,...t})}))}function h(e,t="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${t}.localhost/${n}`:`${t}://localhost/${n}`}return e.isRegistered=async function(e){return await u("plugin:globalShortcut|is_registered",{shortcut:e})},e.register=async function(e,t){return await u("plugin:globalShortcut|register",{shortcut:e,handler:a(t)})},e.registerAll=async function(e,t){return await u("plugin:globalShortcut|register_all",{shortcuts:e,handler:a(t)})},e.unregister=async function(e){return await u("plugin:globalShortcut|unregister",{shortcut:e})},e.unregisterAll=async function(){return await u("plugin:globalShortcut|unregister_all")},e}({});Object.defineProperty(window.__TAURI__,"globalShortcut",{value:__TAURI_GLOBALSHORTCUT__})}
if("__TAURI__"in window){var __TAURI_GLOBALSHORTCUT__=function(_){"use strict";return _.isRegistered=async function(_){return await window.__TAURI_INVOKE__("plugin:globalShortcut|is_registered",{shortcut:_})},_.register=async function(_,t){return await window.__TAURI_INVOKE__("plugin:globalShortcut|register",{shortcut:_,handler:window.__TAURI__.transformCallback(t)})},_.registerAll=async function(_,t){return await window.__TAURI_INVOKE__("plugin:globalShortcut|register_all",{shortcuts:_,handler:window.__TAURI__.transformCallback(t)})},_.unregister=async function(_){return await window.__TAURI_INVOKE__("plugin:globalShortcut|unregister",{shortcut:_})},_.unregisterAll=async function(){return await window.__TAURI_INVOKE__("plugin:globalShortcut|unregister_all")},_}({});Object.defineProperty(window.__TAURI__,"globalShortcut",{value:__TAURI_GLOBALSHORTCUT__})}

@ -24,7 +24,11 @@
* @module
*/
import { invoke } from "@tauri-apps/api/tauri";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
}
}
/**
* @since 1.0.0
@ -297,7 +301,7 @@ class Client {
* ```
*/
async drop(): Promise<void> {
return invoke("plugin:http|drop_client", {
return window.__TAURI_INVOKE__("plugin:http|drop_client", {
client: this.id,
});
}
@ -320,30 +324,32 @@ class Client {
if (jsonResponse) {
options.responseType = ResponseType.Text;
}
return invoke<IResponse<T>>("plugin:http|request", {
clientId: this.id,
options,
}).then((res) => {
const response = new Response(res);
if (jsonResponse) {
/* eslint-disable */
try {
response.data = JSON.parse(response.data as string);
} catch (e) {
if (response.ok && (response.data as unknown as string) === "") {
response.data = {} as T;
} else if (response.ok) {
throw Error(
`Failed to parse response \`${response.data}\` as JSON: ${e};
return window
.__TAURI_INVOKE__<IResponse<T>>("plugin:http|request", {
clientId: this.id,
options,
})
.then((res) => {
const response = new Response(res);
if (jsonResponse) {
/* eslint-disable */
try {
response.data = JSON.parse(response.data as string);
} catch (e) {
if (response.ok && (response.data as unknown as string) === "") {
response.data = {} as T;
} else if (response.ok) {
throw Error(
`Failed to parse response \`${response.data}\` as JSON: ${e};
try setting the \`responseType\` option to \`ResponseType.Text\` or \`ResponseType.Binary\` if the API does not return a JSON response.`
);
);
}
}
/* eslint-enable */
return response;
}
/* eslint-enable */
return response;
}
return response;
});
});
}
/**
@ -478,9 +484,11 @@ class Client {
* @since 1.0.0
*/
async function getClient(options?: ClientOptions): Promise<Client> {
return invoke<number>("plugin:http|create_client", {
options,
}).then((id) => new Client(id));
return window
.__TAURI_INVOKE__<number>("plugin:http|create_client", {
options,
})
.then((id) => new Client(id));
}
/** @internal */

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_HTTP__=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)),s=(e,t,r,s)=>(n(e,t,"write to private field"),s?s.call(e,r):t.set(e,r),r);function i(e,t=!1){let n=window.crypto.getRandomValues(new Uint32Array(1))[0],r=`_${n}`;return Object.defineProperty(window,r,{value:n=>(t&&Reflect.deleteProperty(window,r),e?.(n)),writable:!1,configurable:!0}),n}((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})({},{Channel:()=>a,PluginListener:()=>c,addPluginListener:()=>u,convertFileSrc:()=>h,invoke:()=>d,transformCallback:()=>i});var o,a=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,o,(()=>{})),this.id=i((e=>{r(this,o).call(this,e)}))}set onmessage(e){s(this,o,e)}get onmessage(){return r(this,o)}toJSON(){return`__CHANNEL__:${this.id}`}};o=new WeakMap;var l,c=class{constructor(e,t,n){this.plugin=e,this.event=t,this.channelId=n}async unregister(){return d(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function u(e,t,n){let r=new a;return r.onmessage=n,d(`plugin:${e}|register_listener`,{event:t,handler:r}).then((()=>new c(e,t,r.id)))}async function d(e,t={}){return new Promise(((n,r)=>{let s=i((e=>{n(e),Reflect.deleteProperty(window,`_${o}`)}),!0),o=i((e=>{r(e),Reflect.deleteProperty(window,`_${s}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:s,error:o,...t})}))}function h(e,t="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${t}.localhost/${n}`:`${t}://localhost/${n}`}e.ResponseType=void 0,(l=e.ResponseType||(e.ResponseType={}))[l.JSON=1]="JSON",l[l.Text=2]="Text",l[l.Binary=3]="Binary";class p{constructor(e,t){this.type=e,this.payload=t}static form(e){const t={},n=(e,n)=>{if(null!==n){let r;r="string"==typeof n?n:n instanceof Uint8Array||Array.isArray(n)?Array.from(n):n instanceof File?{file:n.name,mime:n.type,fileName:n.name}:"string"==typeof n.file?{file:n.file,mime:n.mime,fileName:n.fileName}:{file:Array.from(n.file),mime:n.mime,fileName:n.fileName},t[String(e)]=r}};if(e instanceof FormData)for(const[t,r]of e)n(t,r);else for(const[t,r]of Object.entries(e))n(t,r);return new p("Form",t)}static json(e){return new p("Json",e)}static text(e){return new p("Text",e)}static bytes(e){return new p("Bytes",Array.from(e instanceof ArrayBuffer?new Uint8Array(e):e))}}class f{constructor(e){this.url=e.url,this.status=e.status,this.ok=this.status>=200&&this.status<300,this.headers=e.headers,this.rawHeaders=e.rawHeaders,this.data=e.data}}class y{constructor(e){this.id=e}async drop(){return d("plugin:http|drop_client",{client:this.id})}async request(t){const n=!t.responseType||t.responseType===e.ResponseType.JSON;return n&&(t.responseType=e.ResponseType.Text),d("plugin:http|request",{clientId:this.id,options:t}).then((e=>{const t=new f(e);if(n){try{t.data=JSON.parse(t.data)}catch(e){if(t.ok&&""===t.data)t.data={};else if(t.ok)throw Error(`Failed to parse response \`${t.data}\` as JSON: ${e};\n try setting the \`responseType\` option to \`ResponseType.Text\` or \`ResponseType.Binary\` if the API does not return a JSON response.`)}return t}return t}))}async get(e,t){return this.request({method:"GET",url:e,...t})}async post(e,t,n){return this.request({method:"POST",url:e,body:t,...n})}async put(e,t,n){return this.request({method:"PUT",url:e,body:t,...n})}async patch(e,t){return this.request({method:"PATCH",url:e,...t})}async delete(e,t){return this.request({method:"DELETE",url:e,...t})}}async function m(e){return d("plugin:http|create_client",{options:e}).then((e=>new y(e)))}let _=null;return e.Body=p,e.Client=y,e.Response=f,e.fetch=async function(e,t){var n;return null===_&&(_=await m()),_.request({url:e,method:null!==(n=null==t?void 0:t.method)&&void 0!==n?n:"GET",...t})},e.getClient=m,e}({});Object.defineProperty(window.__TAURI__,"http",{value:__TAURI_HTTP__})}
if("__TAURI__"in window){var __TAURI_HTTP__=function(e){"use strict";var t;e.ResponseType=void 0,(t=e.ResponseType||(e.ResponseType={}))[t.JSON=1]="JSON",t[t.Text=2]="Text",t[t.Binary=3]="Binary";class r{constructor(e,t){this.type=e,this.payload=t}static form(e){const t={},s=(e,r)=>{if(null!==r){let s;s="string"==typeof r?r:r instanceof Uint8Array||Array.isArray(r)?Array.from(r):r instanceof File?{file:r.name,mime:r.type,fileName:r.name}:"string"==typeof r.file?{file:r.file,mime:r.mime,fileName:r.fileName}:{file:Array.from(r.file),mime:r.mime,fileName:r.fileName},t[String(e)]=s}};if(e instanceof FormData)for(const[t,r]of e)s(t,r);else for(const[t,r]of Object.entries(e))s(t,r);return new r("Form",t)}static json(e){return new r("Json",e)}static text(e){return new r("Text",e)}static bytes(e){return new r("Bytes",Array.from(e instanceof ArrayBuffer?new Uint8Array(e):e))}}class s{constructor(e){this.url=e.url,this.status=e.status,this.ok=this.status>=200&&this.status<300,this.headers=e.headers,this.rawHeaders=e.rawHeaders,this.data=e.data}}class n{constructor(e){this.id=e}async drop(){return window.__TAURI_INVOKE__("plugin:http|drop_client",{client:this.id})}async request(t){const r=!t.responseType||t.responseType===e.ResponseType.JSON;return r&&(t.responseType=e.ResponseType.Text),window.__TAURI_INVOKE__("plugin:http|request",{clientId:this.id,options:t}).then((e=>{const t=new s(e);if(r){try{t.data=JSON.parse(t.data)}catch(e){if(t.ok&&""===t.data)t.data={};else if(t.ok)throw Error(`Failed to parse response \`${t.data}\` as JSON: ${e};\n try setting the \`responseType\` option to \`ResponseType.Text\` or \`ResponseType.Binary\` if the API does not return a JSON response.`)}return t}return t}))}async get(e,t){return this.request({method:"GET",url:e,...t})}async post(e,t,r){return this.request({method:"POST",url:e,body:t,...r})}async put(e,t,r){return this.request({method:"PUT",url:e,body:t,...r})}async patch(e,t){return this.request({method:"PATCH",url:e,...t})}async delete(e,t){return this.request({method:"DELETE",url:e,...t})}}async function i(e){return window.__TAURI_INVOKE__("plugin:http|create_client",{options:e}).then((e=>new n(e)))}let o=null;return e.Body=r,e.Client=n,e.Response=s,e.fetch=async function(e,t){var r;return null===o&&(o=await i()),o.request({url:e,method:null!==(r=null==t?void 0:t.method)&&void 0!==r?r:"GET",...t})},e.getClient=i,e}({});Object.defineProperty(window.__TAURI__,"http",{value:__TAURI_HTTP__})}

@ -1,6 +1,11 @@
import { invoke } from "@tauri-apps/api/tauri";
import { listen, UnlistenFn } from "@tauri-apps/api/event";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
}
}
export type LogOptions = {
file?: string;
line?: number;
@ -57,7 +62,7 @@ async function log(
location = "webview::unknown";
}
await invoke("plugin:log|log", {
await window.__TAURI_INVOKE__("plugin:log|log", {
level,
message,
location,

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_LOG__=function(e){"use strict";var n=Object.defineProperty,t=(e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})},r=(e,n,t)=>{if(!n.has(e))throw TypeError("Cannot "+t)},a=(e,n,t)=>(r(e,n,"read from private field"),t?t.call(e):n.get(e)),i=(e,n,t,a)=>(r(e,n,"write to private field"),a?a.call(e,t):n.set(e,t),t);function o(e,n=!1){let t=window.crypto.getRandomValues(new Uint32Array(1))[0],r=`_${t}`;return Object.defineProperty(window,r,{value:t=>(n&&Reflect.deleteProperty(window,r),e?.(t)),writable:!1,configurable:!0}),t}t({},{Channel:()=>c,PluginListener:()=>s,addPluginListener:()=>u,convertFileSrc:()=>_,invoke:()=>d,transformCallback:()=>o});var l,c=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,n,t)=>{if(n.has(e))throw TypeError("Cannot add the same private member more than once");n instanceof WeakSet?n.add(e):n.set(e,t)})(this,l,(()=>{})),this.id=o((e=>{a(this,l).call(this,e)}))}set onmessage(e){i(this,l,e)}get onmessage(){return a(this,l)}toJSON(){return`__CHANNEL__:${this.id}`}};l=new WeakMap;var s=class{constructor(e,n,t){this.plugin=e,this.event=n,this.channelId=t}async unregister(){return d(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function u(e,n,t){let r=new c;return r.onmessage=t,d(`plugin:${e}|register_listener`,{event:n,handler:r}).then((()=>new s(e,n,r.id)))}async function d(e,n={}){return new Promise(((t,r)=>{let a=o((e=>{t(e),Reflect.deleteProperty(window,`_${i}`)}),!0),i=o((e=>{r(e),Reflect.deleteProperty(window,`_${a}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:a,error:i,...n})}))}function _(e,n="asset"){let t=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${n}.localhost/${t}`:`${n}://localhost/${t}`}async function f(e,n){await d("plugin:event|unlisten",{event:e,eventId:n})}async function w(e,n,t){return d("plugin:event|listen",{event:e,windowLabel:n,handler:o(t)}).then((n=>async()=>f(e,n)))}t({},{TauriEvent:()=>h,emit:()=>p,listen:()=>E,once:()=>y});var v,g,h=((v=h||{}).WINDOW_RESIZED="tauri://resize",v.WINDOW_MOVED="tauri://move",v.WINDOW_CLOSE_REQUESTED="tauri://close-requested",v.WINDOW_CREATED="tauri://window-created",v.WINDOW_DESTROYED="tauri://destroyed",v.WINDOW_FOCUS="tauri://focus",v.WINDOW_BLUR="tauri://blur",v.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",v.WINDOW_THEME_CHANGED="tauri://theme-changed",v.WINDOW_FILE_DROP="tauri://file-drop",v.WINDOW_FILE_DROP_HOVER="tauri://file-drop-hover",v.WINDOW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled",v.MENU="tauri://menu",v);async function E(e,n){return w(e,null,n)}async function y(e,n){return async function(e,n,t){return w(e,n,(n=>{t(n),f(e,n.id).catch((()=>{}))}))}(e,null,n)}async function p(e,n){return async function(e,n,t){await d("plugin:event|emit",{event:e,windowLabel:n,payload:t})}(e,void 0,n)}async function I(e,n,t){var r,a;const i=null===(r=(new Error).stack)||void 0===r?void 0:r.split("\n").map((e=>e.split("@"))),o=null==i?void 0:i.filter((([e,n])=>e.length>0&&"[native code]"!==n)),{file:l,line:c,...s}=null!=t?t:{};let u=null===(a=null==o?void 0:o[0])||void 0===a?void 0:a.filter((e=>e.length>0)).join("@");"Error"===u&&(u="webview::unknown"),await d("plugin:log|log",{level:e,message:n,location:u,file:l,line:c,keyValues:s})}return function(e){e[e.Trace=1]="Trace",e[e.Debug=2]="Debug",e[e.Info=3]="Info",e[e.Warn=4]="Warn",e[e.Error=5]="Error"}(g||(g={})),e.attachConsole=async function(){return await E("log://log",(e=>{const n=e.payload,t=n.message.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,"");switch(n.level){case g.Trace:console.log(t);break;case g.Debug:console.debug(t);break;case g.Info:console.info(t);break;case g.Warn:console.warn(t);break;case g.Error:console.error(t);break;default:throw new Error(`unknown log level ${n.level}`)}}))},e.debug=async function(e,n){await I(g.Debug,e,n)},e.error=async function(e,n){await I(g.Error,e,n)},e.info=async function(e,n){await I(g.Info,e,n)},e.trace=async function(e,n){await I(g.Trace,e,n)},e.warn=async function(e,n){await I(g.Warn,e,n)},e}({});Object.defineProperty(window.__TAURI__,"log",{value:__TAURI_LOG__})}
if("__TAURI__"in window){var __TAURI_LOG__=function(e){"use strict";var n=Object.defineProperty,t=(e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})},r=(e,n,t)=>{if(!n.has(e))throw TypeError("Cannot "+t)},a=(e,n,t)=>(r(e,n,"read from private field"),t?t.call(e):n.get(e)),i=(e,n,t,a)=>(r(e,n,"write to private field"),a?a.call(e,t):n.set(e,t),t);function o(e,n=!1){let t=window.crypto.getRandomValues(new Uint32Array(1))[0],r=`_${t}`;return Object.defineProperty(window,r,{value:t=>(n&&Reflect.deleteProperty(window,r),e?.(t)),writable:!1,configurable:!0}),t}t({},{Channel:()=>c,PluginListener:()=>s,addPluginListener:()=>u,convertFileSrc:()=>_,invoke:()=>d,transformCallback:()=>o});var l,c=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,n,t)=>{if(n.has(e))throw TypeError("Cannot add the same private member more than once");n instanceof WeakSet?n.add(e):n.set(e,t)})(this,l,(()=>{})),this.id=o((e=>{a(this,l).call(this,e)}))}set onmessage(e){i(this,l,e)}get onmessage(){return a(this,l)}toJSON(){return`__CHANNEL__:${this.id}`}};l=new WeakMap;var s=class{constructor(e,n,t){this.plugin=e,this.event=n,this.channelId=t}async unregister(){return d(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function u(e,n,t){let r=new c;return r.onmessage=t,d(`plugin:${e}|register_listener`,{event:n,handler:r}).then((()=>new s(e,n,r.id)))}async function d(e,n={}){return new Promise(((t,r)=>{let a=o((e=>{t(e),Reflect.deleteProperty(window,`_${i}`)}),!0),i=o((e=>{r(e),Reflect.deleteProperty(window,`_${a}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:a,error:i,...n})}))}function _(e,n="asset"){let t=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${n}.localhost/${t}`:`${n}://localhost/${t}`}async function w(e,n){await d("plugin:event|unlisten",{event:e,eventId:n})}async function f(e,n,t){return d("plugin:event|listen",{event:e,windowLabel:n,handler:o(t)}).then((n=>async()=>w(e,n)))}t({},{TauriEvent:()=>h,emit:()=>y,listen:()=>E,once:()=>I});var v,g,h=((v=h||{}).WINDOW_RESIZED="tauri://resize",v.WINDOW_MOVED="tauri://move",v.WINDOW_CLOSE_REQUESTED="tauri://close-requested",v.WINDOW_CREATED="tauri://window-created",v.WINDOW_DESTROYED="tauri://destroyed",v.WINDOW_FOCUS="tauri://focus",v.WINDOW_BLUR="tauri://blur",v.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",v.WINDOW_THEME_CHANGED="tauri://theme-changed",v.WINDOW_FILE_DROP="tauri://file-drop",v.WINDOW_FILE_DROP_HOVER="tauri://file-drop-hover",v.WINDOW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled",v.MENU="tauri://menu",v);async function E(e,n){return f(e,null,n)}async function I(e,n){return async function(e,n,t){return f(e,n,(n=>{t(n),w(e,n.id).catch((()=>{}))}))}(e,null,n)}async function y(e,n){return async function(e,n,t){await d("plugin:event|emit",{event:e,windowLabel:n,payload:t})}(e,void 0,n)}async function p(e,n,t){var r,a;const i=null===(r=(new Error).stack)||void 0===r?void 0:r.split("\n").map((e=>e.split("@"))),o=null==i?void 0:i.filter((([e,n])=>e.length>0&&"[native code]"!==n)),{file:l,line:c,...s}=null!=t?t:{};let u=null===(a=null==o?void 0:o[0])||void 0===a?void 0:a.filter((e=>e.length>0)).join("@");"Error"===u&&(u="webview::unknown"),await window.__TAURI_INVOKE__("plugin:log|log",{level:e,message:n,location:u,file:l,line:c,keyValues:s})}return function(e){e[e.Trace=1]="Trace",e[e.Debug=2]="Debug",e[e.Info=3]="Info",e[e.Warn=4]="Warn",e[e.Error=5]="Error"}(g||(g={})),e.attachConsole=async function(){return await E("log://log",(e=>{const n=e.payload,t=n.message.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,"");switch(n.level){case g.Trace:console.log(t);break;case g.Debug:console.debug(t);break;case g.Info:console.info(t);break;case g.Warn:console.warn(t);break;case g.Error:console.error(t);break;default:throw new Error(`unknown log level ${n.level}`)}}))},e.debug=async function(e,n){await p(g.Debug,e,n)},e.error=async function(e,n){await p(g.Error,e,n)},e.info=async function(e,n){await p(g.Info,e,n)},e.trace=async function(e,n){await p(g.Trace,e,n)},e.warn=async function(e,n){await p(g.Warn,e,n)},e}({});Object.defineProperty(window.__TAURI__,"log",{value:__TAURI_LOG__})}

@ -8,7 +8,11 @@
* @module
*/
import { invoke } from "@tauri-apps/api/tauri";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
}
}
type Platform =
| "linux"
@ -63,7 +67,7 @@ const EOL = isWindows() ? "\r\n" : "\n";
*
*/
async function platform(): Promise<Platform> {
return invoke("plugin:os|platform");
return window.__TAURI_INVOKE__("plugin:os|platform");
}
/**
@ -77,7 +81,7 @@ async function platform(): Promise<Platform> {
* @since 1.0.0
*/
async function version(): Promise<string> {
return invoke("plugin:os|version");
return window.__TAURI_INVOKE__("plugin:os|version");
}
/**
@ -91,7 +95,7 @@ async function version(): Promise<string> {
* @since 1.0.0
*/
async function type(): Promise<OsType> {
return invoke("plugin:os|kind");
return window.__TAURI_INVOKE__("plugin:os|kind");
}
/**
@ -106,7 +110,7 @@ async function type(): Promise<OsType> {
* @since 1.0.0
*/
async function arch(): Promise<Arch> {
return invoke("plugin:os|arch");
return window.__TAURI_INVOKE__("plugin:os|arch");
}
/**
@ -120,7 +124,7 @@ async function arch(): Promise<Arch> {
* @since 1.0.0
*/
async function tempdir(): Promise<string> {
return invoke("plugin:os|tempdir");
return window.__TAURI_INVOKE__("plugin:os|tempdir");
}
export { EOL, platform, version, type, arch, tempdir };

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_OS__=function(e){"use strict";var n=Object.defineProperty,t=(e,n,t)=>{if(!n.has(e))throw TypeError("Cannot "+t)},r=(e,n,r)=>(t(e,n,"read from private field"),r?r.call(e):n.get(e)),i=(e,n,r,i)=>(t(e,n,"write to private field"),i?i.call(e,r):n.set(e,r),r);function o(e,n=!1){let t=window.crypto.getRandomValues(new Uint32Array(1))[0],r=`_${t}`;return Object.defineProperty(window,r,{value:t=>(n&&Reflect.deleteProperty(window,r),e?.(t)),writable:!1,configurable:!0}),t}((e,t)=>{for(var r in t)n(e,r,{get:t[r],enumerable:!0})})({},{Channel:()=>a,PluginListener:()=>l,addPluginListener:()=>c,convertFileSrc:()=>d,invoke:()=>u,transformCallback:()=>o});var s,a=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,n,t)=>{if(n.has(e))throw TypeError("Cannot add the same private member more than once");n instanceof WeakSet?n.add(e):n.set(e,t)})(this,s,(()=>{})),this.id=o((e=>{r(this,s).call(this,e)}))}set onmessage(e){i(this,s,e)}get onmessage(){return r(this,s)}toJSON(){return`__CHANNEL__:${this.id}`}};s=new WeakMap;var l=class{constructor(e,n,t){this.plugin=e,this.event=n,this.channelId=t}async unregister(){return u(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function c(e,n,t){let r=new a;return r.onmessage=t,u(`plugin:${e}|register_listener`,{event:n,handler:r}).then((()=>new l(e,n,r.id)))}async function u(e,n={}){return new Promise(((t,r)=>{let i=o((e=>{t(e),Reflect.deleteProperty(window,`_${s}`)}),!0),s=o((e=>{r(e),Reflect.deleteProperty(window,`_${i}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:i,error:s,...n})}))}function d(e,n="asset"){let t=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${n}.localhost/${t}`:`${n}://localhost/${t}`}const _=navigator.appVersion.includes("Win")?"\r\n":"\n";return e.EOL=_,e.arch=async function(){return u("plugin:os|arch")},e.platform=async function(){return u("plugin:os|platform")},e.tempdir=async function(){return u("plugin:os|tempdir")},e.type=async function(){return u("plugin:os|kind")},e.version=async function(){return u("plugin:os|version")},e}({});Object.defineProperty(window.__TAURI__,"os",{value:__TAURI_OS__})}
if("__TAURI__"in window){var __TAURI_OS__=function(n){"use strict";const _=navigator.appVersion.includes("Win")?"\r\n":"\n";return n.EOL=_,n.arch=async function(){return window.__TAURI_INVOKE__("plugin:os|arch")},n.platform=async function(){return window.__TAURI_INVOKE__("plugin:os|platform")},n.tempdir=async function(){return window.__TAURI_INVOKE__("plugin:os|tempdir")},n.type=async function(){return window.__TAURI_INVOKE__("plugin:os|kind")},n.version=async function(){return window.__TAURI_INVOKE__("plugin:os|version")},n}({});Object.defineProperty(window.__TAURI__,"os",{value:__TAURI_OS__})}

@ -1,7 +1,11 @@
// Copyright 2021 Jonas Kruckenberg
// SPDX-License-Identifier: MIT
import { invoke } from "@tauri-apps/api/tauri";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
}
}
/**
* Well known window positions.
@ -31,7 +35,7 @@ export enum Position {
* @param to The {@link Position} to move to.
*/
export async function moveWindow(to: Position): Promise<void> {
await invoke("plugin:positioner|move_window", {
await window.__TAURI_INVOKE__("plugin:positioner|move_window", {
position: to,
});
}

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_POSITIONER__=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)),o=(e,t,r,o)=>(n(e,t,"write to private field"),o?o.call(e,r):t.set(e,r),r);function i(e,t=!1){let n=window.crypto.getRandomValues(new Uint32Array(1))[0],r=`_${n}`;return Object.defineProperty(window,r,{value:n=>(t&&Reflect.deleteProperty(window,r),e?.(n)),writable:!1,configurable:!0}),n}((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})({},{Channel:()=>s,PluginListener:()=>c,addPluginListener:()=>h,convertFileSrc:()=>d,invoke:()=>_,transformCallback:()=>i});var a,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,a,(()=>{})),this.id=i((e=>{r(this,a).call(this,e)}))}set onmessage(e){o(this,a,e)}get onmessage(){return r(this,a)}toJSON(){return`__CHANNEL__:${this.id}`}};a=new WeakMap;var l,c=class{constructor(e,t,n){this.plugin=e,this.event=t,this.channelId=n}async unregister(){return _(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function h(e,t,n){let r=new s;return r.onmessage=n,_(`plugin:${e}|register_listener`,{event:t,handler:r}).then((()=>new c(e,t,r.id)))}async function _(e,t={}){return new Promise(((n,r)=>{let o=i((e=>{n(e),Reflect.deleteProperty(window,`_${a}`)}),!0),a=i((e=>{r(e),Reflect.deleteProperty(window,`_${o}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:o,error:a,...t})}))}function d(e,t="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${t}.localhost/${n}`:`${t}://localhost/${n}`}return e.Position=void 0,(l=e.Position||(e.Position={}))[l.TopLeft=0]="TopLeft",l[l.TopRight=1]="TopRight",l[l.BottomLeft=2]="BottomLeft",l[l.BottomRight=3]="BottomRight",l[l.TopCenter=4]="TopCenter",l[l.BottomCenter=5]="BottomCenter",l[l.LeftCenter=6]="LeftCenter",l[l.RightCenter=7]="RightCenter",l[l.Center=8]="Center",l[l.TrayLeft=9]="TrayLeft",l[l.TrayBottomLeft=10]="TrayBottomLeft",l[l.TrayRight=11]="TrayRight",l[l.TrayBottomRight=12]="TrayBottomRight",l[l.TrayCenter=13]="TrayCenter",l[l.TrayBottomCenter=14]="TrayBottomCenter",e.moveWindow=async function(e){await _("plugin:positioner|move_window",{position:e})},e}({});Object.defineProperty(window.__TAURI__,"positioner",{value:__TAURI_POSITIONER__})}
if("__TAURI__"in window){var __TAURI_POSITIONER__=function(t){"use strict";var o;return t.Position=void 0,(o=t.Position||(t.Position={}))[o.TopLeft=0]="TopLeft",o[o.TopRight=1]="TopRight",o[o.BottomLeft=2]="BottomLeft",o[o.BottomRight=3]="BottomRight",o[o.TopCenter=4]="TopCenter",o[o.BottomCenter=5]="BottomCenter",o[o.LeftCenter=6]="LeftCenter",o[o.RightCenter=7]="RightCenter",o[o.Center=8]="Center",o[o.TrayLeft=9]="TrayLeft",o[o.TrayBottomLeft=10]="TrayBottomLeft",o[o.TrayRight=11]="TrayRight",o[o.TrayBottomRight=12]="TrayBottomRight",o[o.TrayCenter=13]="TrayCenter",o[o.TrayBottomCenter=14]="TrayBottomCenter",t.moveWindow=async function(t){await window.__TAURI_INVOKE__("plugin:positioner|move_window",{position:t})},t}({});Object.defineProperty(window.__TAURI__,"positioner",{value:__TAURI_POSITIONER__})}

@ -7,7 +7,11 @@
* @module
*/
import { invoke } from "@tauri-apps/api/tauri";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
}
}
/**
* Exits immediately with the given `exitCode`.
@ -23,7 +27,7 @@ import { invoke } from "@tauri-apps/api/tauri";
* @since 1.0.0
*/
async function exit(code = 0): Promise<void> {
return invoke("plugin:process|exit", { code });
return window.__TAURI_INVOKE__("plugin:process|exit", { code });
}
/**
@ -39,7 +43,7 @@ async function exit(code = 0): Promise<void> {
* @since 1.0.0
*/
async function relaunch(): Promise<void> {
return invoke("plugin:process|restart");
return window.__TAURI_INVOKE__("plugin:process|restart");
}
export { exit, relaunch };

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_PROCESS__=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)),i=(e,t,r,i)=>(n(e,t,"write to private field"),i?i.call(e,r):t.set(e,r),r);function s(e,t=!1){let n=window.crypto.getRandomValues(new Uint32Array(1))[0],r=`_${n}`;return Object.defineProperty(window,r,{value:n=>(t&&Reflect.deleteProperty(window,r),e?.(n)),writable:!1,configurable:!0}),n}((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})({},{Channel:()=>a,PluginListener:()=>l,addPluginListener:()=>c,convertFileSrc:()=>u,invoke:()=>_,transformCallback:()=>s});var o,a=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,o,(()=>{})),this.id=s((e=>{r(this,o).call(this,e)}))}set onmessage(e){i(this,o,e)}get onmessage(){return r(this,o)}toJSON(){return`__CHANNEL__:${this.id}`}};o=new WeakMap;var l=class{constructor(e,t,n){this.plugin=e,this.event=t,this.channelId=n}async unregister(){return _(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function c(e,t,n){let r=new a;return r.onmessage=n,_(`plugin:${e}|register_listener`,{event:t,handler:r}).then((()=>new l(e,t,r.id)))}async function _(e,t={}){return new Promise(((n,r)=>{let i=s((e=>{n(e),Reflect.deleteProperty(window,`_${o}`)}),!0),o=s((e=>{r(e),Reflect.deleteProperty(window,`_${i}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:i,error:o,...t})}))}function u(e,t="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${t}.localhost/${n}`:`${t}://localhost/${n}`}return e.exit=async function(e=0){return _("plugin:process|exit",{code:e})},e.relaunch=async function(){return _("plugin:process|restart")},e}({});Object.defineProperty(window.__TAURI__,"process",{value:__TAURI_PROCESS__})}
if("__TAURI__"in window){var __TAURI_PROCESS__=function(_){"use strict";return _.exit=async function(_=0){return window.__TAURI_INVOKE__("plugin:process|exit",{code:_})},_.relaunch=async function(){return window.__TAURI_INVOKE__("plugin:process|restart")},_}({});Object.defineProperty(window.__TAURI__,"process",{value:__TAURI_PROCESS__})}

@ -62,7 +62,14 @@
* @module
*/
import { invoke, transformCallback } from "@tauri-apps/api/tauri";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
__TAURI__: {
transformCallback: <T>(cb: (payload: T) => void) => number;
};
}
}
/**
* @since 1.0.0
@ -119,11 +126,11 @@ async function execute<O extends IOPayload>(
Object.freeze(args);
}
return invoke<number>("plugin:shell|execute", {
return window.__TAURI_INVOKE__<number>("plugin:shell|execute", {
program,
args,
options,
onEventFn: transformCallback(onEvent),
onEventFn: window.__TAURI__.transformCallback(onEvent),
});
}
@ -345,7 +352,7 @@ class Child {
* @returns A promise indicating the success or failure of the operation.
*/
async write(data: IOPayload): Promise<void> {
return invoke("plugin:shell|stdin_write", {
return window.__TAURI_INVOKE__("plugin:shell|stdin_write", {
pid: this.pid,
// correctly serialize Uint8Arrays
buffer: typeof data === "string" ? data : Array.from(data),
@ -358,7 +365,7 @@ class Child {
* @returns A promise indicating the success or failure of the operation.
*/
async kill(): Promise<void> {
return invoke("plugin:shell|kill", {
return window.__TAURI_INVOKE__("plugin:shell|kill", {
cmd: "killChild",
pid: this.pid,
});
@ -629,7 +636,7 @@ type CommandEvent<O extends IOPayload> =
* @since 1.0.0
*/
async function open(path: string, openWith?: string): Promise<void> {
return invoke("plugin:shell|open", {
return window.__TAURI_INVOKE__("plugin:shell|open", {
path,
with: openWith,
});

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_SHELL__=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)),s=(e,t,r,s)=>(n(e,t,"write to private field"),s?s.call(e,r):t.set(e,r),r);function i(e,t=!1){let n=window.crypto.getRandomValues(new Uint32Array(1))[0],r=`_${n}`;return Object.defineProperty(window,r,{value:n=>(t&&Reflect.deleteProperty(window,r),e?.(n)),writable:!1,configurable:!0}),n}((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})({},{Channel:()=>a,PluginListener:()=>l,addPluginListener:()=>c,convertFileSrc:()=>u,invoke:()=>h,transformCallback:()=>i});var o,a=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,o,(()=>{})),this.id=i((e=>{r(this,o).call(this,e)}))}set onmessage(e){s(this,o,e)}get onmessage(){return r(this,o)}toJSON(){return`__CHANNEL__:${this.id}`}};o=new WeakMap;var l=class{constructor(e,t,n){this.plugin=e,this.event=t,this.channelId=n}async unregister(){return h(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function c(e,t,n){let r=new a;return r.onmessage=n,h(`plugin:${e}|register_listener`,{event:t,handler:r}).then((()=>new l(e,t,r.id)))}async function h(e,t={}){return new Promise(((n,r)=>{let s=i((e=>{n(e),Reflect.deleteProperty(window,`_${o}`)}),!0),o=i((e=>{r(e),Reflect.deleteProperty(window,`_${s}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:s,error:o,...t})}))}function u(e,t="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${t}.localhost/${n}`:`${t}://localhost/${n}`}class d{constructor(){this.eventListeners=Object.create(null)}addListener(e,t){return this.on(e,t)}removeListener(e,t){return this.off(e,t)}on(e,t){return e in this.eventListeners?this.eventListeners[e].push(t):this.eventListeners[e]=[t],this}once(e,t){const n=r=>{this.removeListener(e,n),t(r)};return this.addListener(e,n)}off(e,t){return e in this.eventListeners&&(this.eventListeners[e]=this.eventListeners[e].filter((e=>e!==t))),this}removeAllListeners(e){return e?delete this.eventListeners[e]:this.eventListeners=Object.create(null),this}emit(e,t){if(e in this.eventListeners){const n=this.eventListeners[e];for(const e of n)e(t);return!0}return!1}listenerCount(e){return e in this.eventListeners?this.eventListeners[e].length:0}prependListener(e,t){return e in this.eventListeners?this.eventListeners[e].unshift(t):this.eventListeners[e]=[t],this}prependOnceListener(e,t){const n=r=>{this.removeListener(e,n),t(r)};return this.prependListener(e,n)}}class p{constructor(e){this.pid=e}async write(e){return h("plugin:shell|stdin_write",{pid:this.pid,buffer:"string"==typeof e?e:Array.from(e)})}async kill(){return h("plugin:shell|kill",{cmd:"killChild",pid:this.pid})}}class v extends d{constructor(e,t=[],n){super(),this.stdout=new d,this.stderr=new d,this.program=e,this.args="string"==typeof t?[t]:t,this.options=null!=n?n:{}}static create(e,t=[],n){return new v(e,t,n)}static sidecar(e,t=[],n){const r=new v(e,t,n);return r.options.sidecar=!0,r}async spawn(){return async function(e,t,n=[],r){return"object"==typeof n&&Object.freeze(n),h("plugin:shell|execute",{program:t,args:n,options:r,onEventFn:i(e)})}((e=>{switch(e.event){case"Error":this.emit("error",e.payload);break;case"Terminated":this.emit("close",e.payload);break;case"Stdout":this.stdout.emit("data",e.payload);break;case"Stderr":this.stderr.emit("data",e.payload)}}),this.program,this.args,this.options).then((e=>new p(e)))}async execute(){return new Promise(((e,t)=>{this.on("error",t);const n=[],r=[];this.stdout.on("data",(e=>{n.push(e)})),this.stderr.on("data",(e=>{r.push(e)})),this.on("close",(t=>{e({code:t.code,signal:t.signal,stdout:this.collectOutput(n),stderr:this.collectOutput(r)})})),this.spawn().catch(t)}))}collectOutput(e){return"raw"===this.options.encoding?e.reduce(((e,t)=>new Uint8Array([...e,...t,10])),new Uint8Array):e.join("\n")}}return e.Child=p,e.Command=v,e.EventEmitter=d,e.open=async function(e,t){return h("plugin:shell|open",{path:e,with:t})},e}({});Object.defineProperty(window.__TAURI__,"shell",{value:__TAURI_SHELL__})}
if("__TAURI__"in window){var __TAURI_SHELL__=function(e){"use strict";class t{constructor(){this.eventListeners=Object.create(null)}addListener(e,t){return this.on(e,t)}removeListener(e,t){return this.off(e,t)}on(e,t){return e in this.eventListeners?this.eventListeners[e].push(t):this.eventListeners[e]=[t],this}once(e,t){const s=n=>{this.removeListener(e,s),t(n)};return this.addListener(e,s)}off(e,t){return e in this.eventListeners&&(this.eventListeners[e]=this.eventListeners[e].filter((e=>e!==t))),this}removeAllListeners(e){return e?delete this.eventListeners[e]:this.eventListeners=Object.create(null),this}emit(e,t){if(e in this.eventListeners){const s=this.eventListeners[e];for(const e of s)e(t);return!0}return!1}listenerCount(e){return e in this.eventListeners?this.eventListeners[e].length:0}prependListener(e,t){return e in this.eventListeners?this.eventListeners[e].unshift(t):this.eventListeners[e]=[t],this}prependOnceListener(e,t){const s=n=>{this.removeListener(e,s),t(n)};return this.prependListener(e,s)}}class s{constructor(e){this.pid=e}async write(e){return window.__TAURI_INVOKE__("plugin:shell|stdin_write",{pid:this.pid,buffer:"string"==typeof e?e:Array.from(e)})}async kill(){return window.__TAURI_INVOKE__("plugin:shell|kill",{cmd:"killChild",pid:this.pid})}}class n extends t{constructor(e,s=[],n){super(),this.stdout=new t,this.stderr=new t,this.program=e,this.args="string"==typeof s?[s]:s,this.options=null!=n?n:{}}static create(e,t=[],s){return new n(e,t,s)}static sidecar(e,t=[],s){const r=new n(e,t,s);return r.options.sidecar=!0,r}async spawn(){return async function(e,t,s=[],n){return"object"==typeof s&&Object.freeze(s),window.__TAURI_INVOKE__("plugin:shell|execute",{program:t,args:s,options:n,onEventFn:window.__TAURI__.transformCallback(e)})}((e=>{switch(e.event){case"Error":this.emit("error",e.payload);break;case"Terminated":this.emit("close",e.payload);break;case"Stdout":this.stdout.emit("data",e.payload);break;case"Stderr":this.stderr.emit("data",e.payload)}}),this.program,this.args,this.options).then((e=>new s(e)))}async execute(){return new Promise(((e,t)=>{this.on("error",t);const s=[],n=[];this.stdout.on("data",(e=>{s.push(e)})),this.stderr.on("data",(e=>{n.push(e)})),this.on("close",(t=>{e({code:t.code,signal:t.signal,stdout:this.collectOutput(s),stderr:this.collectOutput(n)})})),this.spawn().catch(t)}))}collectOutput(e){return"raw"===this.options.encoding?e.reduce(((e,t)=>new Uint8Array([...e,...t,10])),new Uint8Array):e.join("\n")}}return e.Child=s,e.Command=n,e.EventEmitter=t,e.open=async function(e,t){return window.__TAURI_INVOKE__("plugin:shell|open",{path:e,with:t})},e}({});Object.defineProperty(window.__TAURI__,"shell",{value:__TAURI_SHELL__})}

@ -1,4 +1,8 @@
import { invoke } from "@tauri-apps/api/tauri";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
}
}
export interface QueryResult {
/** The number of rows affected by the query. */
@ -42,7 +46,7 @@ export default class Database {
* ```
*/
static async load(path: string): Promise<Database> {
const _path = await invoke<string>("plugin:sql|load", {
const _path = await window.__TAURI_INVOKE__<string>("plugin:sql|load", {
db: path,
});
@ -83,14 +87,13 @@ export default class Database {
* ```
*/
async execute(query: string, bindValues?: unknown[]): Promise<QueryResult> {
const [rowsAffected, lastInsertId] = await invoke<[number, number]>(
"plugin:sql|execute",
{
db: this.path,
query,
values: bindValues ?? [],
}
);
const [rowsAffected, lastInsertId] = await window.__TAURI_INVOKE__<
[number, number]
>("plugin:sql|execute", {
db: this.path,
query,
values: bindValues ?? [],
});
return {
lastInsertId,
@ -111,7 +114,7 @@ export default class Database {
* ```
*/
async select<T>(query: string, bindValues?: unknown[]): Promise<T> {
const result = await invoke<T>("plugin:sql|select", {
const result = await window.__TAURI_INVOKE__<T>("plugin:sql|select", {
db: this.path,
query,
values: bindValues ?? [],
@ -132,7 +135,7 @@ export default class Database {
* @param db - Optionally state the name of a database if you are managing more than one. Otherwise, all database pools will be in scope.
*/
async close(db?: string): Promise<boolean> {
const success = await invoke<boolean>("plugin:sql|close", {
const success = await window.__TAURI_INVOKE__<boolean>("plugin:sql|close", {
db,
});
return success;

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_SQL__=function(){"use strict";var e=Object.defineProperty,t=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},n=(e,n,r)=>(t(e,n,"read from private field"),r?r.call(e):n.get(e)),r=(e,n,r,s)=>(t(e,n,"write to private field"),s?s.call(e,r):n.set(e,r),r);function s(e,t=!1){let n=window.crypto.getRandomValues(new Uint32Array(1))[0],r=`_${n}`;return Object.defineProperty(window,r,{value:n=>(t&&Reflect.deleteProperty(window,r),e?.(n)),writable:!1,configurable:!0}),n}((t,n)=>{for(var r in n)e(t,r,{get:n[r],enumerable:!0})})({},{Channel:()=>a,PluginListener:()=>l,addPluginListener:()=>o,convertFileSrc:()=>u,invoke:()=>c,transformCallback:()=>s});var i,a=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=s((e=>{n(this,i).call(this,e)}))}set onmessage(e){r(this,i,e)}get onmessage(){return n(this,i)}toJSON(){return`__CHANNEL__:${this.id}`}};i=new WeakMap;var l=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 o(e,t,n){let r=new a;return r.onmessage=n,c(`plugin:${e}|register_listener`,{event:t,handler:r}).then((()=>new l(e,t,r.id)))}async function c(e,t={}){return new Promise(((n,r)=>{let i=s((e=>{n(e),Reflect.deleteProperty(window,`_${a}`)}),!0),a=s((e=>{r(e),Reflect.deleteProperty(window,`_${i}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:i,error:a,...t})}))}function u(e,t="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${t}.localhost/${n}`:`${t}://localhost/${n}`}class d{constructor(e){this.path=e}static async load(e){const t=await c("plugin:sql|load",{db:e});return new d(t)}static get(e){return new d(e)}async execute(e,t){const[n,r]=await c("plugin:sql|execute",{db:this.path,query:e,values:null!=t?t:[]});return{lastInsertId:r,rowsAffected:n}}async select(e,t){return await c("plugin:sql|select",{db:this.path,query:e,values:null!=t?t:[]})}async close(e){return await c("plugin:sql|close",{db:e})}}return d}();Object.defineProperty(window.__TAURI__,"sql",{value:__TAURI_SQL__})}
if("__TAURI__"in window){var __TAURI_SQL__=function(){"use strict";class _{constructor(_){this.path=_}static async load(t){const e=await window.__TAURI_INVOKE__("plugin:sql|load",{db:t});return new _(e)}static get(t){return new _(t)}async execute(_,t){const[e,n]=await window.__TAURI_INVOKE__("plugin:sql|execute",{db:this.path,query:_,values:null!=t?t:[]});return{lastInsertId:n,rowsAffected:e}}async select(_,t){return await window.__TAURI_INVOKE__("plugin:sql|select",{db:this.path,query:_,values:null!=t?t:[]})}async close(_){return await window.__TAURI_INVOKE__("plugin:sql|close",{db:_})}}return _}();Object.defineProperty(window.__TAURI__,"sql",{value:__TAURI_SQL__})}

@ -2,9 +2,14 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { invoke } from "@tauri-apps/api/tauri";
import { listen, UnlistenFn } from "@tauri-apps/api/event";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
}
}
interface ChangePayload<T> {
path: string;
key: string;
@ -28,7 +33,7 @@ export class Store {
* @returns
*/
async set(key: string, value: unknown): Promise<void> {
return await invoke("plugin:store|set", {
return await window.__TAURI_INVOKE__("plugin:store|set", {
path: this.path,
key,
value,
@ -42,7 +47,7 @@ export class Store {
* @returns
*/
async get<T>(key: string): Promise<T | null> {
return await invoke("plugin:store|get", {
return await window.__TAURI_INVOKE__("plugin:store|get", {
path: this.path,
key,
});
@ -55,7 +60,7 @@ export class Store {
* @returns
*/
async has(key: string): Promise<boolean> {
return await invoke("plugin:store|has", {
return await window.__TAURI_INVOKE__("plugin:store|has", {
path: this.path,
key,
});
@ -68,7 +73,7 @@ export class Store {
* @returns
*/
async delete(key: string): Promise<boolean> {
return await invoke("plugin:store|delete", {
return await window.__TAURI_INVOKE__("plugin:store|delete", {
path: this.path,
key,
});
@ -81,7 +86,7 @@ export class Store {
* @returns
*/
async clear(): Promise<void> {
return await invoke("plugin:store|clear", {
return await window.__TAURI_INVOKE__("plugin:store|clear", {
path: this.path,
});
}
@ -93,7 +98,7 @@ export class Store {
* @returns
*/
async reset(): Promise<void> {
return await invoke("plugin:store|reset", {
return await window.__TAURI_INVOKE__("plugin:store|reset", {
path: this.path,
});
}
@ -104,7 +109,7 @@ export class Store {
* @returns
*/
async keys(): Promise<string[]> {
return await invoke("plugin:store|keys", {
return await window.__TAURI_INVOKE__("plugin:store|keys", {
path: this.path,
});
}
@ -115,7 +120,7 @@ export class Store {
* @returns
*/
async values<T>(): Promise<T[]> {
return await invoke("plugin:store|values", {
return await window.__TAURI_INVOKE__("plugin:store|values", {
path: this.path,
});
}
@ -126,7 +131,7 @@ export class Store {
* @returns
*/
async entries<T>(): Promise<Array<[key: string, value: T]>> {
return await invoke("plugin:store|entries", {
return await window.__TAURI_INVOKE__("plugin:store|entries", {
path: this.path,
});
}
@ -137,7 +142,7 @@ export class Store {
* @returns
*/
async length(): Promise<number> {
return await invoke("plugin:store|length", {
return await window.__TAURI_INVOKE__("plugin:store|length", {
path: this.path,
});
}
@ -151,7 +156,7 @@ export class Store {
* @returns
*/
async load(): Promise<void> {
return await invoke("plugin:store|load", {
return await window.__TAURI_INVOKE__("plugin:store|load", {
path: this.path,
});
}
@ -164,7 +169,7 @@ export class Store {
* @returns
*/
async save(): Promise<void> {
return await invoke("plugin:store|save", {
return await window.__TAURI_INVOKE__("plugin:store|save", {
path: this.path,
});
}

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_STORE__=function(e){"use strict";var t=Object.defineProperty,n=(e,n)=>{for(var a in n)t(e,a,{get:n[a],enumerable:!0})},a=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},r=(e,t,n)=>(a(e,t,"read from private field"),n?n.call(e):t.get(e)),i=(e,t,n,r)=>(a(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n);function s(e,t=!1){let n=window.crypto.getRandomValues(new Uint32Array(1))[0],a=`_${n}`;return Object.defineProperty(window,a,{value:n=>(t&&Reflect.deleteProperty(window,a),e?.(n)),writable:!1,configurable:!0}),n}n({},{Channel:()=>l,PluginListener:()=>u,addPluginListener:()=>c,convertFileSrc:()=>p,invoke:()=>h,transformCallback:()=>s});var o,l=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,o,(()=>{})),this.id=s((e=>{r(this,o).call(this,e)}))}set onmessage(e){i(this,o,e)}get onmessage(){return r(this,o)}toJSON(){return`__CHANNEL__:${this.id}`}};o=new WeakMap;var u=class{constructor(e,t,n){this.plugin=e,this.event=t,this.channelId=n}async unregister(){return h(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function c(e,t,n){let a=new l;return a.onmessage=n,h(`plugin:${e}|register_listener`,{event:t,handler:a}).then((()=>new u(e,t,a.id)))}async function h(e,t={}){return new Promise(((n,a)=>{let r=s((e=>{n(e),Reflect.deleteProperty(window,`_${i}`)}),!0),i=s((e=>{a(e),Reflect.deleteProperty(window,`_${r}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:r,error:i,...t})}))}function p(e,t="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${t}.localhost/${n}`:`${t}://localhost/${n}`}async function d(e,t){await h("plugin:event|unlisten",{event:e,eventId:t})}async function _(e,t,n){return h("plugin:event|listen",{event:e,windowLabel:t,handler:s(n)}).then((t=>async()=>d(e,t)))}n({},{TauriEvent:()=>w,emit:()=>f,listen:()=>g,once:()=>v});var y,w=((y=w||{}).WINDOW_RESIZED="tauri://resize",y.WINDOW_MOVED="tauri://move",y.WINDOW_CLOSE_REQUESTED="tauri://close-requested",y.WINDOW_CREATED="tauri://window-created",y.WINDOW_DESTROYED="tauri://destroyed",y.WINDOW_FOCUS="tauri://focus",y.WINDOW_BLUR="tauri://blur",y.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",y.WINDOW_THEME_CHANGED="tauri://theme-changed",y.WINDOW_FILE_DROP="tauri://file-drop",y.WINDOW_FILE_DROP_HOVER="tauri://file-drop-hover",y.WINDOW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled",y.MENU="tauri://menu",y);async function g(e,t){return _(e,null,t)}async function v(e,t){return async function(e,t,n){return _(e,t,(t=>{n(t),d(e,t.id).catch((()=>{}))}))}(e,null,t)}async function f(e,t){return async function(e,t,n){await h("plugin:event|emit",{event:e,windowLabel:t,payload:n})}(e,void 0,t)}return e.Store=class{constructor(e){this.path=e}async set(e,t){return await h("plugin:store|set",{path:this.path,key:e,value:t})}async get(e){return await h("plugin:store|get",{path:this.path,key:e})}async has(e){return await h("plugin:store|has",{path:this.path,key:e})}async delete(e){return await h("plugin:store|delete",{path:this.path,key:e})}async clear(){return await h("plugin:store|clear",{path:this.path})}async reset(){return await h("plugin:store|reset",{path:this.path})}async keys(){return await h("plugin:store|keys",{path:this.path})}async values(){return await h("plugin:store|values",{path:this.path})}async entries(){return await h("plugin:store|entries",{path:this.path})}async length(){return await h("plugin:store|length",{path:this.path})}async load(){return await h("plugin:store|load",{path:this.path})}async save(){return await h("plugin:store|save",{path:this.path})}async onKeyChange(e,t){return await g("store://change",(n=>{n.payload.path===this.path&&n.payload.key===e&&t(n.payload.value)}))}async onChange(e){return await g("store://change",(t=>{t.payload.path===this.path&&e(t.payload.key,t.payload.value)}))}},e}({});Object.defineProperty(window.__TAURI__,"store",{value:__TAURI_STORE__})}
if("__TAURI__"in window){var __TAURI_STORE__=function(e){"use strict";var t=Object.defineProperty,n=(e,n)=>{for(var a in n)t(e,a,{get:n[a],enumerable:!0})},a=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},r=(e,t,n)=>(a(e,t,"read from private field"),n?n.call(e):t.get(e)),i=(e,t,n,r)=>(a(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n);function s(e,t=!1){let n=window.crypto.getRandomValues(new Uint32Array(1))[0],a=`_${n}`;return Object.defineProperty(window,a,{value:n=>(t&&Reflect.deleteProperty(window,a),e?.(n)),writable:!1,configurable:!0}),n}n({},{Channel:()=>o,PluginListener:()=>l,addPluginListener:()=>u,convertFileSrc:()=>h,invoke:()=>c,transformCallback:()=>s});var _,o=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,_,(()=>{})),this.id=s((e=>{r(this,_).call(this,e)}))}set onmessage(e){i(this,_,e)}get onmessage(){return r(this,_)}toJSON(){return`__CHANNEL__:${this.id}`}};_=new WeakMap;var l=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 u(e,t,n){let a=new o;return a.onmessage=n,c(`plugin:${e}|register_listener`,{event:t,handler:a}).then((()=>new l(e,t,a.id)))}async function c(e,t={}){return new Promise(((n,a)=>{let r=s((e=>{n(e),Reflect.deleteProperty(window,`_${i}`)}),!0),i=s((e=>{a(e),Reflect.deleteProperty(window,`_${r}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:r,error:i,...t})}))}function h(e,t="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${t}.localhost/${n}`:`${t}://localhost/${n}`}async function d(e,t){await c("plugin:event|unlisten",{event:e,eventId:t})}async function p(e,t,n){return c("plugin:event|listen",{event:e,windowLabel:t,handler:s(n)}).then((t=>async()=>d(e,t)))}n({},{TauriEvent:()=>y,emit:()=>E,listen:()=>I,once:()=>g});var w,y=((w=y||{}).WINDOW_RESIZED="tauri://resize",w.WINDOW_MOVED="tauri://move",w.WINDOW_CLOSE_REQUESTED="tauri://close-requested",w.WINDOW_CREATED="tauri://window-created",w.WINDOW_DESTROYED="tauri://destroyed",w.WINDOW_FOCUS="tauri://focus",w.WINDOW_BLUR="tauri://blur",w.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",w.WINDOW_THEME_CHANGED="tauri://theme-changed",w.WINDOW_FILE_DROP="tauri://file-drop",w.WINDOW_FILE_DROP_HOVER="tauri://file-drop-hover",w.WINDOW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled",w.MENU="tauri://menu",w);async function I(e,t){return p(e,null,t)}async function g(e,t){return async function(e,t,n){return p(e,t,(t=>{n(t),d(e,t.id).catch((()=>{}))}))}(e,null,t)}async function E(e,t){return async function(e,t,n){await c("plugin:event|emit",{event:e,windowLabel:t,payload:n})}(e,void 0,t)}return e.Store=class{constructor(e){this.path=e}async set(e,t){return await window.__TAURI_INVOKE__("plugin:store|set",{path:this.path,key:e,value:t})}async get(e){return await window.__TAURI_INVOKE__("plugin:store|get",{path:this.path,key:e})}async has(e){return await window.__TAURI_INVOKE__("plugin:store|has",{path:this.path,key:e})}async delete(e){return await window.__TAURI_INVOKE__("plugin:store|delete",{path:this.path,key:e})}async clear(){return await window.__TAURI_INVOKE__("plugin:store|clear",{path:this.path})}async reset(){return await window.__TAURI_INVOKE__("plugin:store|reset",{path:this.path})}async keys(){return await window.__TAURI_INVOKE__("plugin:store|keys",{path:this.path})}async values(){return await window.__TAURI_INVOKE__("plugin:store|values",{path:this.path})}async entries(){return await window.__TAURI_INVOKE__("plugin:store|entries",{path:this.path})}async length(){return await window.__TAURI_INVOKE__("plugin:store|length",{path:this.path})}async load(){return await window.__TAURI_INVOKE__("plugin:store|load",{path:this.path})}async save(){return await window.__TAURI_INVOKE__("plugin:store|save",{path:this.path})}async onKeyChange(e,t){return await I("store://change",(n=>{n.payload.path===this.path&&n.payload.key===e&&t(n.payload.value)}))}async onChange(e){return await I("store://change",(t=>{t.payload.path===this.path&&e(t.payload.key,t.payload.value)}))}},e}({});Object.defineProperty(window.__TAURI__,"store",{value:__TAURI_STORE__})}

@ -1,4 +1,8 @@
import { invoke } from "@tauri-apps/api/tauri";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
}
}
type BytesDto = string | number[];
export type ClientPath =
@ -127,16 +131,18 @@ class ProcedureExecutor {
outputLocation: Location,
sizeBytes?: number
): Promise<Uint8Array> {
return await invoke<number[]>("plugin:stronghold|execute_procedure", {
...this.procedureArgs,
procedure: {
type: "SLIP10Generate",
payload: {
output: outputLocation,
sizeBytes,
return await window
.__TAURI_INVOKE__<number[]>("plugin:stronghold|execute_procedure", {
...this.procedureArgs,
procedure: {
type: "SLIP10Generate",
payload: {
output: outputLocation,
sizeBytes,
},
},
},
}).then((n) => Uint8Array.from(n));
})
.then((n) => Uint8Array.from(n));
}
/**
@ -154,20 +160,22 @@ class ProcedureExecutor {
sourceLocation: Location,
outputLocation: Location
): Promise<Uint8Array> {
return await invoke<number[]>("plugin:stronghold|execute_procedure", {
...this.procedureArgs,
procedure: {
type: "SLIP10Derive",
payload: {
chain,
input: {
type: source,
payload: sourceLocation,
return await window
.__TAURI_INVOKE__<number[]>("plugin:stronghold|execute_procedure", {
...this.procedureArgs,
procedure: {
type: "SLIP10Derive",
payload: {
chain,
input: {
type: source,
payload: sourceLocation,
},
output: outputLocation,
},
output: outputLocation,
},
},
}).then((n) => Uint8Array.from(n));
})
.then((n) => Uint8Array.from(n));
}
/**
@ -183,17 +191,19 @@ class ProcedureExecutor {
outputLocation: Location,
passphrase?: string
): Promise<Uint8Array> {
return await invoke<number[]>("plugin:stronghold|execute_procedure", {
...this.procedureArgs,
procedure: {
type: "BIP39Recover",
payload: {
mnemonic,
passphrase,
output: outputLocation,
return await window
.__TAURI_INVOKE__<number[]>("plugin:stronghold|execute_procedure", {
...this.procedureArgs,
procedure: {
type: "BIP39Recover",
payload: {
mnemonic,
passphrase,
output: outputLocation,
},
},
},
}).then((n) => Uint8Array.from(n));
})
.then((n) => Uint8Array.from(n));
}
/**
@ -207,16 +217,18 @@ class ProcedureExecutor {
outputLocation: Location,
passphrase?: string
): Promise<Uint8Array> {
return await invoke<number[]>("plugin:stronghold|execute_procedure", {
...this.procedureArgs,
procedure: {
type: "BIP39Generate",
payload: {
output: outputLocation,
passphrase,
return await window
.__TAURI_INVOKE__<number[]>("plugin:stronghold|execute_procedure", {
...this.procedureArgs,
procedure: {
type: "BIP39Generate",
payload: {
output: outputLocation,
passphrase,
},
},
},
}).then((n) => Uint8Array.from(n));
})
.then((n) => Uint8Array.from(n));
}
/**
@ -225,16 +237,18 @@ class ProcedureExecutor {
* @returns A promise resolving to the public key hex string.
*/
async getEd25519PublicKey(privateKeyLocation: Location): Promise<Uint8Array> {
return await invoke<number[]>("plugin:stronghold|execute_procedure", {
...this.procedureArgs,
procedure: {
type: "PublicKey",
payload: {
type: "Ed25519",
privateKey: privateKeyLocation,
return await window
.__TAURI_INVOKE__<number[]>("plugin:stronghold|execute_procedure", {
...this.procedureArgs,
procedure: {
type: "PublicKey",
payload: {
type: "Ed25519",
privateKey: privateKeyLocation,
},
},
},
}).then((n) => Uint8Array.from(n));
})
.then((n) => Uint8Array.from(n));
}
/**
@ -247,16 +261,18 @@ class ProcedureExecutor {
privateKeyLocation: Location,
msg: string
): Promise<Uint8Array> {
return await invoke<number[]>("plugin:stronghold|execute_procedure", {
...this.procedureArgs,
procedure: {
type: "Ed25519Sign",
payload: {
privateKey: privateKeyLocation,
msg,
return await window
.__TAURI_INVOKE__<number[]>("plugin:stronghold|execute_procedure", {
...this.procedureArgs,
procedure: {
type: "Ed25519Sign",
payload: {
privateKey: privateKeyLocation,
msg,
},
},
},
}).then((n) => Uint8Array.from(n));
})
.then((n) => Uint8Array.from(n));
}
}
@ -294,11 +310,13 @@ export class Store {
}
async get(key: StoreKey): Promise<Uint8Array> {
return await invoke<number[]>("plugin:stronghold|get_store_record", {
snapshotPath: this.path,
client: this.client,
key: toBytesDto(key),
}).then((v) => Uint8Array.from(v));
return await window
.__TAURI_INVOKE__<number[]>("plugin:stronghold|get_store_record", {
snapshotPath: this.path,
client: this.client,
key: toBytesDto(key),
})
.then((v) => Uint8Array.from(v));
}
async insert(
@ -306,24 +324,29 @@ export class Store {
value: number[],
lifetime?: Duration
): Promise<void> {
return await invoke("plugin:stronghold|save_store_record", {
snapshotPath: this.path,
client: this.client,
key: toBytesDto(key),
value,
lifetime,
});
}
async remove(key: StoreKey): Promise<Uint8Array | null> {
return await invoke<number[] | null>(
"plugin:stronghold|remove_store_record",
return await window.__TAURI_INVOKE__(
"plugin:stronghold|save_store_record",
{
snapshotPath: this.path,
client: this.client,
key: toBytesDto(key),
value,
lifetime,
}
).then((v) => (v != null ? Uint8Array.from(v) : null));
);
}
async remove(key: StoreKey): Promise<Uint8Array | null> {
return await window
.__TAURI_INVOKE__<number[] | null>(
"plugin:stronghold|remove_store_record",
{
snapshotPath: this.path,
client: this.client,
key: toBytesDto(key),
}
)
.then((v) => (v != null ? Uint8Array.from(v) : null));
}
}
@ -358,7 +381,7 @@ export class Vault extends ProcedureExecutor {
* @returns
*/
async insert(recordPath: RecordPath, secret: number[]): Promise<void> {
return await invoke("plugin:stronghold|save_secret", {
return await window.__TAURI_INVOKE__("plugin:stronghold|save_secret", {
snapshotPath: this.path,
client: this.client,
vault: this.name,
@ -374,7 +397,7 @@ export class Vault extends ProcedureExecutor {
* @returns
*/
async remove(location: Location): Promise<void> {
return await invoke("plugin:stronghold|remove_secret", {
return await window.__TAURI_INVOKE__("plugin:stronghold|remove_secret", {
snapshotPath: this.path,
client: this.client,
vault: this.name,
@ -406,7 +429,7 @@ export class Stronghold {
* @returns
*/
private async reload(password: string): Promise<void> {
return await invoke("plugin:stronghold|initialize", {
return await window.__TAURI_INVOKE__("plugin:stronghold|initialize", {
snapshotPath: this.path,
password,
});
@ -416,23 +439,27 @@ export class Stronghold {
* Remove this instance from the cache.
*/
async unload(): Promise<void> {
return await invoke("plugin:stronghold|destroy", {
return await window.__TAURI_INVOKE__("plugin:stronghold|destroy", {
snapshotPath: this.path,
});
}
async loadClient(client: ClientPath): Promise<Client> {
return await invoke("plugin:stronghold|load_client", {
snapshotPath: this.path,
client: toBytesDto(client),
}).then(() => new Client(this.path, client));
return await window
.__TAURI_INVOKE__("plugin:stronghold|load_client", {
snapshotPath: this.path,
client: toBytesDto(client),
})
.then(() => new Client(this.path, client));
}
async createClient(client: ClientPath): Promise<Client> {
return await invoke("plugin:stronghold|create_client", {
snapshotPath: this.path,
client: toBytesDto(client),
}).then(() => new Client(this.path, client));
return await window
.__TAURI_INVOKE__("plugin:stronghold|create_client", {
snapshotPath: this.path,
client: toBytesDto(client),
})
.then(() => new Client(this.path, client));
}
/**
@ -440,7 +467,7 @@ export class Stronghold {
* @returns
*/
async save(): Promise<void> {
return await invoke("plugin:stronghold|save", {
return await window.__TAURI_INVOKE__("plugin:stronghold|save", {
snapshotPath: this.path,
});
}

File diff suppressed because one or more lines are too long

@ -42,7 +42,9 @@ class Update {
if (onEvent != null) {
channel.onmessage = onEvent;
}
return invoke("plugin:updater|download_and_install", { onEvent: channel });
return invoke("plugin:updater|download_and_install", {
onEvent: channel,
});
}
}

@ -1,4 +1,11 @@
import { invoke, transformCallback } from "@tauri-apps/api/tauri";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
__TAURI__: {
transformCallback: <T>(cb: (payload: T) => void) => number;
};
}
}
export interface MessageKind<T, D> {
type: T;
@ -32,11 +39,13 @@ export default class WebSocket {
listeners.forEach((l) => l(message));
};
return await invoke<number>("plugin:websocket|connect", {
url,
callbackFunction: transformCallback(handler),
options,
}).then((id) => new WebSocket(id, listeners));
return await window
.__TAURI_INVOKE__<number>("plugin:websocket|connect", {
url,
callbackFunction: window.__TAURI__.transformCallback(handler),
options,
})
.then((id) => new WebSocket(id, listeners));
}
addListener(cb: (arg: Message) => void): void {
@ -56,7 +65,7 @@ export default class WebSocket {
"invalid `message` type, expected a `{ type: string, data: any }` object, a string or a numeric array"
);
}
return await invoke("plugin:websocket|send", {
return await window.__TAURI_INVOKE__("plugin:websocket|send", {
id: this.id,
message: m,
});

@ -1 +1 @@
if("__TAURI__"in window){var __TAURI_WEBSOCKET__=function(){"use strict";var e=Object.defineProperty,t=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)},n=(e,n,r)=>(t(e,n,"read from private field"),r?r.call(e):n.get(e)),r=(e,n,r,i)=>(t(e,n,"write to private field"),i?i.call(e,r):n.set(e,r),r);function i(e,t=!1){let n=window.crypto.getRandomValues(new Uint32Array(1))[0],r=`_${n}`;return Object.defineProperty(window,r,{value:n=>(t&&Reflect.deleteProperty(window,r),e?.(n)),writable:!1,configurable:!0}),n}((t,n)=>{for(var r in n)e(t,r,{get:n[r],enumerable:!0})})({},{Channel:()=>a,PluginListener:()=>o,addPluginListener:()=>c,convertFileSrc:()=>d,invoke:()=>l,transformCallback:()=>i});var s,a=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,s,(()=>{})),this.id=i((e=>{n(this,s).call(this,e)}))}set onmessage(e){r(this,s,e)}get onmessage(){return n(this,s)}toJSON(){return`__CHANNEL__:${this.id}`}};s=new WeakMap;var o=class{constructor(e,t,n){this.plugin=e,this.event=t,this.channelId=n}async unregister(){return l(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function c(e,t,n){let r=new a;return r.onmessage=n,l(`plugin:${e}|register_listener`,{event:t,handler:r}).then((()=>new o(e,t,r.id)))}async function l(e,t={}){return new Promise(((n,r)=>{let s=i((e=>{n(e),Reflect.deleteProperty(window,`_${a}`)}),!0),a=i((e=>{r(e),Reflect.deleteProperty(window,`_${s}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:s,error:a,...t})}))}function d(e,t="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${t}.localhost/${n}`:`${t}://localhost/${n}`}class u{constructor(e,t){this.id=e,this.listeners=t}static async connect(e,t){const n=[];return await l("plugin:websocket|connect",{url:e,callbackFunction:i((e=>{n.forEach((t=>t(e)))})),options:t}).then((e=>new u(e,n)))}addListener(e){this.listeners.push(e)}async send(e){let t;if("string"==typeof e)t={type:"Text",data:e};else if("object"==typeof e&&"type"in e)t=e;else{if(!Array.isArray(e))throw new Error("invalid `message` type, expected a `{ type: string, data: any }` object, a string or a numeric array");t={type:"Binary",data:e}}return await l("plugin:websocket|send",{id:this.id,message:t})}async disconnect(){return await this.send({type:"Close",data:{code:1e3,reason:"Disconnected by client"}})}}return u}();Object.defineProperty(window.__TAURI__,"websocket",{value:__TAURI_WEBSOCKET__})}
if("__TAURI__"in window){var __TAURI_WEBSOCKET__=function(){"use strict";class e{constructor(e,t){this.id=e,this.listeners=t}static async connect(t,n){const i=[];return await window.__TAURI_INVOKE__("plugin:websocket|connect",{url:t,callbackFunction:window.__TAURI__.transformCallback((e=>{i.forEach((t=>t(e)))})),options:n}).then((t=>new e(t,i)))}addListener(e){this.listeners.push(e)}async send(e){let t;if("string"==typeof e)t={type:"Text",data:e};else if("object"==typeof e&&"type"in e)t=e;else{if(!Array.isArray(e))throw new Error("invalid `message` type, expected a `{ type: string, data: any }` object, a string or a numeric array");t={type:"Binary",data:e}}return await window.__TAURI_INVOKE__("plugin:websocket|send",{id:this.id,message:t})}async disconnect(){return await this.send({type:"Close",data:{code:1e3,reason:"Disconnected by client"}})}}return e}();Object.defineProperty(window.__TAURI__,"websocket",{value:__TAURI_WEBSOCKET__})}

@ -1,4 +1,8 @@
import { invoke } from "@tauri-apps/api/tauri";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
}
}
interface WindowDef {
label: string;
@ -27,14 +31,17 @@ export enum StateFlags {
* Save the state of all open windows to disk.
*/
async function saveWindowState(flags: StateFlags) {
invoke("plugin:window-state|save_window_state", { flags });
window.__TAURI_INVOKE__("plugin:window-state|save_window_state", { flags });
}
/**
* Restore the state for the specified window from disk.
*/
async function restoreState(label: string, flags: StateFlags) {
invoke("plugin:window-state|restore_state", { label, flags });
window.__TAURI_INVOKE__("plugin:window-state|restore_state", {
label,
flags,
});
}
/**

@ -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)),i=(e,t,r,i)=>(n(e,t,"write to private field"),i?i.call(e,r):t.set(e,r),r);function a(e,t=!1){let n=window.crypto.getRandomValues(new Uint32Array(1))[0],r=`_${n}`;return Object.defineProperty(window,r,{value:n=>(t&&Reflect.deleteProperty(window,r),e?.(n)),writable:!1,configurable:!0}),n}((e,n)=>{for(var r in n)t(e,r,{get:n[r],enumerable:!0})})({},{Channel:()=>o,PluginListener:()=>c,addPluginListener:()=>_,convertFileSrc:()=>w,invoke:()=>d,transformCallback:()=>a});var s,o=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,s,(()=>{})),this.id=a((e=>{r(this,s).call(this,e)}))}set onmessage(e){i(this,s,e)}get onmessage(){return r(this,s)}toJSON(){return`__CHANNEL__:${this.id}`}};s=new WeakMap;var l,c=class{constructor(e,t,n){this.plugin=e,this.event=t,this.channelId=n}async unregister(){return d(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function _(e,t,n){let r=new o;return r.onmessage=n,d(`plugin:${e}|register_listener`,{event:t,handler:r}).then((()=>new c(e,t,r.id)))}async function d(e,t={}){return new Promise(((n,r)=>{let i=a((e=>{n(e),Reflect.deleteProperty(window,`_${s}`)}),!0),s=a((e=>{r(e),Reflect.deleteProperty(window,`_${i}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:i,error:s,...t})}))}function w(e,t="asset"){let n=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${t}.localhost/${n}`:`${t}://localhost/${n}`}async function u(e,t){d("plugin:window-state|restore_state",{label:e,flags:t})}return e.StateFlags=void 0,(l=e.StateFlags||(e.StateFlags={}))[l.SIZE=1]="SIZE",l[l.POSITION=2]="POSITION",l[l.MAXIMIZED=4]="MAXIMIZED",l[l.VISIBLE=8]="VISIBLE",l[l.DECORATIONS=16]="DECORATIONS",l[l.FULLSCREEN=32]="FULLSCREEN",l[l.ALL=63]="ALL",e.restoreState=u,e.restoreStateCurrent=async function(e){u(window.__TAURI_METADATA__.__currentWindow.label,e)},e.saveWindowState=async function(e){d("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(_){"use strict";var t;async function e(_,t){window.__TAURI_INVOKE__("plugin:window-state|restore_state",{label:_,flags:t})}return _.StateFlags=void 0,(t=_.StateFlags||(_.StateFlags={}))[t.SIZE=1]="SIZE",t[t.POSITION=2]="POSITION",t[t.MAXIMIZED=4]="MAXIMIZED",t[t.VISIBLE=8]="VISIBLE",t[t.DECORATIONS=16]="DECORATIONS",t[t.FULLSCREEN=32]="FULLSCREEN",t[t.ALL=63]="ALL",_.restoreState=e,_.restoreStateCurrent=async function(_){e(window.__TAURI_METADATA__.__currentWindow.label,_)},_.saveWindowState=async function(_){window.__TAURI_INVOKE__("plugin:window-state|save_window_state",{flags:_})},_}({});Object.defineProperty(window.__TAURI__,"windowState",{value:__TAURI_WINDOWSTATE__})}

@ -2,7 +2,14 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
import { invoke, transformCallback } from "@tauri-apps/api/tauri";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
__TAURI__: {
transformCallback: <T>(cb: (payload: T) => void) => number;
};
}
}
export interface Event<T> {
/** Event name */
@ -28,7 +35,7 @@ export type UnlistenFn = () => void;
* @returns
*/
async function _unlisten(event: string, eventId: number): Promise<void> {
await invoke("plugin:event|unlisten", {
await window.__TAURI_INVOKE__("plugin:event|unlisten", {
event,
eventId,
});
@ -47,7 +54,7 @@ async function emit(
windowLabel?: string,
payload?: unknown
): Promise<void> {
await invoke("plugin:event|emit", {
await window.__TAURI_INVOKE__("plugin:event|emit", {
event,
windowLabel,
payload,
@ -66,13 +73,15 @@ async function listen<T>(
windowLabel: string | null,
handler: EventCallback<T>
): Promise<UnlistenFn> {
return invoke<number>("plugin:event|listen", {
event,
windowLabel,
handler: transformCallback(handler),
}).then((eventId) => {
return async () => _unlisten(event, eventId);
});
return window
.__TAURI_INVOKE__<number>("plugin:event|listen", {
event,
windowLabel,
handler: window.__TAURI__.transformCallback(handler),
})
.then((eventId) => {
return async () => _unlisten(event, eventId);
});
}
/**

@ -16,7 +16,6 @@
* @module
*/
import { invoke } from "@tauri-apps/api/tauri";
import type {
Event,
EventName,
@ -27,6 +26,12 @@ import { TauriEvent } from "@tauri-apps/api/event";
// TODO: use from @tauri-apps/api v2
import { emit, listen, once } from "./event";
declare global {
interface Window {
__TAURI_INVOKE__: <T>(cmd: string, args?: unknown) => Promise<T>;
}
}
type Theme = "light" | "dark";
type TitleBarStyle = "visible" | "transparent" | "overlay";
@ -403,7 +408,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns The window's monitor scale factor.
* */
async scaleFactor(): Promise<number> {
return invoke("plugin:window|scale_factor", {
return window.__TAURI_INVOKE__("plugin:window|scale_factor", {
label: this.label,
});
}
@ -419,9 +424,14 @@ class WindowManager extends WebviewWindowHandle {
* @returns The window's inner position.
* */
async innerPosition(): Promise<PhysicalPosition> {
return invoke<{ x: number; y: number }>("plugin:window|inner_position", {
label: this.label,
}).then(({ x, y }) => new PhysicalPosition(x, y));
return window
.__TAURI_INVOKE__<{ x: number; y: number }>(
"plugin:window|inner_position",
{
label: this.label,
}
)
.then(({ x, y }) => new PhysicalPosition(x, y));
}
/**
@ -435,9 +445,14 @@ class WindowManager extends WebviewWindowHandle {
* @returns The window's outer position.
* */
async outerPosition(): Promise<PhysicalPosition> {
return invoke<{ x: number; y: number }>("plugin:window|outer_position", {
label: this.label,
}).then(({ x, y }) => new PhysicalPosition(x, y));
return window
.__TAURI_INVOKE__<{ x: number; y: number }>(
"plugin:window|outer_position",
{
label: this.label,
}
)
.then(({ x, y }) => new PhysicalPosition(x, y));
}
/**
@ -452,12 +467,14 @@ class WindowManager extends WebviewWindowHandle {
* @returns The window's inner size.
*/
async innerSize(): Promise<PhysicalSize> {
return invoke<{ width: number; height: number }>(
"plugin:window|inner_size",
{
label: this.label,
}
).then(({ width, height }) => new PhysicalSize(width, height));
return window
.__TAURI_INVOKE__<{ width: number; height: number }>(
"plugin:window|inner_size",
{
label: this.label,
}
)
.then(({ width, height }) => new PhysicalSize(width, height));
}
/**
@ -472,12 +489,14 @@ class WindowManager extends WebviewWindowHandle {
* @returns The window's outer size.
*/
async outerSize(): Promise<PhysicalSize> {
return invoke<{ width: number; height: number }>(
"plugin:window|outer_size",
{
label: this.label,
}
).then(({ width, height }) => new PhysicalSize(width, height));
return window
.__TAURI_INVOKE__<{ width: number; height: number }>(
"plugin:window|outer_size",
{
label: this.label,
}
)
.then(({ width, height }) => new PhysicalSize(width, height));
}
/**
@ -491,7 +510,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns Whether the window is in fullscreen mode or not.
* */
async isFullscreen(): Promise<boolean> {
return invoke("plugin:window|is_fullscreen", {
return window.__TAURI_INVOKE__("plugin:window|is_fullscreen", {
label: this.label,
});
}
@ -507,7 +526,7 @@ class WindowManager extends WebviewWindowHandle {
* @since 1.3.0
* */
async isMinimized(): Promise<boolean> {
return invoke("plugin:window|is_minimized", {
return window.__TAURI_INVOKE__("plugin:window|is_minimized", {
label: this.label,
});
}
@ -523,7 +542,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns Whether the window is maximized or not.
* */
async isMaximized(): Promise<boolean> {
return invoke("plugin:window|is_maximized", {
return window.__TAURI_INVOKE__("plugin:window|is_maximized", {
label: this.label,
});
}
@ -539,7 +558,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns Whether the window is decorated or not.
* */
async isDecorated(): Promise<boolean> {
return invoke("plugin:window|is_decorated", {
return window.__TAURI_INVOKE__("plugin:window|is_decorated", {
label: this.label,
});
}
@ -555,7 +574,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns Whether the window is resizable or not.
* */
async isResizable(): Promise<boolean> {
return invoke("plugin:window|is_resizable", {
return window.__TAURI_INVOKE__("plugin:window|is_resizable", {
label: this.label,
});
}
@ -571,7 +590,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns Whether the window is visible or not.
* */
async isVisible(): Promise<boolean> {
return invoke("plugin:window|is_visible", {
return window.__TAURI_INVOKE__("plugin:window|is_visible", {
label: this.label,
});
}
@ -587,7 +606,7 @@ class WindowManager extends WebviewWindowHandle {
* @since 1.3.0
* */
async title(): Promise<string> {
return invoke("plugin:window|title", {
return window.__TAURI_INVOKE__("plugin:window|title", {
label: this.label,
});
}
@ -608,7 +627,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns The window theme.
* */
async theme(): Promise<Theme | null> {
return invoke("plugin:window|theme", {
return window.__TAURI_INVOKE__("plugin:window|theme", {
label: this.label,
});
}
@ -627,7 +646,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async center(): Promise<void> {
return invoke("plugin:window|center", {
return window.__TAURI_INVOKE__("plugin:window|center", {
label: this.label,
});
}
@ -665,7 +684,7 @@ class WindowManager extends WebviewWindowHandle {
}
}
return invoke("plugin:window|request_user_attention", {
return window.__TAURI_INVOKE__("plugin:window|request_user_attention", {
label: this.label,
value: requestType_,
});
@ -683,7 +702,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async setResizable(resizable: boolean): Promise<void> {
return invoke("plugin:window|set_resizable", {
return window.__TAURI_INVOKE__("plugin:window|set_resizable", {
label: this.label,
value: resizable,
});
@ -701,7 +720,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async setTitle(title: string): Promise<void> {
return invoke("plugin:window|set_title", {
return window.__TAURI_INVOKE__("plugin:window|set_title", {
label: this.label,
value: title,
});
@ -718,7 +737,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async maximize(): Promise<void> {
return invoke("plugin:window|maximize", {
return window.__TAURI_INVOKE__("plugin:window|maximize", {
label: this.label,
});
}
@ -734,7 +753,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async unmaximize(): Promise<void> {
return invoke("plugin:window|unmaximize", {
return window.__TAURI_INVOKE__("plugin:window|unmaximize", {
label: this.label,
});
}
@ -750,7 +769,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async toggleMaximize(): Promise<void> {
return invoke("plugin:window|toggle_maximize", {
return window.__TAURI_INVOKE__("plugin:window|toggle_maximize", {
label: this.label,
});
}
@ -766,7 +785,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async minimize(): Promise<void> {
return invoke("plugin:window|minimize", {
return window.__TAURI_INVOKE__("plugin:window|minimize", {
label: this.label,
});
}
@ -782,7 +801,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async unminimize(): Promise<void> {
return invoke("plugin:window|unminimize", {
return window.__TAURI_INVOKE__("plugin:window|unminimize", {
label: this.label,
});
}
@ -798,7 +817,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async show(): Promise<void> {
return invoke("plugin:window|show", {
return window.__TAURI_INVOKE__("plugin:window|show", {
label: this.label,
});
}
@ -814,7 +833,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async hide(): Promise<void> {
return invoke("plugin:window|hide", {
return window.__TAURI_INVOKE__("plugin:window|hide", {
label: this.label,
});
}
@ -830,7 +849,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async close(): Promise<void> {
return invoke("plugin:window|close", {
return window.__TAURI_INVOKE__("plugin:window|close", {
label: this.label,
});
}
@ -847,7 +866,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async setDecorations(decorations: boolean): Promise<void> {
return invoke("plugin:window|set_decorations", {
return window.__TAURI_INVOKE__("plugin:window|set_decorations", {
label: this.label,
value: decorations,
});
@ -875,7 +894,7 @@ class WindowManager extends WebviewWindowHandle {
* @since 2.0
*/
async setShadow(enable: boolean): Promise<void> {
return invoke("plugin:window|set_shadow", {
return window.__TAURI_INVOKE__("plugin:window|set_shadow", {
label: this.label,
value: enable,
});
@ -893,7 +912,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async setAlwaysOnTop(alwaysOnTop: boolean): Promise<void> {
return invoke("plugin:window|set_always_on_top", {
return window.__TAURI_INVOKE__("plugin:window|set_always_on_top", {
label: this.label,
value: alwaysOnTop,
});
@ -912,7 +931,7 @@ class WindowManager extends WebviewWindowHandle {
* @since 1.2.0
*/
async setContentProtected(protected_: boolean): Promise<void> {
return invoke("plugin:window|set_content_protected", {
return window.__TAURI_INVOKE__("plugin:window|set_content_protected", {
label: this.label,
value: protected_,
});
@ -936,7 +955,7 @@ class WindowManager extends WebviewWindowHandle {
);
}
return invoke("plugin:window|set_size", {
return window.__TAURI_INVOKE__("plugin:window|set_size", {
label: this.label,
value: {
type: size.type,
@ -968,7 +987,7 @@ class WindowManager extends WebviewWindowHandle {
);
}
return invoke("plugin:window|set_min_size", {
return window.__TAURI_INVOKE__("plugin:window|set_min_size", {
label: this.label,
value: size
? {
@ -1002,7 +1021,7 @@ class WindowManager extends WebviewWindowHandle {
);
}
return invoke("plugin:window|set_max_size", {
return window.__TAURI_INVOKE__("plugin:window|set_max_size", {
label: this.label,
value: size
? {
@ -1039,7 +1058,7 @@ class WindowManager extends WebviewWindowHandle {
);
}
return invoke("plugin:window|set_position", {
return window.__TAURI_INVOKE__("plugin:window|set_position", {
label: this.label,
value: {
type: position.type,
@ -1063,7 +1082,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async setFullscreen(fullscreen: boolean): Promise<void> {
return invoke("plugin:window|set_fullscreen", {
return window.__TAURI_INVOKE__("plugin:window|set_fullscreen", {
label: this.label,
value: fullscreen,
});
@ -1080,7 +1099,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async setFocus(): Promise<void> {
return invoke("plugin:window|set_focus", {
return window.__TAURI_INVOKE__("plugin:window|set_focus", {
label: this.label,
});
}
@ -1104,7 +1123,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async setIcon(icon: string | Uint8Array): Promise<void> {
return invoke("plugin:window|set_icon", {
return window.__TAURI_INVOKE__("plugin:window|set_icon", {
label: this.label,
value: typeof icon === "string" ? icon : Array.from(icon),
});
@ -1126,7 +1145,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async setSkipTaskbar(skip: boolean): Promise<void> {
return invoke("plugin:window|set_skip_taskbar", {
return window.__TAURI_INVOKE__("plugin:window|set_skip_taskbar", {
label: this.label,
value: skip,
});
@ -1152,7 +1171,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async setCursorGrab(grab: boolean): Promise<void> {
return invoke("plugin:window|set_cursor_grab", {
return window.__TAURI_INVOKE__("plugin:window|set_cursor_grab", {
label: this.label,
value: grab,
});
@ -1176,7 +1195,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async setCursorVisible(visible: boolean): Promise<void> {
return invoke("plugin:window|set_cursor_visible", {
return window.__TAURI_INVOKE__("plugin:window|set_cursor_visible", {
label: this.label,
value: visible,
});
@ -1194,7 +1213,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async setCursorIcon(icon: CursorIcon): Promise<void> {
return invoke("plugin:window|set_cursor_icon", {
return window.__TAURI_INVOKE__("plugin:window|set_cursor_icon", {
label: this.label,
value: icon,
});
@ -1223,7 +1242,7 @@ class WindowManager extends WebviewWindowHandle {
);
}
return invoke("plugin:window|set_cursor_position", {
return window.__TAURI_INVOKE__("plugin:window|set_cursor_position", {
label: this.label,
value: {
type: position.type,
@ -1248,7 +1267,7 @@ class WindowManager extends WebviewWindowHandle {
* @returns A promise indicating the success or failure of the operation.
*/
async setIgnoreCursorEvents(ignore: boolean): Promise<void> {
return invoke("plugin:window|set_ignore_cursor_events", {
return window.__TAURI_INVOKE__("plugin:window|set_ignore_cursor_events", {
label: this.label,
value: ignore,
});
@ -1265,7 +1284,7 @@ class WindowManager extends WebviewWindowHandle {
* @return A promise indicating the success or failure of the operation.
*/
async startDragging(): Promise<void> {
return invoke("plugin:window|start_dragging", {
return window.__TAURI_INVOKE__("plugin:window|start_dragging", {
label: this.label,
});
}
@ -1622,12 +1641,13 @@ class WebviewWindow extends WindowManager {
super(label);
// @ts-expect-error `skip` is not a public API so it is not defined in WindowOptions
if (!options?.skip) {
invoke("plugin:window|create", {
options: {
...options,
label,
},
})
window
.__TAURI_INVOKE__("plugin:window|create", {
options: {
...options,
label,
},
})
.then(async () => this.emit("tauri://created"))
.catch(async (e: string) => this.emit("tauri://error", e));
}
@ -1813,9 +1833,9 @@ function mapPhysicalSize(m: PhysicalSize): PhysicalSize {
* @since 1.0.0
*/
async function currentMonitor(): Promise<Monitor | null> {
return invoke<Monitor | null>("plugin:window|current_monitor").then(
mapMonitor
);
return window
.__TAURI_INVOKE__<Monitor | null>("plugin:window|current_monitor")
.then(mapMonitor);
}
/**
@ -1830,9 +1850,9 @@ async function currentMonitor(): Promise<Monitor | null> {
* @since 1.0.0
*/
async function primaryMonitor(): Promise<Monitor | null> {
return invoke<Monitor | null>("plugin:window|primary_monitor").then(
mapMonitor
);
return window
.__TAURI_INVOKE__<Monitor | null>("plugin:window|primary_monitor")
.then(mapMonitor);
}
/**
@ -1846,9 +1866,9 @@ async function primaryMonitor(): Promise<Monitor | null> {
* @since 1.0.0
*/
async function availableMonitors(): Promise<Monitor[]> {
return invoke<Monitor[]>("plugin:window|available_monitors").then(
(ms) => ms.map(mapMonitor) as Monitor[]
);
return window
.__TAURI_INVOKE__<Monitor[]>("plugin:window|available_monitors")
.then((ms) => ms.map(mapMonitor) as Monitor[]);
}
export {

File diff suppressed because one or more lines are too long

@ -11,8 +11,10 @@ import terser from "@rollup/plugin-terser";
* @returns {import('rollup').RollupOptions}
*/
export function createConfig({ input = "index.ts", pkg, external = [] }) {
const pluginJsName = pkg.name.replace("@tauri-apps/plugin-", "").replace(/-./g, x => x[1].toUpperCase())
const iifeVarName = `__TAURI_${pluginJsName.toUpperCase()}__`
const pluginJsName = pkg.name
.replace("@tauri-apps/plugin-", "")
.replace(/-./g, (x) => x[1].toUpperCase());
const iifeVarName = `__TAURI_${pluginJsName.toUpperCase()}__`;
return [
{
input,
@ -64,8 +66,12 @@ export function createConfig({ input = "index.ts", pkg, external = [] }) {
// and var is not guaranteed to assign to the global `window` object so we make sure to assign it
plugins: [
resolve(),
typescript({
sourceMap: false,
declaration: false,
declarationDir: undefined,
}),
terser(),
typescript({ declaration: false }),
],
},
];

Loading…
Cancel
Save