diff --git a/api/src/cli.ts b/api/src/cli.ts index 75210824e..eea8593d5 100644 --- a/api/src/cli.ts +++ b/api/src/cli.ts @@ -1,4 +1,4 @@ -import { invoke } from './tauri' +import { invokeTauriCommand } from './helpers/tauri' export interface ArgMatch { /** @@ -27,7 +27,7 @@ export interface CliMatches { * gets the CLI matches */ async function getMatches(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Cli', message: { cmd: 'cliMatches' diff --git a/api/src/dialog.ts b/api/src/dialog.ts index 34409c893..6d0c92bb1 100644 --- a/api/src/dialog.ts +++ b/api/src/dialog.ts @@ -1,4 +1,4 @@ -import { invoke } from './tauri' +import { invokeTauriCommand } from './helpers/tauri' export interface DialogFilter { name: string @@ -34,7 +34,7 @@ async function open( Object.freeze(options) } - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Dialog', mainThread: true, message: { @@ -57,7 +57,7 @@ async function save(options: SaveDialogOptions = {}): Promise { Object.freeze(options) } - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Dialog', mainThread: true, message: { diff --git a/api/src/fs.ts b/api/src/fs.ts index ba622ee4e..253dc210b 100644 --- a/api/src/fs.ts +++ b/api/src/fs.ts @@ -1,4 +1,4 @@ -import { invoke } from './tauri' +import { invokeTauriCommand } from './helpers/tauri' export enum BaseDirectory { Audio = 1, @@ -61,7 +61,7 @@ async function readTextFile( filePath: string, options: FsOptions = {} ): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'readTextFile', @@ -83,7 +83,7 @@ async function readBinaryFile( filePath: string, options: FsOptions = {} ): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'readBinaryFile', @@ -114,7 +114,7 @@ async function writeFile( Object.freeze(file) } - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'writeFile', @@ -179,7 +179,7 @@ async function writeBinaryFile( Object.freeze(file) } - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'writeBinaryFile', @@ -203,7 +203,7 @@ async function readDir( dir: string, options: FsDirOptions = {} ): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'readDir', @@ -228,7 +228,7 @@ async function createDir( dir: string, options: FsDirOptions = {} ): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'createDir', @@ -252,7 +252,7 @@ async function removeDir( dir: string, options: FsDirOptions = {} ): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'removeDir', @@ -276,7 +276,7 @@ async function copyFile( destination: string, options: FsOptions = {} ): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'copyFile', @@ -299,7 +299,7 @@ async function removeFile( file: string, options: FsOptions = {} ): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'removeFile', @@ -323,7 +323,7 @@ async function renameFile( newPath: string, options: FsOptions = {} ): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'renameFile', diff --git a/api/src/globalShortcut.ts b/api/src/globalShortcut.ts index ddd3a43c7..13a697b7c 100644 --- a/api/src/globalShortcut.ts +++ b/api/src/globalShortcut.ts @@ -1,4 +1,5 @@ -import { invoke, transformCallback } from './tauri' +import { invokeTauriCommand } from './helpers/tauri' +import { transformCallback } from './tauri' /** * Register a global shortcut @@ -9,7 +10,7 @@ async function register( shortcut: string, handler: (shortcut: string) => void ): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'GlobalShortcut', message: { cmd: 'register', @@ -28,7 +29,7 @@ async function registerAll( shortcuts: string[], handler: (shortcut: string) => void ): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'GlobalShortcut', message: { cmd: 'registerAll', @@ -45,7 +46,7 @@ async function registerAll( * @return {Promise} promise resolving to the state */ async function isRegistered(shortcut: string): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'GlobalShortcut', message: { cmd: 'isRegistered', @@ -59,7 +60,7 @@ async function isRegistered(shortcut: string): Promise { * @param shortcut shortcut definition, modifiers and key separated by "+" e.g. CmdOrControl+Q */ async function unregister(shortcut: string): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'GlobalShortcut', message: { cmd: 'unregister', @@ -72,7 +73,7 @@ async function unregister(shortcut: string): Promise { * Unregisters all shortcuts registered by the application. */ async function unregisterAll(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'GlobalShortcut', message: { cmd: 'unregisterAll' diff --git a/api/src/helpers/event.ts b/api/src/helpers/event.ts index 3f02315fb..5de4efe5f 100644 --- a/api/src/helpers/event.ts +++ b/api/src/helpers/event.ts @@ -1,4 +1,5 @@ -import { invoke, transformCallback } from '../tauri' +import { invokeTauriCommand } from './tauri' +import { transformCallback } from '../tauri' export interface Event { type: string @@ -12,7 +13,7 @@ async function _listen( handler: EventCallback, once: boolean ): Promise { - await invoke({ + await invokeTauriCommand({ __tauriModule: 'Event', message: { cmd: 'listen', @@ -60,7 +61,7 @@ async function emit( windowLabel?: string, payload?: string ): Promise { - await invoke({ + await invokeTauriCommand({ __tauriModule: 'Event', message: { cmd: 'emit', diff --git a/api/src/helpers/tauri.ts b/api/src/helpers/tauri.ts new file mode 100644 index 000000000..9d0c43b84 --- /dev/null +++ b/api/src/helpers/tauri.ts @@ -0,0 +1,22 @@ +import { invoke } from '../tauri' + +export type TauriModule = 'Fs' | + 'Window' | + 'Shell' | + 'Event' | + 'Internal' | + 'Dialog' | + 'Cli' | + 'Notification' | + 'Http' | + 'GlobalShortcut' + +export interface TauriCommand { + __tauriModule: TauriModule + mainThread?: boolean + [key: string]: unknown +} + +export async function invokeTauriCommand(command: TauriCommand): Promise { + return invoke('tauri', command) +} diff --git a/api/src/http.ts b/api/src/http.ts index c4f7f1de2..5c65dfce7 100644 --- a/api/src/http.ts +++ b/api/src/http.ts @@ -1,4 +1,4 @@ -import { invoke } from './tauri' +import { invokeTauriCommand } from './helpers/tauri' export interface ClientOptions { maxRedirections: boolean @@ -80,7 +80,7 @@ export class Client { * drops the client instance */ async drop(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Http', message: { cmd: 'dropClient', @@ -97,7 +97,7 @@ export class Client { * @return promise resolving to the response */ async request(options: HttpOptions): Promise> { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Http', message: { cmd: 'httpRequest', @@ -201,7 +201,7 @@ export class Client { } async function getClient(options?: ClientOptions): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Http', message: { cmd: 'createClient', diff --git a/api/src/notification.ts b/api/src/notification.ts index 689c2a882..c566deda3 100644 --- a/api/src/notification.ts +++ b/api/src/notification.ts @@ -1,4 +1,4 @@ -import { invoke } from './tauri' +import { invokeTauriCommand } from './helpers/tauri' export interface Options { title: string @@ -13,7 +13,7 @@ async function isPermissionGranted(): Promise { if (window.Notification.permission !== 'default') { return Promise.resolve(window.Notification.permission === 'granted') } - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Notification', message: { cmd: 'isNotificationPermissionGranted' diff --git a/api/src/path.ts b/api/src/path.ts index fe7433c08..48966cc11 100644 --- a/api/src/path.ts +++ b/api/src/path.ts @@ -1,4 +1,4 @@ -import { invoke } from './tauri' +import { invokeTauriCommand } from './helpers/tauri' import { BaseDirectory } from './fs' /** @@ -7,7 +7,7 @@ import { BaseDirectory } from './fs' * @return {Promise} */ async function appDir(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'resolvePath', @@ -23,7 +23,7 @@ async function appDir(): Promise { * @return {Promise} */ async function audioDir(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'resolvePath', @@ -39,7 +39,7 @@ async function audioDir(): Promise { * @return {Promise} */ async function cacheDir(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'resolvePath', @@ -55,7 +55,7 @@ async function cacheDir(): Promise { * @return {Promise} */ async function configDir(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'resolvePath', @@ -71,7 +71,7 @@ async function configDir(): Promise { * @return {Promise} */ async function dataDir(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'resolvePath', @@ -87,7 +87,7 @@ async function dataDir(): Promise { * @return {Promise} */ async function desktopDir(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'resolvePath', @@ -103,7 +103,7 @@ async function desktopDir(): Promise { * @return {Promise} */ async function documentDir(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'resolvePath', @@ -119,7 +119,7 @@ async function documentDir(): Promise { * @return {Promise} */ async function downloadDir(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'resolvePath', @@ -135,7 +135,7 @@ async function downloadDir(): Promise { * @return {Promise} */ async function executableDir(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'resolvePath', @@ -151,7 +151,7 @@ async function executableDir(): Promise { * @return {Promise} */ async function fontDir(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'resolvePath', @@ -167,7 +167,7 @@ async function fontDir(): Promise { * @return {Promise} */ async function homeDir(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'resolvePath', @@ -183,7 +183,7 @@ async function homeDir(): Promise { * @return {Promise} */ async function localDataDir(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'resolvePath', @@ -199,7 +199,7 @@ async function localDataDir(): Promise { * @return {Promise} */ async function pictureDir(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'resolvePath', @@ -215,7 +215,7 @@ async function pictureDir(): Promise { * @return {Promise} */ async function publicDir(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'resolvePath', @@ -231,7 +231,7 @@ async function publicDir(): Promise { * @return {Promise} */ async function resourceDir(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'resolvePath', @@ -247,7 +247,7 @@ async function resourceDir(): Promise { * @return {Promise} */ async function runtimeDir(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'resolvePath', @@ -263,7 +263,7 @@ async function runtimeDir(): Promise { * @return {Promise} */ async function templateDir(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'resolvePath', @@ -279,7 +279,7 @@ async function templateDir(): Promise { * @return {Promise} */ async function videoDir(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'resolvePath', @@ -298,7 +298,7 @@ async function resolvePath( path: string, directory: BaseDirectory ): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Fs', message: { cmd: 'resolvePath', diff --git a/api/src/shell.ts b/api/src/shell.ts index b8c2a5452..c75b1817b 100644 --- a/api/src/shell.ts +++ b/api/src/shell.ts @@ -1,4 +1,4 @@ -import { invoke } from './tauri' +import { invokeTauriCommand } from './helpers/tauri' /** * spawns a process @@ -15,7 +15,7 @@ async function execute( Object.freeze(args) } - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Shell', message: { cmd: 'execute', @@ -31,7 +31,7 @@ async function execute( * @param url the URL to open */ async function open(url: string): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Shell', message: { cmd: 'open', diff --git a/api/src/tauri.ts b/api/src/tauri.ts index 8a6855169..addbace57 100644 --- a/api/src/tauri.ts +++ b/api/src/tauri.ts @@ -1,7 +1,9 @@ declare global { // eslint-disable-next-line @typescript-eslint/no-unused-vars interface Window { - __TAURI_INVOKE_HANDLER__: (command: { [key: string]: unknown }) => void + rpc: { + notify: (command: string, args?: { [key: string]: unknown }) => void + } } } @@ -49,6 +51,11 @@ function transformCallback( return identifier } +export interface InvokeArgs { + mainThread?: boolean + [key: string]: unknown +} + /** * sends a message to the backend * @@ -57,8 +64,8 @@ function transformCallback( * @return {Promise} Promise resolving or rejecting to the backend response */ async function invoke( - cmd: string | { [key: string]: unknown }, - args: { [key: string]: unknown } = {} + cmd: string, + args: InvokeArgs = {} ): Promise { return new Promise((resolve, reject) => { const callback = transformCallback((e) => { @@ -70,15 +77,7 @@ async function invoke( Reflect.deleteProperty(window, callback) }, true) - if (typeof cmd === 'string') { - args.cmd = cmd - } else if (typeof cmd === 'object') { - args = cmd - } else { - return reject(new Error('Invalid argument type.')) - } - - window.__TAURI_INVOKE_HANDLER__({ + window.rpc.notify(cmd, { callback, error, ...args diff --git a/api/src/window.ts b/api/src/window.ts index c64ce0cfb..3d7acb4e6 100644 --- a/api/src/window.ts +++ b/api/src/window.ts @@ -1,4 +1,4 @@ -import { invoke } from './tauri' +import { invokeTauriCommand } from './helpers/tauri' import { EventCallback, emit, listen, once } from './helpers/event' interface WindowDef { @@ -90,14 +90,12 @@ class WebviewWindowHandle { } return false } - - _emitTauriEvent(event: string): void {} } class WebviewWindow extends WebviewWindowHandle { constructor(label: string, options: WindowOptions = {}) { super(label) - invoke({ + invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'createWebview', @@ -131,7 +129,7 @@ class WindowManager { * Updates the window resizable flag. */ async setResizable(resizable: boolean): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'setResizable', @@ -146,7 +144,7 @@ class WindowManager { * @param title the new title */ async setTitle(title: string): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'setTitle', @@ -159,7 +157,7 @@ class WindowManager { * Maximizes the window. */ async maximize(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'maximize' @@ -171,7 +169,7 @@ class WindowManager { * Unmaximizes the window. */ async unmaximize(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'unmaximize' @@ -183,7 +181,7 @@ class WindowManager { * Minimizes the window. */ async minimize(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'minimize' @@ -195,7 +193,7 @@ class WindowManager { * Unminimizes the window. */ async unminimize(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'unminimize' @@ -207,7 +205,7 @@ class WindowManager { * Sets the window visibility to true. */ async show(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'show' @@ -219,7 +217,7 @@ class WindowManager { * Sets the window visibility to false. */ async hide(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'hide' @@ -231,7 +229,7 @@ class WindowManager { * Closes the window. */ async close(): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'close' @@ -245,7 +243,7 @@ class WindowManager { * @param {boolean} decorations whether the window should have borders and bars */ async setDecorations(decorations: boolean): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'setDecorations', @@ -260,7 +258,7 @@ class WindowManager { * @param {boolean} alwaysOnTop whether the window should always be on top of other windows or not */ async setAlwaysOnTop(alwaysOnTop: boolean): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'setAlwaysOnTop', @@ -275,7 +273,7 @@ class WindowManager { * @param {number} width the new window width */ async setWidth(width: number): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'setWidth', @@ -290,7 +288,7 @@ class WindowManager { * @param {number} height the new window height */ async setHeight(height: number): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'setHeight', @@ -306,7 +304,7 @@ class WindowManager { * @param {number} height the new window height */ async resize(width: number, height: number): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'resize', @@ -323,7 +321,7 @@ class WindowManager { * @param {number} minHeight the new window min height */ async setMinSize(minWidth: number, minHeight: number): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'setMinSize', @@ -340,7 +338,7 @@ class WindowManager { * @param {number} maxHeight the new window max height */ async setMaxSize(maxWidth: number, maxHeight: number): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'setMaxSize', @@ -356,7 +354,7 @@ class WindowManager { * @param {number} x the new window x position */ async setX(x: number): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'setX', @@ -371,7 +369,7 @@ class WindowManager { * @param {number} y the new window y position */ async setY(y: number): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'setY', @@ -387,7 +385,7 @@ class WindowManager { * @param {number} y the new window y position */ async setPosition(x: number, y: number): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'setPosition', @@ -403,7 +401,7 @@ class WindowManager { * @param {boolean} fullscreen whether the window should go to fullscreen or not */ async setFullscreen(fullscreen: boolean): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'setFullscreen', @@ -418,7 +416,7 @@ class WindowManager { * @param {string | number[]} icon icon bytes or path to the icon file */ async setIcon(icon: 'string' | number[]): Promise { - return invoke({ + return invokeTauriCommand({ __tauriModule: 'Window', message: { cmd: 'setIcon', diff --git a/cli/core/src/templates/tauri.js b/cli/core/src/templates/tauri.js index c3dfa76cb..2dbd701df 100644 --- a/cli/core/src/templates/tauri.js +++ b/cli/core/src/templates/tauri.js @@ -124,8 +124,9 @@ if (!String.prototype.startsWith) { return reject(new Error("Invalid argument type.")); } - if (window.__TAURI_INVOKE_HANDLER__) { - window.__TAURI_INVOKE_HANDLER__( + if (window.rpc) { + window.rpc.notify( + cmd, _objectSpread( { callback: callback, @@ -136,7 +137,8 @@ if (!String.prototype.startsWith) { ); } else { window.addEventListener("DOMContentLoaded", function () { - window.__TAURI_INVOKE_HANDLER__( + window.rpc.notify( + cmd, _objectSpread( { callback: callback, @@ -165,7 +167,7 @@ if (!String.prototype.startsWith) { target.href.startsWith("http") && target.target === "_blank" ) { - window.__TAURI__.invoke({ + window.__TAURI__.invoke('tauri', { __tauriModule: "Shell", message: { cmd: "open", @@ -198,7 +200,7 @@ if (!String.prototype.startsWith) { ); } - window.__TAURI__.invoke({ + window.__TAURI__.invoke('tauri', { __tauriModule: "Event", message: { cmd: "listen", @@ -219,7 +221,7 @@ if (!String.prototype.startsWith) { if (window.Notification.permission !== "default") { return Promise.resolve(window.Notification.permission === "granted"); } - return window.__TAURI__.invoke({ + return window.__TAURI__.invoke('tauri', { __tauriModule: "Notification", message: { cmd: "isNotificationPermissionGranted", @@ -235,7 +237,7 @@ if (!String.prototype.startsWith) { function requestPermission() { return window.__TAURI__ - .invoke({ + .invoke('tauri', { __tauriModule: "Notification", mainThread: true, message: { @@ -255,7 +257,7 @@ if (!String.prototype.startsWith) { isPermissionGranted().then(function (permission) { if (permission) { - return window.__TAURI__.invoke({ + return window.__TAURI__.invoke('tauri', { __tauriModule: "Notification", message: { cmd: "notification", @@ -304,7 +306,7 @@ if (!String.prototype.startsWith) { }); window.alert = function (message) { - window.__TAURI__.invoke({ + window.__TAURI__.invoke('tauri', { __tauriModule: "Dialog", mainThread: true, message: { @@ -315,7 +317,7 @@ if (!String.prototype.startsWith) { }; window.confirm = function (message) { - return window.__TAURI__.invoke({ + return window.__TAURI__.invoke('tauri', { __tauriModule: "Dialog", mainThread: true, message: { diff --git a/cli/tauri.js/test/jest/fixtures/app/dist/index.html b/cli/tauri.js/test/jest/fixtures/app/dist/index.html index 7f0aed006..052a4fa74 100644 --- a/cli/tauri.js/test/jest/fixtures/app/dist/index.html +++ b/cli/tauri.js/test/jest/fixtures/app/dist/index.html @@ -136,9 +136,7 @@ }) setTimeout(function () { - window.__TAURI_INVOKE_HANDLER__({ - cmd: 'exit' - }) + window.rpc.notify('exit') }, 15000) diff --git a/cli/tauri.js/test/jest/fixtures/app/src-tauri/src/cmd.rs b/cli/tauri.js/test/jest/fixtures/app/src-tauri/src/cmd.rs deleted file mode 100644 index c61062070..000000000 --- a/cli/tauri.js/test/jest/fixtures/app/src-tauri/src/cmd.rs +++ /dev/null @@ -1,8 +0,0 @@ -#[derive(serde::Deserialize)] -#[serde(tag = "cmd", rename_all = "camelCase")] -pub enum Cmd { - // your custom commands - // multiple arguments are allowed - // note that rename_all = "camelCase": you need to use "myCustomCommand" on JS - Exit {}, -} diff --git a/cli/tauri.js/test/jest/fixtures/app/src-tauri/src/main.rs b/cli/tauri.js/test/jest/fixtures/app/src-tauri/src/main.rs index a7a50f64e..7f3f6a1b8 100644 --- a/cli/tauri.js/test/jest/fixtures/app/src-tauri/src/main.rs +++ b/cli/tauri.js/test/jest/fixtures/app/src-tauri/src/main.rs @@ -1,5 +1,3 @@ -mod cmd; - use tauri::ApplicationDispatcherExt; #[derive(tauri::FromTauriContext)] @@ -21,19 +19,9 @@ fn main() { .current_webview() .eval("window.onTauriInit && window.onTauriInit()"); }) - .invoke_handler(|webview_manager, arg| async move { - use cmd::Cmd::*; - match serde_json::from_str(&arg) { - Err(e) => Err(e.into()), - Ok(command) => { - match command { - // definitions for your custom commands from Cmd here - Exit {} => { - // TODO dispatcher.terminate(); - } - } - Ok(()) - } + .invoke_handler(|webview_manager, command, _arg| async move { + if &command == "exit" { + webview_manager.close().unwrap(); } }) .build() diff --git a/tauri-macros/src/command.rs b/tauri-macros/src/command.rs index 198e668fe..5be4a76bf 100644 --- a/tauri-macros/src/command.rs +++ b/tauri-macros/src/command.rs @@ -133,17 +133,10 @@ pub fn generate_handler(item: proc_macro::TokenStream) -> TokenStream { }); quote! { - |webview_manager, arg| async move { - let dispatch: ::std::result::Result<::tauri::DispatchInstructions, ::serde_json::Error> = - ::serde_json::from_str(&arg); - match dispatch { - Err(e) => Err(e.into()), - Ok(dispatch) => { - match dispatch.cmd.as_str() { - #(stringify!(#fn_names) => #fn_wrappers(webview_manager, dispatch.args).await,)* - _ => Err(tauri::Error::UnknownApi(None)), - } - } + |webview_manager, command, arg| async move { + match command.as_str() { + #(stringify!(#fn_names) => #fn_wrappers(webview_manager, arg).await,)* + _ => Err(tauri::Error::UnknownApi(None)), } } } diff --git a/tauri/Cargo.toml b/tauri/Cargo.toml index 9c3fe3bfe..19083d9f7 100644 --- a/tauri/Cargo.toml +++ b/tauri/Cargo.toml @@ -31,7 +31,7 @@ thiserror = "1.0.24" once_cell = "1.7.0" tauri-api = { version = "0.7.5", path = "../tauri-api" } tauri-macros = { version = "0.1", path = "../tauri-macros" } -wry = { git = "https://github.com/tauri-apps/wry", rev = "a607d6aba95e6ee0d9620394b7ee0092527095dc" } +wry = { git = "https://github.com/tauri-apps/wry", rev = "729fdc182eaf4af44d822dfc9396deb3f5f5810a" } rand = "0.8" [build-dependencies] diff --git a/tauri/examples/api/src-tauri/Cargo.lock b/tauri/examples/api/src-tauri/Cargo.lock index ae978e8cf..f05c10129 100644 --- a/tauri/examples/api/src-tauri/Cargo.lock +++ b/tauri/examples/api/src-tauri/Cargo.lock @@ -1285,6 +1285,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "infer" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34ad0755c42f65a1374dcd0aae07e03dfefc911eceb3f409d2b4a888189447e6" + [[package]] name = "instant" version = "0.1.9" @@ -3547,7 +3553,7 @@ dependencies = [ [[package]] name = "wry" version = "0.5.1" -source = "git+https://github.com/tauri-apps/wry?rev=a607d6aba95e6ee0d9620394b7ee0092527095dc#a607d6aba95e6ee0d9620394b7ee0092527095dc" +source = "git+https://github.com/tauri-apps/wry?rev=729fdc182eaf4af44d822dfc9396deb3f5f5810a#729fdc182eaf4af44d822dfc9396deb3f5f5810a" dependencies = [ "cairo-rs", "cocoa", @@ -3558,8 +3564,8 @@ dependencies = [ "glib", "gtk", "image", + "infer", "libc", - "mime_guess", "objc", "objc_id", "once_cell", diff --git a/tauri/examples/helloworld/public/__tauri.js b/tauri/examples/helloworld/public/__tauri.js index f5a6f6dde..2dbd701df 100644 --- a/tauri/examples/helloworld/public/__tauri.js +++ b/tauri/examples/helloworld/public/__tauri.js @@ -103,7 +103,7 @@ if (!String.prototype.startsWith) { return identifier; }; - window.__TAURI__.invoke = function invoke(args) { + window.__TAURI__.invoke = function invoke(cmd, args = {}) { var _this = this; return new Promise(function (resolve, reject) { @@ -116,8 +116,17 @@ if (!String.prototype.startsWith) { delete window[callback]; }, true); - if (window.__TAURI_INVOKE_HANDLER__) { - window.__TAURI_INVOKE_HANDLER__( + if (typeof cmd === "string") { + args.cmd = cmd; + } else if (typeof cmd === "object") { + args = cmd; + } else { + return reject(new Error("Invalid argument type.")); + } + + if (window.rpc) { + window.rpc.notify( + cmd, _objectSpread( { callback: callback, @@ -128,7 +137,8 @@ if (!String.prototype.startsWith) { ); } else { window.addEventListener("DOMContentLoaded", function () { - window.__TAURI_INVOKE_HANDLER__( + window.rpc.notify( + cmd, _objectSpread( { callback: callback, @@ -157,7 +167,7 @@ if (!String.prototype.startsWith) { target.href.startsWith("http") && target.target === "_blank" ) { - window.__TAURI__.invoke({ + window.__TAURI__.invoke('tauri', { __tauriModule: "Shell", message: { cmd: "open", @@ -190,19 +200,19 @@ if (!String.prototype.startsWith) { ); } - window.__TAURI__.invoke({ - __tauriModule: 'Event', + window.__TAURI__.invoke('tauri', { + __tauriModule: "Event", message: { - cmd: 'listen', - event: 'tauri://window-created', + cmd: "listen", + event: "tauri://window-created", handler: window.__TAURI__.transformCallback(function (event) { if (event.payload) { - var windowLabel = event.payload.label - window.__TAURI__.__windows.push({ label: windowLabel }) + var windowLabel = event.payload.label; + window.__TAURI__.__windows.push({ label: windowLabel }); } - }) - } - }) + }), + }, + }); let permissionSettable = false; let permissionValue = "default"; @@ -211,7 +221,7 @@ if (!String.prototype.startsWith) { if (window.Notification.permission !== "default") { return Promise.resolve(window.Notification.permission === "granted"); } - return window.__TAURI__.invoke({ + return window.__TAURI__.invoke('tauri', { __tauriModule: "Notification", message: { cmd: "isNotificationPermissionGranted", @@ -227,7 +237,7 @@ if (!String.prototype.startsWith) { function requestPermission() { return window.__TAURI__ - .invoke({ + .invoke('tauri', { __tauriModule: "Notification", mainThread: true, message: { @@ -247,7 +257,7 @@ if (!String.prototype.startsWith) { isPermissionGranted().then(function (permission) { if (permission) { - return window.__TAURI__.invoke({ + return window.__TAURI__.invoke('tauri', { __tauriModule: "Notification", message: { cmd: "notification", @@ -296,7 +306,7 @@ if (!String.prototype.startsWith) { }); window.alert = function (message) { - window.__TAURI__.invoke({ + window.__TAURI__.invoke('tauri', { __tauriModule: "Dialog", mainThread: true, message: { @@ -307,7 +317,7 @@ if (!String.prototype.startsWith) { }; window.confirm = function (message) { - return window.__TAURI__.invoke({ + return window.__TAURI__.invoke('tauri', { __tauriModule: "Dialog", mainThread: true, message: { diff --git a/tauri/examples/helloworld/src-tauri/Cargo.lock b/tauri/examples/helloworld/src-tauri/Cargo.lock index d9c59b5cd..3c0934961 100644 --- a/tauri/examples/helloworld/src-tauri/Cargo.lock +++ b/tauri/examples/helloworld/src-tauri/Cargo.lock @@ -1242,6 +1242,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "infer" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34ad0755c42f65a1374dcd0aae07e03dfefc911eceb3f409d2b4a888189447e6" + [[package]] name = "instant" version = "0.1.9" @@ -3461,7 +3467,7 @@ dependencies = [ [[package]] name = "wry" version = "0.5.1" -source = "git+https://github.com/tauri-apps/wry?rev=a607d6aba95e6ee0d9620394b7ee0092527095dc#a607d6aba95e6ee0d9620394b7ee0092527095dc" +source = "git+https://github.com/tauri-apps/wry?rev=729fdc182eaf4af44d822dfc9396deb3f5f5810a#729fdc182eaf4af44d822dfc9396deb3f5f5810a" dependencies = [ "cairo-rs", "cocoa", @@ -3472,8 +3478,8 @@ dependencies = [ "glib", "gtk", "image", + "infer", "libc", - "mime_guess", "objc", "objc_id", "once_cell", diff --git a/tauri/examples/multiwindow/dist/__tauri.js b/tauri/examples/multiwindow/dist/__tauri.js index 080e0aa1c..c4bebf829 100644 --- a/tauri/examples/multiwindow/dist/__tauri.js +++ b/tauri/examples/multiwindow/dist/__tauri.js @@ -1,4 +1,4 @@ -function _inherits(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),r&&_setPrototypeOf(e,r)}function _setPrototypeOf(e,r){return(_setPrototypeOf=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e})(e,r)}function _createSuper(e){var r=_isNativeReflectConstruct();return function(){var t,n=_getPrototypeOf(e);if(r){var o=_getPrototypeOf(this).constructor;t=Reflect.construct(n,arguments,o)}else t=n.apply(this,arguments);return _possibleConstructorReturn(this,t)}}function _possibleConstructorReturn(e,r){return!r||"object"!==_typeof(r)&&"function"!=typeof r?_assertThisInitialized(e):r}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _createForOfIteratorHelper(e,r){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=_unsupportedIterableToArray(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,u=!0,i=!1;return{s:function(){t=e[Symbol.iterator]()},n:function(){var e=t.next();return u=e.done,e},e:function(e){i=!0,a=e},f:function(){try{u||null==t.return||t.return()}finally{if(i)throw a}}}}function _unsupportedIterableToArray(e,r){if(e){if("string"==typeof e)return _arrayLikeToArray(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(e,r):void 0}}function _arrayLikeToArray(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t=0;--a){var u=this.tryEntries[a],i=u.completion;if("root"===u.tryLoc)return o("end");if(u.tryLoc<=this.prev){var c=n.call(u,"catchLoc"),s=n.call(u,"finallyLoc");if(c&&s){if(this.prev=0;--t){var o=this.tryEntries[t];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--r){var t=this.tryEntries[r];if(t.finallyLoc===e)return this.complete(t.completion,t.afterLoc),P(t),y}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.tryLoc===e){var n=t.completion;if("throw"===n.type){var o=n.arg;P(t)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:M(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=r),y}},e}("object"===("undefined"==typeof module?"undefined":_typeof(module))?module.exports:{});try{regeneratorRuntime=r}catch(e){Function("r","regeneratorRuntime = r")(r)}function t(e){for(var r=void 0,t=e[0],n=1;n1&&void 0!==arguments[1]&&arguments[1],n=o();return Object.defineProperty(window,n,{value:function(o){return r&&Reflect.deleteProperty(window,n),t([e,"optionalCall",function(e){return e(o)}])},writable:!1,configurable:!0}),n}function u(e){return i.apply(this,arguments)}function i(){return(i=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e,t){var n=a((function(r){e(r),Reflect.deleteProperty(window,o)}),!0),o=a((function(e){t(e),Reflect.deleteProperty(window,n)}),!0);window.__TAURI_INVOKE_HANDLER__(_objectSpread({callback:n,error:o},r))})));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var c=Object.freeze({__proto__:null,transformCallback:a,invoke:u});function s(){return(s=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Cli",message:{cmd:"cliMatches"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var p=Object.freeze({__proto__:null,getMatches:function(){return s.apply(this,arguments)}});function f(){return(f=_asyncToGenerator(regeneratorRuntime.mark((function e(){var r,t=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return"object"===_typeof(r=t.length>0&&void 0!==t[0]?t[0]:{})&&Object.freeze(r),e.abrupt("return",u({__tauriModule:"Dialog",mainThread:!0,message:{cmd:"openDialog",options:r}}));case 3:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function l(){return(l=_asyncToGenerator(regeneratorRuntime.mark((function e(){var r,t=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return"object"===_typeof(r=t.length>0&&void 0!==t[0]?t[0]:{})&&Object.freeze(r),e.abrupt("return",u({__tauriModule:"Dialog",mainThread:!0,message:{cmd:"saveDialog",options:r}}));case 3:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var h=Object.freeze({__proto__:null,open:function(){return f.apply(this,arguments)},save:function(){return l.apply(this,arguments)}});function m(e,r,t){return y.apply(this,arguments)}function y(){return(y=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,u({__tauriModule:"Event",message:{cmd:"listen",event:r,handler:a(t,n),once:n}});case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function d(e,r){return g.apply(this,arguments)}function g(){return(g=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",m(r,t,!1));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function _(e,r){return v.apply(this,arguments)}function v(){return(v=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",m(r,t,!0));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function w(e,r,t){return b.apply(this,arguments)}function b(){return(b=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,u({__tauriModule:"Event",message:{cmd:"emit",event:r,windowLabel:t,payload:n}});case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function R(){return(R=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",w(r,void 0,t));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var k,x=Object.freeze({__proto__:null,emit:function(e,r){return R.apply(this,arguments)},listen:d,once:_});function T(){return(T=_asyncToGenerator(regeneratorRuntime.mark((function e(r){var t,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"readTextFile",path:r,options:t}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function G(){return(G=_asyncToGenerator(regeneratorRuntime.mark((function e(r){var t,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"readBinaryFile",path:r,options:t}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function P(){return(P=_asyncToGenerator(regeneratorRuntime.mark((function e(r){var t,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return"object"===_typeof(t=n.length>1&&void 0!==n[1]?n[1]:{})&&Object.freeze(t),"object"===_typeof(r)&&Object.freeze(r),e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"writeFile",path:r.path,contents:r.contents,options:t}}));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}!function(e){e[e.Audio=1]="Audio";e[e.Cache=2]="Cache";e[e.Config=3]="Config";e[e.Data=4]="Data";e[e.LocalData=5]="LocalData";e[e.Desktop=6]="Desktop";e[e.Document=7]="Document";e[e.Download=8]="Download";e[e.Executable=9]="Executable";e[e.Font=10]="Font";e[e.Home=11]="Home";e[e.Picture=12]="Picture";e[e.Public=13]="Public";e[e.Runtime=14]="Runtime";e[e.Template=15]="Template";e[e.Video=16]="Video";e[e.Resource=17]="Resource";e[e.App=18]="App"}(k||(k={}));var O=65536;function M(e){var r=function(e){if(e.length1&&void 0!==n[1]?n[1]:{})&&Object.freeze(t),"object"===_typeof(r)&&Object.freeze(r),e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"writeBinaryFile",path:r.path,contents:M(r.contents),options:t}}));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function F(){return(F=_asyncToGenerator(regeneratorRuntime.mark((function e(r){var t,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"readDir",path:r,options:t}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function D(){return(D=_asyncToGenerator(regeneratorRuntime.mark((function e(r){var t,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"createDir",path:r,options:t}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function S(){return(S=_asyncToGenerator(regeneratorRuntime.mark((function e(r){var t,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"removeDir",path:r,options:t}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function C(){return(C=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){var n,o=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=o.length>2&&void 0!==o[2]?o[2]:{},e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"copyFile",source:r,destination:t,options:n}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function E(){return(E=_asyncToGenerator(regeneratorRuntime.mark((function e(r){var t,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"removeFile",path:r,options:t}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function A(){return(A=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){var n,o=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=o.length>2&&void 0!==o[2]?o[2]:{},e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"renameFile",oldPath:r,newPath:t,options:n}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var L=Object.freeze({__proto__:null,get BaseDirectory(){return k},get Dir(){return k},readTextFile:function(e){return T.apply(this,arguments)},readBinaryFile:function(e){return G.apply(this,arguments)},writeFile:function(e){return P.apply(this,arguments)},writeBinaryFile:function(e){return j.apply(this,arguments)},readDir:function(e){return F.apply(this,arguments)},createDir:function(e){return D.apply(this,arguments)},removeDir:function(e){return S.apply(this,arguments)},copyFile:function(e,r){return C.apply(this,arguments)},removeFile:function(e){return E.apply(this,arguments)},renameFile:function(e,r){return A.apply(this,arguments)}});function z(){return(z=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:k.App}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function W(){return(W=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:k.Audio}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function N(){return(N=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:k.Cache}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function I(){return(I=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:k.Config}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function H(){return(H=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:k.Data}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function q(){return(q=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:k.Desktop}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function B(){return(B=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:k.Document}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function U(){return(U=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:k.Download}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function K(){return(K=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:k.Executable}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function V(){return(V=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:k.Font}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Y(){return(Y=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:k.Home}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function J(){return(J=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:k.LocalData}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function X(){return(X=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:k.Picture}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function $(){return($=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:k.Public}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Q(){return(Q=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:k.Resource}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Z(){return(Z=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:k.Runtime}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ee(){return(ee=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:k.Template}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function re(){return(re=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:k.Video}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function te(){return(te=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Fs",message:{cmd:"resolvePath",path:r,directory:t}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var ne,oe=Object.freeze({__proto__:null,appDir:function(){return z.apply(this,arguments)},audioDir:function(){return W.apply(this,arguments)},cacheDir:function(){return N.apply(this,arguments)},configDir:function(){return I.apply(this,arguments)},dataDir:function(){return H.apply(this,arguments)},desktopDir:function(){return q.apply(this,arguments)},documentDir:function(){return B.apply(this,arguments)},downloadDir:function(){return U.apply(this,arguments)},executableDir:function(){return K.apply(this,arguments)},fontDir:function(){return V.apply(this,arguments)},homeDir:function(){return Y.apply(this,arguments)},localDataDir:function(){return J.apply(this,arguments)},pictureDir:function(){return X.apply(this,arguments)},publicDir:function(){return $.apply(this,arguments)},resourceDir:function(){return Q.apply(this,arguments)},runtimeDir:function(){return Z.apply(this,arguments)},templateDir:function(){return ee.apply(this,arguments)},videoDir:function(){return re.apply(this,arguments)},resolvePath:function(e,r){return te.apply(this,arguments)}});function ae(e,r){return null!=e?e:r()}function ue(e){for(var r=void 0,t=e[0],n=1;n1&&void 0!==arguments[1]?arguments[1]:{};return _classCallCheck(this,t),n=r.call(this,e),u({__tauriModule:"Window",message:{cmd:"createWebview",options:_objectSpread({label:e},o)}}).then(_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",n.emit("tauri://created"));case 1:case"end":return e.stop()}}),e)})))).catch(function(){var e=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",n.emit("tauri://error",r));case 1:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}()),n}return _createClass(t,null,[{key:"getByLabel",value:function(e){return ge().some((function(r){return r.label===e}))?new ve(e):null}}]),t}(ve),be=new(function(){function e(){_classCallCheck(this,e)}var r,t,n,o,a,i,c,s,p,f,l,h,m,y,d,g,_,v,w,b,R;return _createClass(e,[{key:"setResizable",value:(R=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"setResizable",resizable:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return R.apply(this,arguments)})},{key:"setTitle",value:(b=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"setTitle",title:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return b.apply(this,arguments)})},{key:"maximize",value:(w=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"maximize"}}));case 1:case"end":return e.stop()}}),e)}))),function(){return w.apply(this,arguments)})},{key:"unmaximize",value:(v=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"unmaximize"}}));case 1:case"end":return e.stop()}}),e)}))),function(){return v.apply(this,arguments)})},{key:"minimize",value:(_=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"minimize"}}));case 1:case"end":return e.stop()}}),e)}))),function(){return _.apply(this,arguments)})},{key:"unminimize",value:(g=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"unminimize"}}));case 1:case"end":return e.stop()}}),e)}))),function(){return g.apply(this,arguments)})},{key:"show",value:(d=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"show"}}));case 1:case"end":return e.stop()}}),e)}))),function(){return d.apply(this,arguments)})},{key:"hide",value:(y=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"hide"}}));case 1:case"end":return e.stop()}}),e)}))),function(){return y.apply(this,arguments)})},{key:"setTransparent",value:(m=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"setTransparent",transparent:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return m.apply(this,arguments)})},{key:"setDecorations",value:(h=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"setDecorations",decorations:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return h.apply(this,arguments)})},{key:"setAlwaysOnTop",value:(l=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"setAlwaysOnTop",alwaysOnTop:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return l.apply(this,arguments)})},{key:"setWidth",value:(f=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"setWidth",width:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return f.apply(this,arguments)})},{key:"setHeight",value:(p=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"setHeight",height:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return p.apply(this,arguments)})},{key:"resize",value:(s=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"resize",width:r,height:t}}));case 1:case"end":return e.stop()}}),e)}))),function(e,r){return s.apply(this,arguments)})},{key:"setMinSize",value:(c=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"setMinSize",minWidth:r,minHeight:t}}));case 1:case"end":return e.stop()}}),e)}))),function(e,r){return c.apply(this,arguments)})},{key:"setMaxSize",value:(i=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"setMaxSize",maxWidth:r,maxHeight:t}}));case 1:case"end":return e.stop()}}),e)}))),function(e,r){return i.apply(this,arguments)})},{key:"setX",value:(a=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"setX",x:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return a.apply(this,arguments)})},{key:"setY",value:(o=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"setY",y:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return o.apply(this,arguments)})},{key:"setPosition",value:(n=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"setPosition",x:r,y:t}}));case 1:case"end":return e.stop()}}),e)}))),function(e,r){return n.apply(this,arguments)})},{key:"setFullscreen",value:(t=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"setFullscreen",fullscreen:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})},{key:"setIcon",value:(r=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"Window",message:{cmd:"setIcon",icon:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return r.apply(this,arguments)})}]),e}()),Re=Object.freeze({__proto__:null,WebviewWindow:we,getCurrent:function(){return new ve(window.__TAURI__.__currentWindow.label)},getAll:ge,manager:be});function ke(){return(ke=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("default"===window.Notification.permission){e.next=2;break}return e.abrupt("return",Promise.resolve("granted"===window.Notification.permission));case 2:return e.abrupt("return",u({__tauriModule:"Notification",message:{cmd:"isNotificationPermissionGranted"}}));case 3:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function xe(){return(xe=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",window.Notification.requestPermission());case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Te=Object.freeze({__proto__:null,sendNotification:function(e){"string"==typeof e?new window.Notification(e):new window.Notification(e.title,e)},requestPermission:function(){return xe.apply(this,arguments)},isPermissionGranted:function(){return ke.apply(this,arguments)}});function Ge(){return(Ge=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"GlobalShortcut",message:{cmd:"register",shortcut:r,handler:a(t)}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Pe(){return(Pe=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"GlobalShortcut",message:{cmd:"registerAll",shortcuts:r,handler:a(t)}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Oe(){return(Oe=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"GlobalShortcut",message:{cmd:"isRegistered",shortcut:r}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Me(){return(Me=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"GlobalShortcut",message:{cmd:"unregister",shortcut:r}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function je(){return(je=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u({__tauriModule:"GlobalShortcut",message:{cmd:"unregisterAll"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Fe=Object.freeze({__proto__:null,register:function(e,r){return Ge.apply(this,arguments)},registerAll:function(e,r){return Pe.apply(this,arguments)},isRegistered:function(e){return Oe.apply(this,arguments)},unregister:function(e){return Me.apply(this,arguments)},unregisterAll:function(){return je.apply(this,arguments)}});e.cli=p,e.dialog=h,e.event=x,e.fs=L,e.globalShortcut=Fe,e.http=he,e.notification=Te,e.path=oe,e.shell=de,e.tauri=c,e.window=Re,Object.defineProperty(e,"__esModule",{value:!0})})); +function _inherits(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(r&&r.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),r&&_setPrototypeOf(e,r)}function _setPrototypeOf(e,r){return(_setPrototypeOf=Object.setPrototypeOf||function(e,r){return e.__proto__=r,e})(e,r)}function _createSuper(e){var r=_isNativeReflectConstruct();return function(){var t,n=_getPrototypeOf(e);if(r){var o=_getPrototypeOf(this).constructor;t=Reflect.construct(n,arguments,o)}else t=n.apply(this,arguments);return _possibleConstructorReturn(this,t)}}function _possibleConstructorReturn(e,r){return!r||"object"!==_typeof(r)&&"function"!=typeof r?_assertThisInitialized(e):r}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _createForOfIteratorHelper(e,r){var t;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(t=_unsupportedIterableToArray(e))||r&&e&&"number"==typeof e.length){t&&(e=t);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,u=!0,i=!1;return{s:function(){t=e[Symbol.iterator]()},n:function(){var e=t.next();return u=e.done,e},e:function(e){i=!0,a=e},f:function(){try{u||null==t.return||t.return()}finally{if(i)throw a}}}}function _unsupportedIterableToArray(e,r){if(e){if("string"==typeof e)return _arrayLikeToArray(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(e,r):void 0}}function _arrayLikeToArray(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t=0;--a){var u=this.tryEntries[a],i=u.completion;if("root"===u.tryLoc)return o("end");if(u.tryLoc<=this.prev){var c=n.call(u,"catchLoc"),s=n.call(u,"finallyLoc");if(c&&s){if(this.prev=0;--t){var o=this.tryEntries[t];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev=0;--r){var t=this.tryEntries[r];if(t.finallyLoc===e)return this.complete(t.completion,t.afterLoc),P(t),y}},catch:function(e){for(var r=this.tryEntries.length-1;r>=0;--r){var t=this.tryEntries[r];if(t.tryLoc===e){var n=t.completion;if("throw"===n.type){var o=n.arg;P(t)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,n){return this.delegate={iterator:O(e),resultName:t,nextLoc:n},"next"===this.method&&(this.arg=r),y}},e}("object"===("undefined"==typeof module?"undefined":_typeof(module))?module.exports:{});try{regeneratorRuntime=r}catch(e){Function("r","regeneratorRuntime = r")(r)}function t(e){for(var r=void 0,t=e[0],n=1;n1&&void 0!==arguments[1]&&arguments[1],n=o();return Object.defineProperty(window,n,{value:function(o){return r&&Reflect.deleteProperty(window,n),t([e,"optionalCall",function(e){return e(o)}])},writable:!1,configurable:!0}),n}function u(e){return i.apply(this,arguments)}function i(){return(i=_asyncToGenerator(regeneratorRuntime.mark((function e(r){var t,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",new Promise((function(e,n){var o=a((function(r){e(r),Reflect.deleteProperty(window,u)}),!0),u=a((function(e){n(e),Reflect.deleteProperty(window,o)}),!0);window.rpc.notify(r,_objectSpread({callback:o,error:u},t))})));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var c=Object.freeze({__proto__:null,transformCallback:a,invoke:u});function s(e){return p.apply(this,arguments)}function p(){return(p=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",u("tauri",r));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function f(){return(f=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Cli",message:{cmd:"cliMatches"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var l=Object.freeze({__proto__:null,getMatches:function(){return f.apply(this,arguments)}});function h(){return(h=_asyncToGenerator(regeneratorRuntime.mark((function e(){var r,t=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return"object"===_typeof(r=t.length>0&&void 0!==t[0]?t[0]:{})&&Object.freeze(r),e.abrupt("return",s({__tauriModule:"Dialog",mainThread:!0,message:{cmd:"openDialog",options:r}}));case 3:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function m(){return(m=_asyncToGenerator(regeneratorRuntime.mark((function e(){var r,t=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return"object"===_typeof(r=t.length>0&&void 0!==t[0]?t[0]:{})&&Object.freeze(r),e.abrupt("return",s({__tauriModule:"Dialog",mainThread:!0,message:{cmd:"saveDialog",options:r}}));case 3:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var y=Object.freeze({__proto__:null,open:function(){return h.apply(this,arguments)},save:function(){return m.apply(this,arguments)}});function d(e,r,t){return g.apply(this,arguments)}function g(){return(g=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,s({__tauriModule:"Event",message:{cmd:"listen",event:r,handler:a(t,n),once:n}});case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function _(e,r){return v.apply(this,arguments)}function v(){return(v=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",d(r,t,!1));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function w(e,r){return b.apply(this,arguments)}function b(){return(b=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",d(r,t,!0));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function R(e,r,t){return k.apply(this,arguments)}function k(){return(k=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,s({__tauriModule:"Event",message:{cmd:"emit",event:r,windowLabel:t,payload:n}});case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function x(){return(x=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",R(r,void 0,t));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var T,G=Object.freeze({__proto__:null,emit:function(e,r){return x.apply(this,arguments)},listen:_,once:w});function P(){return(P=_asyncToGenerator(regeneratorRuntime.mark((function e(r){var t,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"readTextFile",path:r,options:t}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function M(){return(M=_asyncToGenerator(regeneratorRuntime.mark((function e(r){var t,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"readBinaryFile",path:r,options:t}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function O(){return(O=_asyncToGenerator(regeneratorRuntime.mark((function e(r){var t,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return"object"===_typeof(t=n.length>1&&void 0!==n[1]?n[1]:{})&&Object.freeze(t),"object"===_typeof(r)&&Object.freeze(r),e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"writeFile",path:r.path,contents:r.contents,options:t}}));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}!function(e){e[e.Audio=1]="Audio";e[e.Cache=2]="Cache";e[e.Config=3]="Config";e[e.Data=4]="Data";e[e.LocalData=5]="LocalData";e[e.Desktop=6]="Desktop";e[e.Document=7]="Document";e[e.Download=8]="Download";e[e.Executable=9]="Executable";e[e.Font=10]="Font";e[e.Home=11]="Home";e[e.Picture=12]="Picture";e[e.Public=13]="Public";e[e.Runtime=14]="Runtime";e[e.Template=15]="Template";e[e.Video=16]="Video";e[e.Resource=17]="Resource";e[e.App=18]="App"}(T||(T={}));var j=65536;function F(e){var r=function(e){if(e.length1&&void 0!==n[1]?n[1]:{})&&Object.freeze(t),"object"===_typeof(r)&&Object.freeze(r),e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"writeBinaryFile",path:r.path,contents:F(r.contents),options:t}}));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function S(){return(S=_asyncToGenerator(regeneratorRuntime.mark((function e(r){var t,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"readDir",path:r,options:t}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function C(){return(C=_asyncToGenerator(regeneratorRuntime.mark((function e(r){var t,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"createDir",path:r,options:t}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function E(){return(E=_asyncToGenerator(regeneratorRuntime.mark((function e(r){var t,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"removeDir",path:r,options:t}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function A(){return(A=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){var n,o=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=o.length>2&&void 0!==o[2]?o[2]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"copyFile",source:r,destination:t,options:n}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function z(){return(z=_asyncToGenerator(regeneratorRuntime.mark((function e(r){var t,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"removeFile",path:r,options:t}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function L(){return(L=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){var n,o=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=o.length>2&&void 0!==o[2]?o[2]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"renameFile",oldPath:r,newPath:t,options:n}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var W=Object.freeze({__proto__:null,get BaseDirectory(){return T},get Dir(){return T},readTextFile:function(e){return P.apply(this,arguments)},readBinaryFile:function(e){return M.apply(this,arguments)},writeFile:function(e){return O.apply(this,arguments)},writeBinaryFile:function(e){return D.apply(this,arguments)},readDir:function(e){return S.apply(this,arguments)},createDir:function(e){return C.apply(this,arguments)},removeDir:function(e){return E.apply(this,arguments)},copyFile:function(e,r){return A.apply(this,arguments)},removeFile:function(e){return z.apply(this,arguments)},renameFile:function(e,r){return L.apply(this,arguments)}});function N(){return(N=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:T.App}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function I(){return(I=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:T.Audio}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function H(){return(H=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:T.Cache}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function q(){return(q=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:T.Config}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function B(){return(B=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:T.Data}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function U(){return(U=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:T.Desktop}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Y(){return(Y=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:T.Document}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function J(){return(J=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:T.Download}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function K(){return(K=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:T.Executable}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function V(){return(V=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:T.Font}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function X(){return(X=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:T.Home}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function $(){return($=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:T.LocalData}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Q(){return(Q=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:T.Picture}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Z(){return(Z=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:T.Public}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ee(){return(ee=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:T.Resource}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function re(){return(re=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:T.Runtime}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function te(){return(te=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:T.Template}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ne(){return(ne=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:T.Video}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function oe(){return(oe=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:r,directory:t}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var ae,ue=Object.freeze({__proto__:null,appDir:function(){return N.apply(this,arguments)},audioDir:function(){return I.apply(this,arguments)},cacheDir:function(){return H.apply(this,arguments)},configDir:function(){return q.apply(this,arguments)},dataDir:function(){return B.apply(this,arguments)},desktopDir:function(){return U.apply(this,arguments)},documentDir:function(){return Y.apply(this,arguments)},downloadDir:function(){return J.apply(this,arguments)},executableDir:function(){return K.apply(this,arguments)},fontDir:function(){return V.apply(this,arguments)},homeDir:function(){return X.apply(this,arguments)},localDataDir:function(){return $.apply(this,arguments)},pictureDir:function(){return Q.apply(this,arguments)},publicDir:function(){return Z.apply(this,arguments)},resourceDir:function(){return ee.apply(this,arguments)},runtimeDir:function(){return re.apply(this,arguments)},templateDir:function(){return te.apply(this,arguments)},videoDir:function(){return ne.apply(this,arguments)},resolvePath:function(e,r){return oe.apply(this,arguments)}});function ie(e,r){return null!=e?e:r()}function ce(e){for(var r=void 0,t=e[0],n=1;n1&&void 0!==arguments[1]?arguments[1]:{};return _classCallCheck(this,t),n=r.call(this,e),s({__tauriModule:"Window",message:{cmd:"createWebview",options:_objectSpread({label:e},o)}}).then(_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",n.emit("tauri://created"));case 1:case"end":return e.stop()}}),e)})))).catch(function(){var e=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",n.emit("tauri://error",r));case 1:case"end":return e.stop()}}),e)})));return function(r){return e.apply(this,arguments)}}()),n}return _createClass(t,null,[{key:"getByLabel",value:function(e){return ve().some((function(r){return r.label===e}))?new be(e):null}}]),t}(be),ke=new(function(){function e(){_classCallCheck(this,e)}var r,t,n,o,a,u,i,c,p,f,l,h,m,y,d,g,_,v,w,b,R;return _createClass(e,[{key:"setResizable",value:(R=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"setResizable",resizable:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return R.apply(this,arguments)})},{key:"setTitle",value:(b=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"setTitle",title:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return b.apply(this,arguments)})},{key:"maximize",value:(w=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"maximize"}}));case 1:case"end":return e.stop()}}),e)}))),function(){return w.apply(this,arguments)})},{key:"unmaximize",value:(v=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"unmaximize"}}));case 1:case"end":return e.stop()}}),e)}))),function(){return v.apply(this,arguments)})},{key:"minimize",value:(_=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"minimize"}}));case 1:case"end":return e.stop()}}),e)}))),function(){return _.apply(this,arguments)})},{key:"unminimize",value:(g=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"unminimize"}}));case 1:case"end":return e.stop()}}),e)}))),function(){return g.apply(this,arguments)})},{key:"show",value:(d=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"show"}}));case 1:case"end":return e.stop()}}),e)}))),function(){return d.apply(this,arguments)})},{key:"hide",value:(y=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"hide"}}));case 1:case"end":return e.stop()}}),e)}))),function(){return y.apply(this,arguments)})},{key:"close",value:(m=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"close"}}));case 1:case"end":return e.stop()}}),e)}))),function(){return m.apply(this,arguments)})},{key:"setDecorations",value:(h=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"setDecorations",decorations:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return h.apply(this,arguments)})},{key:"setAlwaysOnTop",value:(l=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"setAlwaysOnTop",alwaysOnTop:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return l.apply(this,arguments)})},{key:"setWidth",value:(f=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"setWidth",width:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return f.apply(this,arguments)})},{key:"setHeight",value:(p=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"setHeight",height:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return p.apply(this,arguments)})},{key:"resize",value:(c=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"resize",width:r,height:t}}));case 1:case"end":return e.stop()}}),e)}))),function(e,r){return c.apply(this,arguments)})},{key:"setMinSize",value:(i=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"setMinSize",minWidth:r,minHeight:t}}));case 1:case"end":return e.stop()}}),e)}))),function(e,r){return i.apply(this,arguments)})},{key:"setMaxSize",value:(u=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"setMaxSize",maxWidth:r,maxHeight:t}}));case 1:case"end":return e.stop()}}),e)}))),function(e,r){return u.apply(this,arguments)})},{key:"setX",value:(a=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"setX",x:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return a.apply(this,arguments)})},{key:"setY",value:(o=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"setY",y:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return o.apply(this,arguments)})},{key:"setPosition",value:(n=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"setPosition",x:r,y:t}}));case 1:case"end":return e.stop()}}),e)}))),function(e,r){return n.apply(this,arguments)})},{key:"setFullscreen",value:(t=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"setFullscreen",fullscreen:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return t.apply(this,arguments)})},{key:"setIcon",value:(r=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"setIcon",icon:r}}));case 1:case"end":return e.stop()}}),e)}))),function(e){return r.apply(this,arguments)})}]),e}()),xe=Object.freeze({__proto__:null,WebviewWindow:Re,getCurrent:function(){return new be(window.__TAURI__.__currentWindow.label)},getAll:ve,manager:ke});function Te(){return(Te=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("default"===window.Notification.permission){e.next=2;break}return e.abrupt("return",Promise.resolve("granted"===window.Notification.permission));case 2:return e.abrupt("return",s({__tauriModule:"Notification",message:{cmd:"isNotificationPermissionGranted"}}));case 3:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ge(){return(Ge=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",window.Notification.requestPermission());case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Pe=Object.freeze({__proto__:null,sendNotification:function(e){"string"==typeof e?new window.Notification(e):new window.Notification(e.title,e)},requestPermission:function(){return Ge.apply(this,arguments)},isPermissionGranted:function(){return Te.apply(this,arguments)}});function Me(){return(Me=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"GlobalShortcut",message:{cmd:"register",shortcut:r,handler:a(t)}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Oe(){return(Oe=_asyncToGenerator(regeneratorRuntime.mark((function e(r,t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"GlobalShortcut",message:{cmd:"registerAll",shortcuts:r,handler:a(t)}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function je(){return(je=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"GlobalShortcut",message:{cmd:"isRegistered",shortcut:r}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Fe(){return(Fe=_asyncToGenerator(regeneratorRuntime.mark((function e(r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"GlobalShortcut",message:{cmd:"unregister",shortcut:r}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function De(){return(De=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"GlobalShortcut",message:{cmd:"unregisterAll"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Se=Object.freeze({__proto__:null,register:function(e,r){return Me.apply(this,arguments)},registerAll:function(e,r){return Oe.apply(this,arguments)},isRegistered:function(e){return je.apply(this,arguments)},unregister:function(e){return Fe.apply(this,arguments)},unregisterAll:function(){return De.apply(this,arguments)}});e.cli=l,e.dialog=y,e.event=G,e.fs=W,e.globalShortcut=Se,e.http=ye,e.notification=Pe,e.path=ue,e.shell=_e,e.tauri=c,e.window=xe,Object.defineProperty(e,"__esModule",{value:!0})})); // polyfills @@ -106,7 +106,7 @@ if (!String.prototype.startsWith) { return identifier; }; - window.__TAURI__.invoke = function invoke(args) { + window.__TAURI__.invoke = function invoke(cmd, args = {}) { var _this = this; return new Promise(function (resolve, reject) { @@ -119,8 +119,17 @@ if (!String.prototype.startsWith) { delete window[callback]; }, true); - if (window.__TAURI_INVOKE_HANDLER__) { - window.__TAURI_INVOKE_HANDLER__( + if (typeof cmd === "string") { + args.cmd = cmd; + } else if (typeof cmd === "object") { + args = cmd; + } else { + return reject(new Error("Invalid argument type.")); + } + + if (window.rpc) { + window.rpc.notify( + cmd, _objectSpread( { callback: callback, @@ -131,7 +140,8 @@ if (!String.prototype.startsWith) { ); } else { window.addEventListener("DOMContentLoaded", function () { - window.__TAURI_INVOKE_HANDLER__( + window.rpc.notify( + cmd, _objectSpread( { callback: callback, @@ -160,7 +170,7 @@ if (!String.prototype.startsWith) { target.href.startsWith("http") && target.target === "_blank" ) { - window.__TAURI__.invoke({ + window.__TAURI__.invoke('tauri', { __tauriModule: "Shell", message: { cmd: "open", @@ -193,19 +203,19 @@ if (!String.prototype.startsWith) { ); } - window.__TAURI__.invoke({ - __tauriModule: 'Event', + window.__TAURI__.invoke('tauri', { + __tauriModule: "Event", message: { - cmd: 'listen', - event: 'tauri://window-created', + cmd: "listen", + event: "tauri://window-created", handler: window.__TAURI__.transformCallback(function (event) { if (event.payload) { - var windowLabel = event.payload.label - window.__TAURI__.__windows.push({ label: windowLabel }) + var windowLabel = event.payload.label; + window.__TAURI__.__windows.push({ label: windowLabel }); } - }) - } - }) + }), + }, + }); let permissionSettable = false; let permissionValue = "default"; @@ -214,7 +224,7 @@ if (!String.prototype.startsWith) { if (window.Notification.permission !== "default") { return Promise.resolve(window.Notification.permission === "granted"); } - return window.__TAURI__.invoke({ + return window.__TAURI__.invoke('tauri', { __tauriModule: "Notification", message: { cmd: "isNotificationPermissionGranted", @@ -230,7 +240,7 @@ if (!String.prototype.startsWith) { function requestPermission() { return window.__TAURI__ - .invoke({ + .invoke('tauri', { __tauriModule: "Notification", mainThread: true, message: { @@ -250,7 +260,7 @@ if (!String.prototype.startsWith) { isPermissionGranted().then(function (permission) { if (permission) { - return window.__TAURI__.invoke({ + return window.__TAURI__.invoke('tauri', { __tauriModule: "Notification", message: { cmd: "notification", @@ -299,7 +309,7 @@ if (!String.prototype.startsWith) { }); window.alert = function (message) { - window.__TAURI__.invoke({ + window.__TAURI__.invoke('tauri', { __tauriModule: "Dialog", mainThread: true, message: { @@ -310,7 +320,7 @@ if (!String.prototype.startsWith) { }; window.confirm = function (message) { - return window.__TAURI__.invoke({ + return window.__TAURI__.invoke('tauri', { __tauriModule: "Dialog", mainThread: true, message: { diff --git a/tauri/examples/multiwindow/src-tauri/Cargo.lock b/tauri/examples/multiwindow/src-tauri/Cargo.lock index 440b44e12..f4e5ecf2d 100644 --- a/tauri/examples/multiwindow/src-tauri/Cargo.lock +++ b/tauri/examples/multiwindow/src-tauri/Cargo.lock @@ -1240,6 +1240,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "infer" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34ad0755c42f65a1374dcd0aae07e03dfefc911eceb3f409d2b4a888189447e6" + [[package]] name = "instant" version = "0.1.9" @@ -3459,7 +3465,7 @@ dependencies = [ [[package]] name = "wry" version = "0.5.1" -source = "git+https://github.com/tauri-apps/wry?rev=a607d6aba95e6ee0d9620394b7ee0092527095dc#a607d6aba95e6ee0d9620394b7ee0092527095dc" +source = "git+https://github.com/tauri-apps/wry?rev=729fdc182eaf4af44d822dfc9396deb3f5f5810a#729fdc182eaf4af44d822dfc9396deb3f5f5810a" dependencies = [ "cairo-rs", "cocoa", @@ -3470,8 +3476,8 @@ dependencies = [ "glib", "gtk", "image", + "infer", "libc", - "mime_guess", "objc", "objc_id", "once_cell", diff --git a/tauri/src/app.rs b/tauri/src/app.rs index 95f69ebe9..515dac7cc 100644 --- a/tauri/src/app.rs +++ b/tauri/src/app.rs @@ -1,5 +1,5 @@ use futures::future::BoxFuture; -use serde::{Deserialize, Serialize}; +use serde::Serialize; use serde_json::Value as JsonValue; use tauri_api::{config::Config, private::AsTauriContext}; @@ -15,12 +15,12 @@ mod webview_manager; pub use crate::api::config::WindowUrl; use crate::flavors::Wry; pub use webview::{ - wry::WryApplication, ApplicationDispatcherExt, ApplicationExt, Callback, CustomProtocol, Icon, - Message, WebviewBuilderExt, + wry::WryApplication, ApplicationDispatcherExt, ApplicationExt, CustomProtocol, Icon, Message, + RpcRequest, WebviewBuilderExt, WebviewRpcHandler, }; pub use webview_manager::{WebviewDispatcher, WebviewManager}; -type InvokeHandler = dyn Fn(WebviewManager, String) -> BoxFuture<'static, crate::Result> +type InvokeHandler = dyn Fn(WebviewManager, String, JsonValue) -> BoxFuture<'static, crate::Result> + Send + Sync; type Setup = dyn Fn(WebviewManager) -> BoxFuture<'static, ()> + Send + Sync; @@ -63,15 +63,6 @@ impl From for InvokeResponse { } } -#[derive(Deserialize)] -#[allow(missing_docs)] -#[serde(tag = "cmd", rename_all = "camelCase")] -pub struct DispatchInstructions { - pub cmd: String, - #[serde(flatten)] - pub args: JsonValue, -} - /// The application runner. pub struct App { /// The JS message handler. @@ -116,10 +107,11 @@ impl App { pub(crate) async fn run_invoke_handler( &self, dispatcher: &WebviewManager, + command: String, arg: &JsonValue, ) -> crate::Result> { if let Some(ref invoke_handler) = self.invoke_handler { - let fut = invoke_handler(dispatcher.clone(), arg.to_string()); + let fut = invoke_handler(dispatcher.clone(), command, arg.clone()); fut.await.map(Some) } else { Ok(None) @@ -142,7 +134,7 @@ trait WebviewInitializer { webview: Webview, ) -> crate::Result<( ::WebviewBuilder, - Vec>, + Option>, Option, )>; @@ -161,7 +153,7 @@ impl WebviewInitializer for Arc> { webview: Webview, ) -> crate::Result<( ::WebviewBuilder, - Vec>, + Option>, Option, )> { let webview_manager = WebviewManager::new( @@ -229,13 +221,13 @@ impl AppBuilder { /// Defines the JS message handler callback. pub fn invoke_handler< T: futures::Future> + Send + Sync + 'static, - F: Fn(WebviewManager, String) -> T + Send + Sync + 'static, + F: Fn(WebviewManager, String, JsonValue) -> T + Send + Sync + 'static, >( mut self, invoke_handler: F, ) -> Self { - self.invoke_handler = Some(Box::new(move |webview_manager, arg| { - Box::pin(invoke_handler(webview_manager, arg)) + self.invoke_handler = Some(Box::new(move |webview_manager, command, args| { + Box::pin(invoke_handler(webview_manager, command, args)) })); self } @@ -319,10 +311,10 @@ fn run(mut application: App) -> crate::Result<() application.dispatchers.clone(), webview_label.to_string(), ); - let (webview_builder, callbacks, custom_protocol) = + let (webview_builder, rpc_handler, custom_protocol) = crate::async_runtime::block_on(application.init_webview(webview))?; - let dispatcher = webview_app.create_webview(webview_builder, callbacks, custom_protocol)?; + let dispatcher = webview_app.create_webview(webview_builder, rpc_handler, custom_protocol)?; crate::async_runtime::block_on(application.on_webview_created( webview_label, dispatcher, diff --git a/tauri/src/app/utils.rs b/tauri/src/app/utils.rs index 0bcb7b6bf..008d98df1 100644 --- a/tauri/src/app/utils.rs +++ b/tauri/src/app/utils.rs @@ -11,8 +11,8 @@ use crate::{ }; use super::{ - webview::{Callback, CustomProtocol, WebviewBuilderExtPrivate}, - App, Context, Webview, WebviewManager, + webview::{CustomProtocol, WebviewBuilderExtPrivate, WebviewRpcHandler}, + App, Context, RpcRequest, Webview, WebviewManager, }; use serde::Deserialize; @@ -84,11 +84,11 @@ pub(super) fn initialization_script( r#" {tauri_initialization_script} {event_initialization_script} - if (window.__TAURI_INVOKE_HANDLER__) {{ - window.__TAURI__.invoke({{ cmd: "__initialized" }}) + if (window.rpc) {{ + window.__TAURI__.invoke("__initialized") }} else {{ window.addEventListener('DOMContentLoaded', function () {{ - window.__TAURI__.invoke({{ cmd: "__initialized" }}) + window.__TAURI__.invoke("__initialized") }}) }} {plugin_initialization_script} @@ -140,7 +140,7 @@ fn event_initialization_script() -> String { pub(super) type BuiltWebview = ( ::WebviewBuilder, - Vec::Dispatcher>>, + Option::Dispatcher>>, Option, ); @@ -164,7 +164,7 @@ pub(super) fn build_webview( WindowUrl::App => true, WindowUrl::Custom(url) => &url[0..8] == "tauri://", }; - let (webview_builder, callbacks, custom_protocol) = if is_local { + let (webview_builder, rpc_handler, custom_protocol) = if is_local { let mut webview_builder = webview.builder.url(webview_url) .initialization_script(&initialization_script(plugin_initialization_script, &context.tauri_script)) .initialization_script(&format!( @@ -184,10 +184,17 @@ pub(super) fn build_webview( } let webview_manager_ = webview_manager.clone(); - let tauri_invoke_handler = crate::Callback:: { - name: "__TAURI_INVOKE_HANDLER__".to_string(), - function: Box::new(move |_, arg| { - let arg = arg.into_iter().next().unwrap_or(JsonValue::Null); + let rpc_handler: Box::Dispatcher, RpcRequest) + Send> = + Box::new(move |_, request: RpcRequest| { + let command = request.command.clone(); + let arg = request + .params + .unwrap() + .as_array_mut() + .unwrap() + .first_mut() + .unwrap_or(&mut JsonValue::Null) + .take(); let webview_manager = webview_manager_.clone(); match serde_json::from_value::(arg) { Ok(message) => { @@ -199,7 +206,12 @@ pub(super) fn build_webview( crate::async_runtime::block_on(async move { execute_promise( &webview_manager, - on_message(application, webview_manager.clone(), message), + on_message( + application, + webview_manager.clone(), + command.clone(), + message, + ), callback, error, ) @@ -209,7 +221,7 @@ pub(super) fn build_webview( crate::async_runtime::spawn(async move { execute_promise( &webview_manager, - on_message(application, webview_manager.clone(), message), + on_message(application, webview_manager.clone(), command, message), callback, error, ) @@ -229,8 +241,7 @@ pub(super) fn build_webview( } } } - }), - }; + }); let assets = context.assets; let custom_protocol = CustomProtocol { name: "tauri".into(), @@ -268,16 +279,12 @@ pub(super) fn build_webview( } }), }; - ( - webview_builder, - vec![tauri_invoke_handler], - Some(custom_protocol), - ) + (webview_builder, Some(rpc_handler), Some(custom_protocol)) } else { - (webview.builder.url(webview_url), Vec::new(), None) + (webview.builder.url(webview_url), None, None) }; - Ok((webview_builder, callbacks, custom_protocol)) + Ok((webview_builder, rpc_handler, custom_protocol)) } /// Asynchronously executes the given task @@ -313,9 +320,10 @@ async fn execute_promise< async fn on_message( application: Arc>, webview_manager: WebviewManager, + command: String, message: Message, ) -> crate::Result { - if message.inner == serde_json::json!({ "cmd":"__initialized" }) { + if &command == "__initialized" { application.run_setup(&webview_manager).await; crate::plugin::ready(A::plugin_store(), &webview_manager).await; Ok(().into()) @@ -330,7 +338,7 @@ async fn on_message( .await } else { let mut response = match application - .run_invoke_handler(&webview_manager, &message.inner) + .run_invoke_handler(&webview_manager, command.clone(), &message.inner) .await { Ok(value) => { @@ -343,7 +351,14 @@ async fn on_message( Err(e) => Err(e), }; if let Err(crate::Error::UnknownApi(_)) = response { - match crate::plugin::extend_api(A::plugin_store(), &webview_manager, &message.inner).await { + match crate::plugin::extend_api( + A::plugin_store(), + &webview_manager, + command, + &message.inner, + ) + .await + { Ok(value) => { // If value is None, that means that no plugin matched the command // and the UnknownApi error should be sent to the webview diff --git a/tauri/src/app/webview.rs b/tauri/src/app/webview.rs index e88b88e4d..8dd3588e4 100644 --- a/tauri/src/app/webview.rs +++ b/tauri/src/app/webview.rs @@ -157,14 +157,17 @@ pub trait WebviewBuilderExt: Sized { fn finish(self) -> crate::Result; } -/// Binds the given callback to a global variable on the window object. -pub struct Callback { - /// Function name to bind. - pub name: String, - /// Function callback handler. - pub function: Box) + Send>, +/// Rpc request. +pub struct RpcRequest { + /// RPC command. + pub command: String, + /// Params. + pub params: Option, } +/// Rpc handler. +pub type WebviewRpcHandler = Box; + /// Uses a custom handler to resolve file requests pub struct CustomProtocol { /// Name of the protocol @@ -185,7 +188,7 @@ pub trait ApplicationDispatcherExt: Clone + Send + Sync + Sized { fn create_webview( &self, webview_builder: Self::WebviewBuilder, - callbacks: Vec>, + rpc_handler: Option>, custom_protocol: Option, ) -> crate::Result; @@ -278,7 +281,7 @@ pub trait ApplicationExt: Sized { fn create_webview( &mut self, webview_builder: Self::WebviewBuilder, - callbacks: Vec>, + rpc_handler: Option>, custom_protocol: Option, ) -> crate::Result; diff --git a/tauri/src/app/webview/wry.rs b/tauri/src/app/webview/wry.rs index fb41a990e..e21c2e23a 100644 --- a/tauri/src/app/webview/wry.rs +++ b/tauri/src/app/webview/wry.rs @@ -1,6 +1,6 @@ use super::{ - ApplicationDispatcherExt, ApplicationExt, Callback, CustomProtocol, Icon, WebviewBuilderExt, - WebviewBuilderExtPrivate, WindowConfig, + ApplicationDispatcherExt, ApplicationExt, CustomProtocol, Icon, RpcRequest, WebviewBuilderExt, + WebviewBuilderExtPrivate, WebviewRpcHandler, WindowConfig, }; use once_cell::sync::Lazy; @@ -177,6 +177,15 @@ impl WebviewBuilderExt for wry::Attributes { } } +impl From for RpcRequest { + fn from(request: wry::RpcRequest) -> Self { + Self { + command: request.method, + params: request.params, + } + } +} + #[derive(Clone)] pub struct WryDispatcher( Arc>, @@ -189,25 +198,22 @@ impl ApplicationDispatcherExt for WryDispatcher { fn create_webview( &self, attributes: Self::WebviewBuilder, - callbacks: Vec>, + rpc_handler: Option>, custom_protocol: Option, ) -> crate::Result { - let mut wry_callbacks = Vec::new(); let app_dispatcher = self.1.clone(); - for mut callback in callbacks { - let app_dispatcher = app_dispatcher.clone(); - let callback = wry::Callback { - name: callback.name.to_string(), - function: Box::new(move |dispatcher, _, req| { - (callback.function)( - Self(Arc::new(Mutex::new(dispatcher)), app_dispatcher.clone()), - req, + + let wry_rpc_handler = Box::new( + move |dispatcher: wry::WindowProxy, request: wry::RpcRequest| { + if let Some(handler) = &rpc_handler { + handler( + WryDispatcher(Arc::new(Mutex::new(dispatcher)), app_dispatcher.clone()), + request.into(), ); - Ok(()) - }), - }; - wry_callbacks.push(callback); - } + } + None + }, + ); let window_dispatcher = self .1 @@ -215,7 +221,7 @@ impl ApplicationDispatcherExt for WryDispatcher { .unwrap() .add_window_with_configs( attributes, - Some(wry_callbacks), + Some(wry_rpc_handler), custom_protocol.map(|p| wry::CustomProtocol { name: p.name.clone(), handler: Box::new(move |a| (*p.handler)(a).map_err(|_| wry::Error::InitScriptError)), @@ -449,31 +455,29 @@ impl ApplicationExt for WryApplication { fn create_webview( &mut self, webview_builder: Self::WebviewBuilder, - callbacks: Vec>, + rpc_handler: Option>, custom_protocol: Option, ) -> crate::Result { - let mut wry_callbacks = Vec::new(); let app_dispatcher = Arc::new(Mutex::new(self.inner.application_proxy())); - for mut callback in callbacks { - let app_dispatcher = app_dispatcher.clone(); - let callback = wry::Callback { - name: callback.name.to_string(), - function: Box::new(move |dispatcher, _, req| { - (callback.function)( - WryDispatcher(Arc::new(Mutex::new(dispatcher)), app_dispatcher.clone()), - req, + + let app_dispatcher_ = app_dispatcher.clone(); + let wry_rpc_handler = Box::new( + move |dispatcher: wry::WindowProxy, request: wry::RpcRequest| { + if let Some(handler) = &rpc_handler { + handler( + WryDispatcher(Arc::new(Mutex::new(dispatcher)), app_dispatcher_.clone()), + request.into(), ); - Ok(()) - }), - }; - wry_callbacks.push(callback); - } + } + None + }, + ); let dispatcher = self .inner .add_window_with_configs( webview_builder.finish()?, - Some(wry_callbacks), + Some(wry_rpc_handler), custom_protocol.map(|p| wry::CustomProtocol { name: p.name.clone(), handler: Box::new(move |a| (*p.handler)(a).map_err(|_| wry::Error::InitScriptError)), diff --git a/tauri/src/app/webview_manager.rs b/tauri/src/app/webview_manager.rs index 4ae42b91c..96924d990 100644 --- a/tauri/src/app/webview_manager.rs +++ b/tauri/src/app/webview_manager.rs @@ -250,12 +250,12 @@ impl WebviewManager { .lock() .await .push(label.to_string()); - let (webview_builder, callbacks, custom_protocol) = + let (webview_builder, rpc_handler, custom_protocol) = self.application.init_webview(webview).await?; let window_dispatcher = self.current_webview().await?.dispatcher.create_webview( webview_builder, - callbacks, + rpc_handler, custom_protocol, )?; let webview_manager = Self::new( diff --git a/tauri/src/endpoints/file_system.rs b/tauri/src/endpoints/file_system.rs index 3d909ed80..56722cad5 100644 --- a/tauri/src/endpoints/file_system.rs +++ b/tauri/src/endpoints/file_system.rs @@ -374,7 +374,7 @@ mod test { // .resizable(true) // .debug(true) // .user_data(()) - // .invoke_handler(|_wv, _arg| Ok(())) + // .invoke_handler(|_wv, _command, _arg| Ok(())) // .content(Content::Html(content)) // .build()?, // ) diff --git a/tauri/src/plugin.rs b/tauri/src/plugin.rs index 7e560e267..903f720b1 100644 --- a/tauri/src/plugin.rs +++ b/tauri/src/plugin.rs @@ -39,6 +39,7 @@ pub trait Plugin: Send + Sync { async fn extend_api( &mut self, webview_manager: WebviewManager, + command: String, payload: &JsonValue, ) -> crate::Result { Err(crate::Error::UnknownApi(None)) @@ -123,11 +124,15 @@ pub(crate) async fn ready( pub(crate) async fn extend_api( store: &PluginStore, webview_manager: &crate::WebviewManager, + command: String, arg: &JsonValue, ) -> crate::Result> { let mut plugins = store.lock().await; for ext in plugins.iter_mut() { - match ext.extend_api(webview_manager.clone(), arg).await { + match ext + .extend_api(webview_manager.clone(), command.clone(), arg) + .await + { Ok(value) => { return Ok(Some(value)); }