diff --git a/build.rs b/build.rs deleted file mode 100644 index e8baf46..0000000 --- a/build.rs +++ /dev/null @@ -1,33 +0,0 @@ -use std::process::Command; - -fn main() { - /* Shared arguments */ - let sargs: &[&str] = &[ - "--outdir=dist", - "--format=esm", - "--bundle", - "tauri/tooling/api/src/app.ts", - "tauri/tooling/api/src/clipboard.ts", - "tauri/tooling/api/src/tauri.ts", - "tauri/tooling/api/src/event.ts", - "tauri/tooling/api/src/mocks.ts", - "tauri/tooling/api/src/window.ts", - "tauri/tooling/api/src/process.ts" - ]; - - if cfg!(windows) { - /* Use cmd if the target is windows */ - Command::new("cmd") - .args(&["/C", "esbuild"]) - .args(sargs) - .output() - .unwrap(); - } else if cfg!(unix) { - Command::new("esbuild") - .args(sargs) - .output() - .unwrap(); - } else { - panic!("Unsupported build target"); - } -} diff --git a/package.json b/package.json new file mode 100644 index 0000000..b99b41c --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "tauri-sys", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "build": "esbuild --outdir=src --format=esm --bundle tauri/tooling/api/src/*.ts" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "esbuild": "^0.15.13" + } +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml new file mode 100644 index 0000000..fbedf0f --- /dev/null +++ b/pnpm-lock.yaml @@ -0,0 +1,237 @@ +lockfileVersion: 5.4 + +specifiers: + esbuild: ^0.15.13 + +devDependencies: + esbuild: 0.15.13 + +packages: + + /@esbuild/android-arm/0.15.13: + resolution: {integrity: sha512-RY2fVI8O0iFUNvZirXaQ1vMvK0xhCcl0gqRj74Z6yEiO1zAUa7hbsdwZM1kzqbxHK7LFyMizipfXT3JME+12Hw==} + engines: {node: '>=12'} + cpu: [arm] + os: [android] + requiresBuild: true + dev: true + optional: true + + /@esbuild/linux-loong64/0.15.13: + resolution: {integrity: sha512-+BoyIm4I8uJmH/QDIH0fu7MG0AEx9OXEDXnqptXCwKOlOqZiS4iraH1Nr7/ObLMokW3sOCeBNyD68ATcV9b9Ag==} + engines: {node: '>=12'} + cpu: [loong64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-android-64/0.15.13: + resolution: {integrity: sha512-yRorukXBlokwTip+Sy4MYskLhJsO0Kn0/Fj43s1krVblfwP+hMD37a4Wmg139GEsMLl+vh8WXp2mq/cTA9J97g==} + engines: {node: '>=12'} + cpu: [x64] + os: [android] + requiresBuild: true + dev: true + optional: true + + /esbuild-android-arm64/0.15.13: + resolution: {integrity: sha512-TKzyymLD6PiVeyYa4c5wdPw87BeAiTXNtK6amWUcXZxkV51gOk5u5qzmDaYSwiWeecSNHamFsaFjLoi32QR5/w==} + engines: {node: '>=12'} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: true + optional: true + + /esbuild-darwin-64/0.15.13: + resolution: {integrity: sha512-WAx7c2DaOS6CrRcoYCgXgkXDliLnFv3pQLV6GeW1YcGEZq2Gnl8s9Pg7ahValZkpOa0iE/ojRVQ87sbUhF1Cbg==} + engines: {node: '>=12'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /esbuild-darwin-arm64/0.15.13: + resolution: {integrity: sha512-U6jFsPfSSxC3V1CLiQqwvDuj3GGrtQNB3P3nNC3+q99EKf94UGpsG9l4CQ83zBs1NHrk1rtCSYT0+KfK5LsD8A==} + engines: {node: '>=12'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: true + optional: true + + /esbuild-freebsd-64/0.15.13: + resolution: {integrity: sha512-whItJgDiOXaDG/idy75qqevIpZjnReZkMGCgQaBWZuKHoElDJC1rh7MpoUgupMcdfOd+PgdEwNQW9DAE6i8wyA==} + engines: {node: '>=12'} + cpu: [x64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + + /esbuild-freebsd-arm64/0.15.13: + resolution: {integrity: sha512-6pCSWt8mLUbPtygv7cufV0sZLeylaMwS5Fznj6Rsx9G2AJJsAjQ9ifA+0rQEIg7DwJmi9it+WjzNTEAzzdoM3Q==} + engines: {node: '>=12'} + cpu: [arm64] + os: [freebsd] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-32/0.15.13: + resolution: {integrity: sha512-VbZdWOEdrJiYApm2kkxoTOgsoCO1krBZ3quHdYk3g3ivWaMwNIVPIfEE0f0XQQ0u5pJtBsnk2/7OPiCFIPOe/w==} + engines: {node: '>=12'} + cpu: [ia32] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-64/0.15.13: + resolution: {integrity: sha512-rXmnArVNio6yANSqDQlIO4WiP+Cv7+9EuAHNnag7rByAqFVuRusLbGi2697A5dFPNXoO//IiogVwi3AdcfPC6A==} + engines: {node: '>=12'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-arm/0.15.13: + resolution: {integrity: sha512-Ac6LpfmJO8WhCMQmO253xX2IU2B3wPDbl4IvR0hnqcPrdfCaUa2j/lLMGTjmQ4W5JsJIdHEdW12dG8lFS0MbxQ==} + engines: {node: '>=12'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-arm64/0.15.13: + resolution: {integrity: sha512-alEMGU4Z+d17U7KQQw2IV8tQycO6T+rOrgW8OS22Ua25x6kHxoG6Ngry6Aq6uranC+pNWNMB6aHFPh7aTQdORQ==} + engines: {node: '>=12'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-mips64le/0.15.13: + resolution: {integrity: sha512-47PgmyYEu+yN5rD/MbwS6DxP2FSGPo4Uxg5LwIdxTiyGC2XKwHhHyW7YYEDlSuXLQXEdTO7mYe8zQ74czP7W8A==} + engines: {node: '>=12'} + cpu: [mips64el] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-ppc64le/0.15.13: + resolution: {integrity: sha512-z6n28h2+PC1Ayle9DjKoBRcx/4cxHoOa2e689e2aDJSaKug3jXcQw7mM+GLg+9ydYoNzj8QxNL8ihOv/OnezhA==} + engines: {node: '>=12'} + cpu: [ppc64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-riscv64/0.15.13: + resolution: {integrity: sha512-+Lu4zuuXuQhgLUGyZloWCqTslcCAjMZH1k3Xc9MSEJEpEFdpsSU0sRDXAnk18FKOfEjhu4YMGaykx9xjtpA6ow==} + engines: {node: '>=12'} + cpu: [riscv64] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-linux-s390x/0.15.13: + resolution: {integrity: sha512-BMeXRljruf7J0TMxD5CIXS65y7puiZkAh+s4XFV9qy16SxOuMhxhVIXYLnbdfLrsYGFzx7U9mcdpFWkkvy/Uag==} + engines: {node: '>=12'} + cpu: [s390x] + os: [linux] + requiresBuild: true + dev: true + optional: true + + /esbuild-netbsd-64/0.15.13: + resolution: {integrity: sha512-EHj9QZOTel581JPj7UO3xYbltFTYnHy+SIqJVq6yd3KkCrsHRbapiPb0Lx3EOOtybBEE9EyqbmfW1NlSDsSzvQ==} + engines: {node: '>=12'} + cpu: [x64] + os: [netbsd] + requiresBuild: true + dev: true + optional: true + + /esbuild-openbsd-64/0.15.13: + resolution: {integrity: sha512-nkuDlIjF/sfUhfx8SKq0+U+Fgx5K9JcPq1mUodnxI0x4kBdCv46rOGWbuJ6eof2n3wdoCLccOoJAbg9ba/bT2w==} + engines: {node: '>=12'} + cpu: [x64] + os: [openbsd] + requiresBuild: true + dev: true + optional: true + + /esbuild-sunos-64/0.15.13: + resolution: {integrity: sha512-jVeu2GfxZQ++6lRdY43CS0Tm/r4WuQQ0Pdsrxbw+aOrHQPHV0+LNOLnvbN28M7BSUGnJnHkHm2HozGgNGyeIRw==} + engines: {node: '>=12'} + cpu: [x64] + os: [sunos] + requiresBuild: true + dev: true + optional: true + + /esbuild-windows-32/0.15.13: + resolution: {integrity: sha512-XoF2iBf0wnqo16SDq+aDGi/+QbaLFpkiRarPVssMh9KYbFNCqPLlGAWwDvxEVz+ywX6Si37J2AKm+AXq1kC0JA==} + engines: {node: '>=12'} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /esbuild-windows-64/0.15.13: + resolution: {integrity: sha512-Et6htEfGycjDrtqb2ng6nT+baesZPYQIW+HUEHK4D1ncggNrDNk3yoboYQ5KtiVrw/JaDMNttz8rrPubV/fvPQ==} + engines: {node: '>=12'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /esbuild-windows-arm64/0.15.13: + resolution: {integrity: sha512-3bv7tqntThQC9SWLRouMDmZnlOukBhOCTlkzNqzGCmrkCJI7io5LLjwJBOVY6kOUlIvdxbooNZwjtBvj+7uuVg==} + engines: {node: '>=12'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: true + optional: true + + /esbuild/0.15.13: + resolution: {integrity: sha512-Cu3SC84oyzzhrK/YyN4iEVy2jZu5t2fz66HEOShHURcjSkOSAVL8C/gfUT+lDJxkVHpg8GZ10DD0rMHRPqMFaQ==} + engines: {node: '>=12'} + hasBin: true + requiresBuild: true + optionalDependencies: + '@esbuild/android-arm': 0.15.13 + '@esbuild/linux-loong64': 0.15.13 + esbuild-android-64: 0.15.13 + esbuild-android-arm64: 0.15.13 + esbuild-darwin-64: 0.15.13 + esbuild-darwin-arm64: 0.15.13 + esbuild-freebsd-64: 0.15.13 + esbuild-freebsd-arm64: 0.15.13 + esbuild-linux-32: 0.15.13 + esbuild-linux-64: 0.15.13 + esbuild-linux-arm: 0.15.13 + esbuild-linux-arm64: 0.15.13 + esbuild-linux-mips64le: 0.15.13 + esbuild-linux-ppc64le: 0.15.13 + esbuild-linux-riscv64: 0.15.13 + esbuild-linux-s390x: 0.15.13 + esbuild-netbsd-64: 0.15.13 + esbuild-openbsd-64: 0.15.13 + esbuild-sunos-64: 0.15.13 + esbuild-windows-32: 0.15.13 + esbuild-windows-64: 0.15.13 + esbuild-windows-arm64: 0.15.13 + dev: true diff --git a/dist/app.js b/src/app.js similarity index 100% rename from dist/app.js rename to src/app.js diff --git a/src/cli.js b/src/cli.js new file mode 100644 index 0000000..8829347 --- /dev/null +++ b/src/cli.js @@ -0,0 +1,55 @@ +// tauri/tooling/api/src/tauri.ts +function uid() { + return window.crypto.getRandomValues(new Uint32Array(1))[0]; +} +function transformCallback(callback, once = false) { + const identifier = uid(); + const prop = `_${identifier}`; + Object.defineProperty(window, prop, { + value: (result) => { + if (once) { + Reflect.deleteProperty(window, prop); + } + return callback?.(result); + }, + writable: false, + configurable: true + }); + return identifier; +} +async function invoke(cmd, args = {}) { + return new Promise((resolve, reject) => { + const callback = transformCallback((e) => { + resolve(e); + Reflect.deleteProperty(window, `_${error}`); + }, true); + const error = transformCallback((e) => { + reject(e); + Reflect.deleteProperty(window, `_${callback}`); + }, true); + window.__TAURI_IPC__({ + cmd, + callback, + error, + ...args + }); + }); +} + +// tauri/tooling/api/src/helpers/tauri.ts +async function invokeTauriCommand(command) { + return invoke("tauri", command); +} + +// tauri/tooling/api/src/cli.ts +async function getMatches() { + return invokeTauriCommand({ + __tauriModule: "Cli", + message: { + cmd: "cliMatches" + } + }); +} +export { + getMatches +}; diff --git a/dist/clipboard.js b/src/clipboard.js similarity index 100% rename from dist/clipboard.js rename to src/clipboard.js diff --git a/src/dialog.js b/src/dialog.js new file mode 100644 index 0000000..53811e1 --- /dev/null +++ b/src/dialog.js @@ -0,0 +1,111 @@ +// tauri/tooling/api/src/tauri.ts +function uid() { + return window.crypto.getRandomValues(new Uint32Array(1))[0]; +} +function transformCallback(callback, once = false) { + const identifier = uid(); + const prop = `_${identifier}`; + Object.defineProperty(window, prop, { + value: (result) => { + if (once) { + Reflect.deleteProperty(window, prop); + } + return callback?.(result); + }, + writable: false, + configurable: true + }); + return identifier; +} +async function invoke(cmd, args = {}) { + return new Promise((resolve, reject) => { + const callback = transformCallback((e) => { + resolve(e); + Reflect.deleteProperty(window, `_${error}`); + }, true); + const error = transformCallback((e) => { + reject(e); + Reflect.deleteProperty(window, `_${callback}`); + }, true); + window.__TAURI_IPC__({ + cmd, + callback, + error, + ...args + }); + }); +} + +// tauri/tooling/api/src/helpers/tauri.ts +async function invokeTauriCommand(command) { + return invoke("tauri", command); +} + +// tauri/tooling/api/src/dialog.ts +async function open(options = {}) { + if (typeof options === "object") { + Object.freeze(options); + } + return invokeTauriCommand({ + __tauriModule: "Dialog", + message: { + cmd: "openDialog", + options + } + }); +} +async function save(options = {}) { + if (typeof options === "object") { + Object.freeze(options); + } + return invokeTauriCommand({ + __tauriModule: "Dialog", + message: { + cmd: "saveDialog", + options + } + }); +} +async function message(message2, options) { + const opts = typeof options === "string" ? { title: options } : options; + return invokeTauriCommand({ + __tauriModule: "Dialog", + message: { + cmd: "messageDialog", + message: message2.toString(), + title: opts?.title?.toString(), + type: opts?.type + } + }); +} +async function ask(message2, options) { + const opts = typeof options === "string" ? { title: options } : options; + return invokeTauriCommand({ + __tauriModule: "Dialog", + message: { + cmd: "askDialog", + message: message2.toString(), + title: opts?.title?.toString(), + type: opts?.type + } + }); +} +async function confirm(message2, options) { + const opts = typeof options === "string" ? { title: options } : options; + return invokeTauriCommand({ + __tauriModule: "Dialog", + message: { + cmd: "confirmDialog", + message: message2.toString(), + title: opts?.title?.toString(), + type: opts?.type + } + }); +} +export { + ask, + confirm, + message, + open, + save +}; diff --git a/dist/event.js b/src/event.js similarity index 100% rename from dist/event.js rename to src/event.js diff --git a/src/fs.js b/src/fs.js new file mode 100644 index 0000000..8e223c3 --- /dev/null +++ b/src/fs.js @@ -0,0 +1,243 @@ +// tauri/tooling/api/src/tauri.ts +function uid() { + return window.crypto.getRandomValues(new Uint32Array(1))[0]; +} +function transformCallback(callback, once = false) { + const identifier = uid(); + const prop = `_${identifier}`; + Object.defineProperty(window, prop, { + value: (result) => { + if (once) { + Reflect.deleteProperty(window, prop); + } + return callback?.(result); + }, + writable: false, + configurable: true + }); + return identifier; +} +async function invoke(cmd, args = {}) { + return new Promise((resolve, reject) => { + const callback = transformCallback((e) => { + resolve(e); + Reflect.deleteProperty(window, `_${error}`); + }, true); + const error = transformCallback((e) => { + reject(e); + Reflect.deleteProperty(window, `_${callback}`); + }, true); + window.__TAURI_IPC__({ + cmd, + callback, + error, + ...args + }); + }); +} + +// tauri/tooling/api/src/helpers/tauri.ts +async function invokeTauriCommand(command) { + return invoke("tauri", command); +} + +// tauri/tooling/api/src/fs.ts +var BaseDirectory = /* @__PURE__ */ ((BaseDirectory2) => { + BaseDirectory2[BaseDirectory2["Audio"] = 1] = "Audio"; + BaseDirectory2[BaseDirectory2["Cache"] = 2] = "Cache"; + BaseDirectory2[BaseDirectory2["Config"] = 3] = "Config"; + BaseDirectory2[BaseDirectory2["Data"] = 4] = "Data"; + BaseDirectory2[BaseDirectory2["LocalData"] = 5] = "LocalData"; + BaseDirectory2[BaseDirectory2["Desktop"] = 6] = "Desktop"; + BaseDirectory2[BaseDirectory2["Document"] = 7] = "Document"; + BaseDirectory2[BaseDirectory2["Download"] = 8] = "Download"; + BaseDirectory2[BaseDirectory2["Executable"] = 9] = "Executable"; + BaseDirectory2[BaseDirectory2["Font"] = 10] = "Font"; + BaseDirectory2[BaseDirectory2["Home"] = 11] = "Home"; + BaseDirectory2[BaseDirectory2["Picture"] = 12] = "Picture"; + BaseDirectory2[BaseDirectory2["Public"] = 13] = "Public"; + BaseDirectory2[BaseDirectory2["Runtime"] = 14] = "Runtime"; + BaseDirectory2[BaseDirectory2["Template"] = 15] = "Template"; + BaseDirectory2[BaseDirectory2["Video"] = 16] = "Video"; + BaseDirectory2[BaseDirectory2["Resource"] = 17] = "Resource"; + BaseDirectory2[BaseDirectory2["App"] = 18] = "App"; + BaseDirectory2[BaseDirectory2["Log"] = 19] = "Log"; + BaseDirectory2[BaseDirectory2["Temp"] = 20] = "Temp"; + BaseDirectory2[BaseDirectory2["AppConfig"] = 21] = "AppConfig"; + BaseDirectory2[BaseDirectory2["AppData"] = 22] = "AppData"; + BaseDirectory2[BaseDirectory2["AppLocalData"] = 23] = "AppLocalData"; + BaseDirectory2[BaseDirectory2["AppCache"] = 24] = "AppCache"; + BaseDirectory2[BaseDirectory2["AppLog"] = 25] = "AppLog"; + return BaseDirectory2; +})(BaseDirectory || {}); +async function readTextFile(filePath, options = {}) { + return invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "readTextFile", + path: filePath, + options + } + }); +} +async function readBinaryFile(filePath, options = {}) { + const arr = await invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "readFile", + path: filePath, + options + } + }); + return Uint8Array.from(arr); +} +async function writeTextFile(path, contents, options) { + if (typeof options === "object") { + Object.freeze(options); + } + if (typeof path === "object") { + Object.freeze(path); + } + const file = { path: "", contents: "" }; + let fileOptions = options; + if (typeof path === "string") { + file.path = path; + } else { + file.path = path.path; + file.contents = path.contents; + } + if (typeof contents === "string") { + file.contents = contents ?? ""; + } else { + fileOptions = contents; + } + return invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "writeFile", + path: file.path, + contents: Array.from(new TextEncoder().encode(file.contents)), + options: fileOptions + } + }); +} +async function writeBinaryFile(path, contents, options) { + if (typeof options === "object") { + Object.freeze(options); + } + if (typeof path === "object") { + Object.freeze(path); + } + const file = { path: "", contents: [] }; + let fileOptions = options; + if (typeof path === "string") { + file.path = path; + } else { + file.path = path.path; + file.contents = path.contents; + } + if (contents && "dir" in contents) { + fileOptions = contents; + } else if (typeof path === "string") { + file.contents = contents ?? []; + } + return invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "writeFile", + path: file.path, + contents: Array.from( + file.contents instanceof ArrayBuffer ? new Uint8Array(file.contents) : file.contents + ), + options: fileOptions + } + }); +} +async function readDir(dir, options = {}) { + return invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "readDir", + path: dir, + options + } + }); +} +async function createDir(dir, options = {}) { + return invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "createDir", + path: dir, + options + } + }); +} +async function removeDir(dir, options = {}) { + return invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "removeDir", + path: dir, + options + } + }); +} +async function copyFile(source, destination, options = {}) { + return invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "copyFile", + source, + destination, + options + } + }); +} +async function removeFile(file, options = {}) { + return invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "removeFile", + path: file, + options + } + }); +} +async function renameFile(oldPath, newPath, options = {}) { + return invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "renameFile", + oldPath, + newPath, + options + } + }); +} +async function exists(path, options = {}) { + return invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "exists", + path, + options + } + }); +} +export { + BaseDirectory, + BaseDirectory as Dir, + copyFile, + createDir, + exists, + readBinaryFile, + readDir, + readTextFile, + removeDir, + removeFile, + renameFile, + writeBinaryFile, + writeTextFile as writeFile, + writeTextFile +}; diff --git a/src/globalShortcut.js b/src/globalShortcut.js new file mode 100644 index 0000000..0a6235f --- /dev/null +++ b/src/globalShortcut.js @@ -0,0 +1,97 @@ +// tauri/tooling/api/src/tauri.ts +function uid() { + return window.crypto.getRandomValues(new Uint32Array(1))[0]; +} +function transformCallback(callback, once = false) { + const identifier = uid(); + const prop = `_${identifier}`; + Object.defineProperty(window, prop, { + value: (result) => { + if (once) { + Reflect.deleteProperty(window, prop); + } + return callback?.(result); + }, + writable: false, + configurable: true + }); + return identifier; +} +async function invoke(cmd, args = {}) { + return new Promise((resolve, reject) => { + const callback = transformCallback((e) => { + resolve(e); + Reflect.deleteProperty(window, `_${error}`); + }, true); + const error = transformCallback((e) => { + reject(e); + Reflect.deleteProperty(window, `_${callback}`); + }, true); + window.__TAURI_IPC__({ + cmd, + callback, + error, + ...args + }); + }); +} + +// tauri/tooling/api/src/helpers/tauri.ts +async function invokeTauriCommand(command) { + return invoke("tauri", command); +} + +// tauri/tooling/api/src/globalShortcut.ts +async function register(shortcut, handler) { + return invokeTauriCommand({ + __tauriModule: "GlobalShortcut", + message: { + cmd: "register", + shortcut, + handler: transformCallback(handler) + } + }); +} +async function registerAll(shortcuts, handler) { + return invokeTauriCommand({ + __tauriModule: "GlobalShortcut", + message: { + cmd: "registerAll", + shortcuts, + handler: transformCallback(handler) + } + }); +} +async function isRegistered(shortcut) { + return invokeTauriCommand({ + __tauriModule: "GlobalShortcut", + message: { + cmd: "isRegistered", + shortcut + } + }); +} +async function unregister(shortcut) { + return invokeTauriCommand({ + __tauriModule: "GlobalShortcut", + message: { + cmd: "unregister", + shortcut + } + }); +} +async function unregisterAll() { + return invokeTauriCommand({ + __tauriModule: "GlobalShortcut", + message: { + cmd: "unregisterAll" + } + }); +} +export { + isRegistered, + register, + registerAll, + unregister, + unregisterAll +}; diff --git a/src/http.js b/src/http.js new file mode 100644 index 0000000..7147405 --- /dev/null +++ b/src/http.js @@ -0,0 +1,207 @@ +// tauri/tooling/api/src/tauri.ts +function uid() { + return window.crypto.getRandomValues(new Uint32Array(1))[0]; +} +function transformCallback(callback, once = false) { + const identifier = uid(); + const prop = `_${identifier}`; + Object.defineProperty(window, prop, { + value: (result) => { + if (once) { + Reflect.deleteProperty(window, prop); + } + return callback?.(result); + }, + writable: false, + configurable: true + }); + return identifier; +} +async function invoke(cmd, args = {}) { + return new Promise((resolve, reject) => { + const callback = transformCallback((e) => { + resolve(e); + Reflect.deleteProperty(window, `_${error}`); + }, true); + const error = transformCallback((e) => { + reject(e); + Reflect.deleteProperty(window, `_${callback}`); + }, true); + window.__TAURI_IPC__({ + cmd, + callback, + error, + ...args + }); + }); +} + +// tauri/tooling/api/src/helpers/tauri.ts +async function invokeTauriCommand(command) { + return invoke("tauri", command); +} + +// tauri/tooling/api/src/http.ts +var ResponseType = /* @__PURE__ */ ((ResponseType2) => { + ResponseType2[ResponseType2["JSON"] = 1] = "JSON"; + ResponseType2[ResponseType2["Text"] = 2] = "Text"; + ResponseType2[ResponseType2["Binary"] = 3] = "Binary"; + return ResponseType2; +})(ResponseType || {}); +var Body = class { + constructor(type, payload) { + this.type = type; + this.payload = payload; + } + static form(data) { + const form = {}; + for (const key in data) { + const v = data[key]; + let r; + if (typeof v === "string") { + r = v; + } else if (v instanceof Uint8Array || Array.isArray(v)) { + r = Array.from(v); + } else if (typeof v.file === "string") { + r = { file: v.file, mime: v.mime, fileName: v.fileName }; + } else { + r = { file: Array.from(v.file), mime: v.mime, fileName: v.fileName }; + } + form[key] = r; + } + return new Body("Form", form); + } + static json(data) { + return new Body("Json", data); + } + static text(value) { + return new Body("Text", value); + } + static bytes(bytes) { + return new Body( + "Bytes", + Array.from(bytes instanceof ArrayBuffer ? new Uint8Array(bytes) : bytes) + ); + } +}; +var Response = class { + constructor(response) { + this.url = response.url; + this.status = response.status; + this.ok = this.status >= 200 && this.status < 300; + this.headers = response.headers; + this.rawHeaders = response.rawHeaders; + this.data = response.data; + } +}; +var Client = class { + constructor(id) { + this.id = id; + } + async drop() { + return invokeTauriCommand({ + __tauriModule: "Http", + message: { + cmd: "dropClient", + client: this.id + } + }); + } + async request(options) { + const jsonResponse = !options.responseType || options.responseType === 1 /* JSON */; + if (jsonResponse) { + options.responseType = 2 /* Text */; + } + return invokeTauriCommand({ + __tauriModule: "Http", + message: { + cmd: "httpRequest", + client: this.id, + options + } + }).then((res) => { + const response = new Response(res); + if (jsonResponse) { + try { + response.data = JSON.parse(response.data); + } catch (e) { + if (response.ok && response.data === "") { + response.data = {}; + } else if (response.ok) { + throw Error( + `Failed to parse response \`${response.data}\` as JSON: ${e}; + try setting the \`responseType\` option to \`ResponseType.Text\` or \`ResponseType.Binary\` if the API does not return a JSON response.` + ); + } + } + return response; + } + return response; + }); + } + async get(url, options) { + return this.request({ + method: "GET", + url, + ...options + }); + } + async post(url, body, options) { + return this.request({ + method: "POST", + url, + body, + ...options + }); + } + async put(url, body, options) { + return this.request({ + method: "PUT", + url, + body, + ...options + }); + } + async patch(url, options) { + return this.request({ + method: "PATCH", + url, + ...options + }); + } + async delete(url, options) { + return this.request({ + method: "DELETE", + url, + ...options + }); + } +}; +async function getClient(options) { + return invokeTauriCommand({ + __tauriModule: "Http", + message: { + cmd: "createClient", + options + } + }).then((id) => new Client(id)); +} +var defaultClient = null; +async function fetch(url, options) { + if (defaultClient === null) { + defaultClient = await getClient(); + } + return defaultClient.request({ + url, + method: options?.method ?? "GET", + ...options + }); +} +export { + Body, + Client, + Response, + ResponseType, + fetch, + getClient +}; diff --git a/src/index.js b/src/index.js new file mode 100644 index 0000000..211e255 --- /dev/null +++ b/src/index.js @@ -0,0 +1,2402 @@ +var __defProp = Object.defineProperty; +var __export = (target, all) => { + for (var name in all) + __defProp(target, name, { get: all[name], enumerable: true }); +}; + +// tauri/tooling/api/src/app.ts +var app_exports = {}; +__export(app_exports, { + getName: () => getName, + getTauriVersion: () => getTauriVersion, + getVersion: () => getVersion, + hide: () => hide, + show: () => show +}); + +// tauri/tooling/api/src/tauri.ts +var tauri_exports = {}; +__export(tauri_exports, { + convertFileSrc: () => convertFileSrc, + invoke: () => invoke, + transformCallback: () => transformCallback +}); +function uid() { + return window.crypto.getRandomValues(new Uint32Array(1))[0]; +} +function transformCallback(callback, once3 = false) { + const identifier = uid(); + const prop = `_${identifier}`; + Object.defineProperty(window, prop, { + value: (result) => { + if (once3) { + Reflect.deleteProperty(window, prop); + } + return callback?.(result); + }, + writable: false, + configurable: true + }); + return identifier; +} +async function invoke(cmd, args = {}) { + return new Promise((resolve2, reject) => { + const callback = transformCallback((e) => { + resolve2(e); + Reflect.deleteProperty(window, `_${error}`); + }, true); + const error = transformCallback((e) => { + reject(e); + Reflect.deleteProperty(window, `_${callback}`); + }, true); + window.__TAURI_IPC__({ + cmd, + callback, + error, + ...args + }); + }); +} +function convertFileSrc(filePath, protocol = "asset") { + const path = encodeURIComponent(filePath); + return navigator.userAgent.includes("Windows") ? `https://${protocol}.localhost/${path}` : `${protocol}://localhost/${path}`; +} + +// tauri/tooling/api/src/helpers/tauri.ts +async function invokeTauriCommand(command) { + return invoke("tauri", command); +} + +// tauri/tooling/api/src/app.ts +async function getVersion() { + return invokeTauriCommand({ + __tauriModule: "App", + message: { + cmd: "getAppVersion" + } + }); +} +async function getName() { + return invokeTauriCommand({ + __tauriModule: "App", + message: { + cmd: "getAppName" + } + }); +} +async function getTauriVersion() { + return invokeTauriCommand({ + __tauriModule: "App", + message: { + cmd: "getTauriVersion" + } + }); +} +async function show() { + return invokeTauriCommand({ + __tauriModule: "App", + message: { + cmd: "show" + } + }); +} +async function hide() { + return invokeTauriCommand({ + __tauriModule: "App", + message: { + cmd: "hide" + } + }); +} + +// tauri/tooling/api/src/cli.ts +var cli_exports = {}; +__export(cli_exports, { + getMatches: () => getMatches +}); +async function getMatches() { + return invokeTauriCommand({ + __tauriModule: "Cli", + message: { + cmd: "cliMatches" + } + }); +} + +// tauri/tooling/api/src/clipboard.ts +var clipboard_exports = {}; +__export(clipboard_exports, { + readText: () => readText, + writeText: () => writeText +}); +async function writeText(text) { + return invokeTauriCommand({ + __tauriModule: "Clipboard", + message: { + cmd: "writeText", + data: text + } + }); +} +async function readText() { + return invokeTauriCommand({ + __tauriModule: "Clipboard", + message: { + cmd: "readText", + data: null + } + }); +} + +// tauri/tooling/api/src/dialog.ts +var dialog_exports = {}; +__export(dialog_exports, { + ask: () => ask, + confirm: () => confirm, + message: () => message, + open: () => open, + save: () => save +}); +async function open(options = {}) { + if (typeof options === "object") { + Object.freeze(options); + } + return invokeTauriCommand({ + __tauriModule: "Dialog", + message: { + cmd: "openDialog", + options + } + }); +} +async function save(options = {}) { + if (typeof options === "object") { + Object.freeze(options); + } + return invokeTauriCommand({ + __tauriModule: "Dialog", + message: { + cmd: "saveDialog", + options + } + }); +} +async function message(message2, options) { + const opts = typeof options === "string" ? { title: options } : options; + return invokeTauriCommand({ + __tauriModule: "Dialog", + message: { + cmd: "messageDialog", + message: message2.toString(), + title: opts?.title?.toString(), + type: opts?.type + } + }); +} +async function ask(message2, options) { + const opts = typeof options === "string" ? { title: options } : options; + return invokeTauriCommand({ + __tauriModule: "Dialog", + message: { + cmd: "askDialog", + message: message2.toString(), + title: opts?.title?.toString(), + type: opts?.type + } + }); +} +async function confirm(message2, options) { + const opts = typeof options === "string" ? { title: options } : options; + return invokeTauriCommand({ + __tauriModule: "Dialog", + message: { + cmd: "confirmDialog", + message: message2.toString(), + title: opts?.title?.toString(), + type: opts?.type + } + }); +} + +// tauri/tooling/api/src/event.ts +var event_exports = {}; +__export(event_exports, { + TauriEvent: () => TauriEvent, + emit: () => emit2, + listen: () => listen2, + once: () => once2 +}); + +// tauri/tooling/api/src/helpers/event.ts +async function _unlisten(event, eventId) { + return invokeTauriCommand({ + __tauriModule: "Event", + message: { + cmd: "unlisten", + event, + eventId + } + }); +} +async function emit(event, windowLabel, payload) { + await invokeTauriCommand({ + __tauriModule: "Event", + message: { + cmd: "emit", + event, + windowLabel, + payload + } + }); +} +async function listen(event, windowLabel, handler) { + return invokeTauriCommand({ + __tauriModule: "Event", + message: { + cmd: "listen", + event, + windowLabel, + handler: transformCallback(handler) + } + }).then((eventId) => { + return async () => _unlisten(event, eventId); + }); +} +async function once(event, windowLabel, handler) { + return listen(event, windowLabel, (eventData) => { + handler(eventData); + _unlisten(event, eventData.id).catch(() => { + }); + }); +} + +// tauri/tooling/api/src/event.ts +var TauriEvent = /* @__PURE__ */ ((TauriEvent2) => { + TauriEvent2["WINDOW_RESIZED"] = "tauri://resize"; + TauriEvent2["WINDOW_MOVED"] = "tauri://move"; + TauriEvent2["WINDOW_CLOSE_REQUESTED"] = "tauri://close-requested"; + TauriEvent2["WINDOW_CREATED"] = "tauri://window-created"; + TauriEvent2["WINDOW_DESTROYED"] = "tauri://destroyed"; + TauriEvent2["WINDOW_FOCUS"] = "tauri://focus"; + TauriEvent2["WINDOW_BLUR"] = "tauri://blur"; + TauriEvent2["WINDOW_SCALE_FACTOR_CHANGED"] = "tauri://scale-change"; + TauriEvent2["WINDOW_THEME_CHANGED"] = "tauri://theme-changed"; + TauriEvent2["WINDOW_FILE_DROP"] = "tauri://file-drop"; + TauriEvent2["WINDOW_FILE_DROP_HOVER"] = "tauri://file-drop-hover"; + TauriEvent2["WINDOW_FILE_DROP_CANCELLED"] = "tauri://file-drop-cancelled"; + TauriEvent2["MENU"] = "tauri://menu"; + TauriEvent2["CHECK_UPDATE"] = "tauri://update"; + TauriEvent2["UPDATE_AVAILABLE"] = "tauri://update-available"; + TauriEvent2["INSTALL_UPDATE"] = "tauri://update-install"; + TauriEvent2["STATUS_UPDATE"] = "tauri://update-status"; + TauriEvent2["DOWNLOAD_PROGRESS"] = "tauri://update-download-progress"; + return TauriEvent2; +})(TauriEvent || {}); +async function listen2(event, handler) { + return listen(event, null, handler); +} +async function once2(event, handler) { + return once(event, null, handler); +} +async function emit2(event, payload) { + return emit(event, void 0, payload); +} + +// tauri/tooling/api/src/fs.ts +var fs_exports = {}; +__export(fs_exports, { + BaseDirectory: () => BaseDirectory, + Dir: () => BaseDirectory, + copyFile: () => copyFile, + createDir: () => createDir, + exists: () => exists, + readBinaryFile: () => readBinaryFile, + readDir: () => readDir, + readTextFile: () => readTextFile, + removeDir: () => removeDir, + removeFile: () => removeFile, + renameFile: () => renameFile, + writeBinaryFile: () => writeBinaryFile, + writeFile: () => writeTextFile, + writeTextFile: () => writeTextFile +}); +var BaseDirectory = /* @__PURE__ */ ((BaseDirectory2) => { + BaseDirectory2[BaseDirectory2["Audio"] = 1] = "Audio"; + BaseDirectory2[BaseDirectory2["Cache"] = 2] = "Cache"; + BaseDirectory2[BaseDirectory2["Config"] = 3] = "Config"; + BaseDirectory2[BaseDirectory2["Data"] = 4] = "Data"; + BaseDirectory2[BaseDirectory2["LocalData"] = 5] = "LocalData"; + BaseDirectory2[BaseDirectory2["Desktop"] = 6] = "Desktop"; + BaseDirectory2[BaseDirectory2["Document"] = 7] = "Document"; + BaseDirectory2[BaseDirectory2["Download"] = 8] = "Download"; + BaseDirectory2[BaseDirectory2["Executable"] = 9] = "Executable"; + BaseDirectory2[BaseDirectory2["Font"] = 10] = "Font"; + BaseDirectory2[BaseDirectory2["Home"] = 11] = "Home"; + BaseDirectory2[BaseDirectory2["Picture"] = 12] = "Picture"; + BaseDirectory2[BaseDirectory2["Public"] = 13] = "Public"; + BaseDirectory2[BaseDirectory2["Runtime"] = 14] = "Runtime"; + BaseDirectory2[BaseDirectory2["Template"] = 15] = "Template"; + BaseDirectory2[BaseDirectory2["Video"] = 16] = "Video"; + BaseDirectory2[BaseDirectory2["Resource"] = 17] = "Resource"; + BaseDirectory2[BaseDirectory2["App"] = 18] = "App"; + BaseDirectory2[BaseDirectory2["Log"] = 19] = "Log"; + BaseDirectory2[BaseDirectory2["Temp"] = 20] = "Temp"; + BaseDirectory2[BaseDirectory2["AppConfig"] = 21] = "AppConfig"; + BaseDirectory2[BaseDirectory2["AppData"] = 22] = "AppData"; + BaseDirectory2[BaseDirectory2["AppLocalData"] = 23] = "AppLocalData"; + BaseDirectory2[BaseDirectory2["AppCache"] = 24] = "AppCache"; + BaseDirectory2[BaseDirectory2["AppLog"] = 25] = "AppLog"; + return BaseDirectory2; +})(BaseDirectory || {}); +async function readTextFile(filePath, options = {}) { + return invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "readTextFile", + path: filePath, + options + } + }); +} +async function readBinaryFile(filePath, options = {}) { + const arr = await invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "readFile", + path: filePath, + options + } + }); + return Uint8Array.from(arr); +} +async function writeTextFile(path, contents, options) { + if (typeof options === "object") { + Object.freeze(options); + } + if (typeof path === "object") { + Object.freeze(path); + } + const file = { path: "", contents: "" }; + let fileOptions = options; + if (typeof path === "string") { + file.path = path; + } else { + file.path = path.path; + file.contents = path.contents; + } + if (typeof contents === "string") { + file.contents = contents ?? ""; + } else { + fileOptions = contents; + } + return invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "writeFile", + path: file.path, + contents: Array.from(new TextEncoder().encode(file.contents)), + options: fileOptions + } + }); +} +async function writeBinaryFile(path, contents, options) { + if (typeof options === "object") { + Object.freeze(options); + } + if (typeof path === "object") { + Object.freeze(path); + } + const file = { path: "", contents: [] }; + let fileOptions = options; + if (typeof path === "string") { + file.path = path; + } else { + file.path = path.path; + file.contents = path.contents; + } + if (contents && "dir" in contents) { + fileOptions = contents; + } else if (typeof path === "string") { + file.contents = contents ?? []; + } + return invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "writeFile", + path: file.path, + contents: Array.from( + file.contents instanceof ArrayBuffer ? new Uint8Array(file.contents) : file.contents + ), + options: fileOptions + } + }); +} +async function readDir(dir, options = {}) { + return invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "readDir", + path: dir, + options + } + }); +} +async function createDir(dir, options = {}) { + return invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "createDir", + path: dir, + options + } + }); +} +async function removeDir(dir, options = {}) { + return invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "removeDir", + path: dir, + options + } + }); +} +async function copyFile(source, destination, options = {}) { + return invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "copyFile", + source, + destination, + options + } + }); +} +async function removeFile(file, options = {}) { + return invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "removeFile", + path: file, + options + } + }); +} +async function renameFile(oldPath, newPath, options = {}) { + return invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "renameFile", + oldPath, + newPath, + options + } + }); +} +async function exists(path, options = {}) { + return invokeTauriCommand({ + __tauriModule: "Fs", + message: { + cmd: "exists", + path, + options + } + }); +} + +// tauri/tooling/api/src/globalShortcut.ts +var globalShortcut_exports = {}; +__export(globalShortcut_exports, { + isRegistered: () => isRegistered, + register: () => register, + registerAll: () => registerAll, + unregister: () => unregister, + unregisterAll: () => unregisterAll +}); +async function register(shortcut, handler) { + return invokeTauriCommand({ + __tauriModule: "GlobalShortcut", + message: { + cmd: "register", + shortcut, + handler: transformCallback(handler) + } + }); +} +async function registerAll(shortcuts, handler) { + return invokeTauriCommand({ + __tauriModule: "GlobalShortcut", + message: { + cmd: "registerAll", + shortcuts, + handler: transformCallback(handler) + } + }); +} +async function isRegistered(shortcut) { + return invokeTauriCommand({ + __tauriModule: "GlobalShortcut", + message: { + cmd: "isRegistered", + shortcut + } + }); +} +async function unregister(shortcut) { + return invokeTauriCommand({ + __tauriModule: "GlobalShortcut", + message: { + cmd: "unregister", + shortcut + } + }); +} +async function unregisterAll() { + return invokeTauriCommand({ + __tauriModule: "GlobalShortcut", + message: { + cmd: "unregisterAll" + } + }); +} + +// tauri/tooling/api/src/http.ts +var http_exports = {}; +__export(http_exports, { + Body: () => Body, + Client: () => Client, + Response: () => Response, + ResponseType: () => ResponseType, + fetch: () => fetch, + getClient: () => getClient +}); +var ResponseType = /* @__PURE__ */ ((ResponseType2) => { + ResponseType2[ResponseType2["JSON"] = 1] = "JSON"; + ResponseType2[ResponseType2["Text"] = 2] = "Text"; + ResponseType2[ResponseType2["Binary"] = 3] = "Binary"; + return ResponseType2; +})(ResponseType || {}); +var Body = class { + constructor(type2, payload) { + this.type = type2; + this.payload = payload; + } + static form(data) { + const form = {}; + for (const key in data) { + const v = data[key]; + let r; + if (typeof v === "string") { + r = v; + } else if (v instanceof Uint8Array || Array.isArray(v)) { + r = Array.from(v); + } else if (typeof v.file === "string") { + r = { file: v.file, mime: v.mime, fileName: v.fileName }; + } else { + r = { file: Array.from(v.file), mime: v.mime, fileName: v.fileName }; + } + form[key] = r; + } + return new Body("Form", form); + } + static json(data) { + return new Body("Json", data); + } + static text(value) { + return new Body("Text", value); + } + static bytes(bytes) { + return new Body( + "Bytes", + Array.from(bytes instanceof ArrayBuffer ? new Uint8Array(bytes) : bytes) + ); + } +}; +var Response = class { + constructor(response) { + this.url = response.url; + this.status = response.status; + this.ok = this.status >= 200 && this.status < 300; + this.headers = response.headers; + this.rawHeaders = response.rawHeaders; + this.data = response.data; + } +}; +var Client = class { + constructor(id) { + this.id = id; + } + async drop() { + return invokeTauriCommand({ + __tauriModule: "Http", + message: { + cmd: "dropClient", + client: this.id + } + }); + } + async request(options) { + const jsonResponse = !options.responseType || options.responseType === 1 /* JSON */; + if (jsonResponse) { + options.responseType = 2 /* Text */; + } + return invokeTauriCommand({ + __tauriModule: "Http", + message: { + cmd: "httpRequest", + client: this.id, + options + } + }).then((res) => { + const response = new Response(res); + if (jsonResponse) { + try { + response.data = JSON.parse(response.data); + } catch (e) { + if (response.ok && response.data === "") { + response.data = {}; + } else if (response.ok) { + throw Error( + `Failed to parse response \`${response.data}\` as JSON: ${e}; + try setting the \`responseType\` option to \`ResponseType.Text\` or \`ResponseType.Binary\` if the API does not return a JSON response.` + ); + } + } + return response; + } + return response; + }); + } + async get(url, options) { + return this.request({ + method: "GET", + url, + ...options + }); + } + async post(url, body, options) { + return this.request({ + method: "POST", + url, + body, + ...options + }); + } + async put(url, body, options) { + return this.request({ + method: "PUT", + url, + body, + ...options + }); + } + async patch(url, options) { + return this.request({ + method: "PATCH", + url, + ...options + }); + } + async delete(url, options) { + return this.request({ + method: "DELETE", + url, + ...options + }); + } +}; +async function getClient(options) { + return invokeTauriCommand({ + __tauriModule: "Http", + message: { + cmd: "createClient", + options + } + }).then((id) => new Client(id)); +} +var defaultClient = null; +async function fetch(url, options) { + if (defaultClient === null) { + defaultClient = await getClient(); + } + return defaultClient.request({ + url, + method: options?.method ?? "GET", + ...options + }); +} + +// tauri/tooling/api/src/notification.ts +var notification_exports = {}; +__export(notification_exports, { + isPermissionGranted: () => isPermissionGranted, + requestPermission: () => requestPermission, + sendNotification: () => sendNotification +}); +async function isPermissionGranted() { + if (window.Notification.permission !== "default") { + return Promise.resolve(window.Notification.permission === "granted"); + } + return invokeTauriCommand({ + __tauriModule: "Notification", + message: { + cmd: "isNotificationPermissionGranted" + } + }); +} +async function requestPermission() { + return window.Notification.requestPermission(); +} +function sendNotification(options) { + if (typeof options === "string") { + new window.Notification(options); + } else { + new window.Notification(options.title, options); + } +} + +// tauri/tooling/api/src/path.ts +var path_exports = {}; +__export(path_exports, { + BaseDirectory: () => BaseDirectory, + appCacheDir: () => appCacheDir, + appConfigDir: () => appConfigDir, + appDataDir: () => appDataDir, + appDir: () => appDir, + appLocalDataDir: () => appLocalDataDir, + appLogDir: () => appLogDir, + audioDir: () => audioDir, + basename: () => basename, + cacheDir: () => cacheDir, + configDir: () => configDir, + dataDir: () => dataDir, + delimiter: () => delimiter, + desktopDir: () => desktopDir, + dirname: () => dirname, + documentDir: () => documentDir, + downloadDir: () => downloadDir, + executableDir: () => executableDir, + extname: () => extname, + fontDir: () => fontDir, + homeDir: () => homeDir, + isAbsolute: () => isAbsolute, + join: () => join, + localDataDir: () => localDataDir, + logDir: () => logDir, + normalize: () => normalize, + pictureDir: () => pictureDir, + publicDir: () => publicDir, + resolve: () => resolve, + resolveResource: () => resolveResource, + resourceDir: () => resourceDir, + runtimeDir: () => runtimeDir, + sep: () => sep, + templateDir: () => templateDir, + videoDir: () => videoDir +}); + +// tauri/tooling/api/src/helpers/os-check.ts +function isWindows() { + return navigator.appVersion.includes("Win"); +} + +// tauri/tooling/api/src/path.ts +async function appDir() { + return appConfigDir(); +} +async function appConfigDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 21 /* AppConfig */ + } + }); +} +async function appDataDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 22 /* AppData */ + } + }); +} +async function appLocalDataDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 23 /* AppLocalData */ + } + }); +} +async function appCacheDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 24 /* AppCache */ + } + }); +} +async function audioDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 1 /* Audio */ + } + }); +} +async function cacheDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 2 /* Cache */ + } + }); +} +async function configDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 3 /* Config */ + } + }); +} +async function dataDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 4 /* Data */ + } + }); +} +async function desktopDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 6 /* Desktop */ + } + }); +} +async function documentDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 7 /* Document */ + } + }); +} +async function downloadDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 8 /* Download */ + } + }); +} +async function executableDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 9 /* Executable */ + } + }); +} +async function fontDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 10 /* Font */ + } + }); +} +async function homeDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 11 /* Home */ + } + }); +} +async function localDataDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 5 /* LocalData */ + } + }); +} +async function pictureDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 12 /* Picture */ + } + }); +} +async function publicDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 13 /* Public */ + } + }); +} +async function resourceDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 17 /* Resource */ + } + }); +} +async function resolveResource(resourcePath) { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: resourcePath, + directory: 17 /* Resource */ + } + }); +} +async function runtimeDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 14 /* Runtime */ + } + }); +} +async function templateDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 15 /* Template */ + } + }); +} +async function videoDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 16 /* Video */ + } + }); +} +async function logDir() { + return appLogDir(); +} +async function appLogDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 25 /* AppLog */ + } + }); +} +var sep = isWindows() ? "\\" : "/"; +var delimiter = isWindows() ? ";" : ":"; +async function resolve(...paths) { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolve", + paths + } + }); +} +async function normalize(path) { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "normalize", + path + } + }); +} +async function join(...paths) { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "join", + paths + } + }); +} +async function dirname(path) { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "dirname", + path + } + }); +} +async function extname(path) { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "extname", + path + } + }); +} +async function basename(path, ext) { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "basename", + path, + ext + } + }); +} +async function isAbsolute(path) { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "isAbsolute", + path + } + }); +} + +// tauri/tooling/api/src/process.ts +var process_exports = {}; +__export(process_exports, { + exit: () => exit, + relaunch: () => relaunch +}); +async function exit(exitCode = 0) { + return invokeTauriCommand({ + __tauriModule: "Process", + message: { + cmd: "exit", + exitCode + } + }); +} +async function relaunch() { + return invokeTauriCommand({ + __tauriModule: "Process", + message: { + cmd: "relaunch" + } + }); +} + +// tauri/tooling/api/src/shell.ts +var shell_exports = {}; +__export(shell_exports, { + Child: () => Child, + Command: () => Command, + EventEmitter: () => EventEmitter, + open: () => open2 +}); +async function execute(onEvent, program, args = [], options) { + if (typeof args === "object") { + Object.freeze(args); + } + return invokeTauriCommand({ + __tauriModule: "Shell", + message: { + cmd: "execute", + program, + args, + options, + onEventFn: transformCallback(onEvent) + } + }); +} +var EventEmitter = class { + constructor() { + this.eventListeners = /* @__PURE__ */ Object.create(null); + } + addListener(eventName, listener) { + return this.on(eventName, listener); + } + removeListener(eventName, listener) { + return this.off(eventName, listener); + } + on(eventName, listener) { + if (eventName in this.eventListeners) { + this.eventListeners[eventName].push(listener); + } else { + this.eventListeners[eventName] = [listener]; + } + return this; + } + once(eventName, listener) { + const wrapper = (...args) => { + this.removeListener(eventName, wrapper); + listener(...args); + }; + return this.addListener(eventName, wrapper); + } + off(eventName, listener) { + if (eventName in this.eventListeners) { + this.eventListeners[eventName] = this.eventListeners[eventName].filter( + (l) => l !== listener + ); + } + return this; + } + removeAllListeners(event) { + if (event) { + delete this.eventListeners[event]; + } else { + this.eventListeners = /* @__PURE__ */ Object.create(null); + } + return this; + } + emit(eventName, ...args) { + if (eventName in this.eventListeners) { + const listeners = this.eventListeners[eventName]; + for (const listener of listeners) + listener(...args); + return true; + } + return false; + } + listenerCount(eventName) { + if (eventName in this.eventListeners) + return this.eventListeners[eventName].length; + return 0; + } + prependListener(eventName, listener) { + if (eventName in this.eventListeners) { + this.eventListeners[eventName].unshift(listener); + } else { + this.eventListeners[eventName] = [listener]; + } + return this; + } + prependOnceListener(eventName, listener) { + const wrapper = (...args) => { + this.removeListener(eventName, wrapper); + listener(...args); + }; + return this.prependListener(eventName, wrapper); + } +}; +var Child = class { + constructor(pid) { + this.pid = pid; + } + async write(data) { + return invokeTauriCommand({ + __tauriModule: "Shell", + message: { + cmd: "stdinWrite", + pid: this.pid, + buffer: typeof data === "string" ? data : Array.from(data) + } + }); + } + async kill() { + return invokeTauriCommand({ + __tauriModule: "Shell", + message: { + cmd: "killChild", + pid: this.pid + } + }); + } +}; +var Command = class extends EventEmitter { + constructor(program, args = [], options) { + super(); + this.stdout = new EventEmitter(); + this.stderr = new EventEmitter(); + this.program = program; + this.args = typeof args === "string" ? [args] : args; + this.options = options ?? {}; + } + static sidecar(program, args = [], options) { + const instance = new Command(program, args, options); + instance.options.sidecar = true; + return instance; + } + async spawn() { + return execute( + (event) => { + switch (event.event) { + case "Error": + this.emit("error", event.payload); + break; + case "Terminated": + this.emit("close", event.payload); + break; + case "Stdout": + this.stdout.emit("data", event.payload); + break; + case "Stderr": + this.stderr.emit("data", event.payload); + break; + } + }, + this.program, + this.args, + this.options + ).then((pid) => new Child(pid)); + } + async execute() { + return new Promise((resolve2, reject) => { + this.on("error", reject); + const stdout = []; + const stderr = []; + this.stdout.on("data", (line) => { + stdout.push(line); + }); + this.stderr.on("data", (line) => { + stderr.push(line); + }); + this.on("close", (payload) => { + resolve2({ + code: payload.code, + signal: payload.signal, + stdout: stdout.join("\n"), + stderr: stderr.join("\n") + }); + }); + this.spawn().catch(reject); + }); + } +}; +async function open2(path, openWith) { + return invokeTauriCommand({ + __tauriModule: "Shell", + message: { + cmd: "open", + path, + with: openWith + } + }); +} + +// tauri/tooling/api/src/updater.ts +var updater_exports = {}; +__export(updater_exports, { + checkUpdate: () => checkUpdate, + installUpdate: () => installUpdate, + onUpdaterEvent: () => onUpdaterEvent +}); +async function onUpdaterEvent(handler) { + return listen2("tauri://update-status" /* STATUS_UPDATE */, (data) => { + handler(data?.payload); + }); +} +async function installUpdate() { + let unlistenerFn; + function cleanListener() { + if (unlistenerFn) { + unlistenerFn(); + } + unlistenerFn = void 0; + } + return new Promise((resolve2, reject) => { + function onStatusChange(statusResult) { + if (statusResult.error) { + cleanListener(); + return reject(statusResult.error); + } + if (statusResult.status === "DONE") { + cleanListener(); + return resolve2(); + } + } + onUpdaterEvent(onStatusChange).then((fn) => { + unlistenerFn = fn; + }).catch((e) => { + cleanListener(); + throw e; + }); + emit2("tauri://update-install" /* INSTALL_UPDATE */).catch((e) => { + cleanListener(); + throw e; + }); + }); +} +async function checkUpdate() { + let unlistenerFn; + function cleanListener() { + if (unlistenerFn) { + unlistenerFn(); + } + unlistenerFn = void 0; + } + return new Promise((resolve2, reject) => { + function onUpdateAvailable(manifest) { + cleanListener(); + return resolve2({ + manifest, + shouldUpdate: true + }); + } + function onStatusChange(statusResult) { + if (statusResult.error) { + cleanListener(); + return reject(statusResult.error); + } + if (statusResult.status === "UPTODATE") { + cleanListener(); + return resolve2({ + shouldUpdate: false + }); + } + } + once2("tauri://update-available" /* UPDATE_AVAILABLE */, (data) => { + onUpdateAvailable(data?.payload); + }).catch((e) => { + cleanListener(); + throw e; + }); + onUpdaterEvent(onStatusChange).then((fn) => { + unlistenerFn = fn; + }).catch((e) => { + cleanListener(); + throw e; + }); + emit2("tauri://update" /* CHECK_UPDATE */).catch((e) => { + cleanListener(); + throw e; + }); + }); +} + +// tauri/tooling/api/src/window.ts +var window_exports = {}; +__export(window_exports, { + CloseRequestedEvent: () => CloseRequestedEvent, + LogicalPosition: () => LogicalPosition, + LogicalSize: () => LogicalSize, + PhysicalPosition: () => PhysicalPosition, + PhysicalSize: () => PhysicalSize, + UserAttentionType: () => UserAttentionType, + WebviewWindow: () => WebviewWindow, + WebviewWindowHandle: () => WebviewWindowHandle, + WindowManager: () => WindowManager, + appWindow: () => appWindow, + availableMonitors: () => availableMonitors, + currentMonitor: () => currentMonitor, + getAll: () => getAll, + getCurrent: () => getCurrent, + primaryMonitor: () => primaryMonitor +}); +var LogicalSize = class { + constructor(width, height) { + this.type = "Logical"; + this.width = width; + this.height = height; + } +}; +var PhysicalSize = class { + constructor(width, height) { + this.type = "Physical"; + this.width = width; + this.height = height; + } + toLogical(scaleFactor) { + return new LogicalSize(this.width / scaleFactor, this.height / scaleFactor); + } +}; +var LogicalPosition = class { + constructor(x, y) { + this.type = "Logical"; + this.x = x; + this.y = y; + } +}; +var PhysicalPosition = class { + constructor(x, y) { + this.type = "Physical"; + this.x = x; + this.y = y; + } + toLogical(scaleFactor) { + return new LogicalPosition(this.x / scaleFactor, this.y / scaleFactor); + } +}; +var UserAttentionType = /* @__PURE__ */ ((UserAttentionType2) => { + UserAttentionType2[UserAttentionType2["Critical"] = 1] = "Critical"; + UserAttentionType2[UserAttentionType2["Informational"] = 2] = "Informational"; + return UserAttentionType2; +})(UserAttentionType || {}); +function getCurrent() { + return new WebviewWindow(window.__TAURI_METADATA__.__currentWindow.label, { + skip: true + }); +} +function getAll() { + return window.__TAURI_METADATA__.__windows.map( + (w) => new WebviewWindow(w.label, { + skip: true + }) + ); +} +var localTauriEvents = ["tauri://created", "tauri://error"]; +var WebviewWindowHandle = class { + constructor(label) { + this.label = label; + this.listeners = /* @__PURE__ */ Object.create(null); + } + async listen(event, handler) { + if (this._handleTauriEvent(event, handler)) { + return Promise.resolve(() => { + const listeners = this.listeners[event]; + listeners.splice(listeners.indexOf(handler), 1); + }); + } + return listen(event, this.label, handler); + } + async once(event, handler) { + if (this._handleTauriEvent(event, handler)) { + return Promise.resolve(() => { + const listeners = this.listeners[event]; + listeners.splice(listeners.indexOf(handler), 1); + }); + } + return once(event, this.label, handler); + } + async emit(event, payload) { + if (localTauriEvents.includes(event)) { + for (const handler of this.listeners[event] || []) { + handler({ event, id: -1, windowLabel: this.label, payload }); + } + return Promise.resolve(); + } + return emit(event, this.label, payload); + } + _handleTauriEvent(event, handler) { + if (localTauriEvents.includes(event)) { + if (!(event in this.listeners)) { + this.listeners[event] = [handler]; + } else { + this.listeners[event].push(handler); + } + return true; + } + return false; + } +}; +var WindowManager = class extends WebviewWindowHandle { + async scaleFactor() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "scaleFactor" + } + } + } + }); + } + async innerPosition() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "innerPosition" + } + } + } + }).then(({ x, y }) => new PhysicalPosition(x, y)); + } + async outerPosition() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "outerPosition" + } + } + } + }).then(({ x, y }) => new PhysicalPosition(x, y)); + } + async innerSize() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "innerSize" + } + } + } + }).then(({ width, height }) => new PhysicalSize(width, height)); + } + async outerSize() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "outerSize" + } + } + } + }).then(({ width, height }) => new PhysicalSize(width, height)); + } + async isFullscreen() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "isFullscreen" + } + } + } + }); + } + async isMaximized() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "isMaximized" + } + } + } + }); + } + async isDecorated() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "isDecorated" + } + } + } + }); + } + async isResizable() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "isResizable" + } + } + } + }); + } + async isVisible() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "isVisible" + } + } + } + }); + } + async theme() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "theme" + } + } + } + }); + } + async center() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "center" + } + } + } + }); + } + async requestUserAttention(requestType) { + let requestType_ = null; + if (requestType) { + if (requestType === 1 /* Critical */) { + requestType_ = { type: "Critical" }; + } else { + requestType_ = { type: "Informational" }; + } + } + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "requestUserAttention", + payload: requestType_ + } + } + } + }); + } + async setResizable(resizable) { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "setResizable", + payload: resizable + } + } + } + }); + } + async setTitle(title) { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "setTitle", + payload: title + } + } + } + }); + } + async maximize() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "maximize" + } + } + } + }); + } + async unmaximize() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "unmaximize" + } + } + } + }); + } + async toggleMaximize() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "toggleMaximize" + } + } + } + }); + } + async minimize() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "minimize" + } + } + } + }); + } + async unminimize() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "unminimize" + } + } + } + }); + } + async show() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "show" + } + } + } + }); + } + async hide() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "hide" + } + } + } + }); + } + async close() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "close" + } + } + } + }); + } + async setDecorations(decorations) { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "setDecorations", + payload: decorations + } + } + } + }); + } + async setAlwaysOnTop(alwaysOnTop) { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "setAlwaysOnTop", + payload: alwaysOnTop + } + } + } + }); + } + async setSize(size) { + if (!size || size.type !== "Logical" && size.type !== "Physical") { + throw new Error( + "the `size` argument must be either a LogicalSize or a PhysicalSize instance" + ); + } + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "setSize", + payload: { + type: size.type, + data: { + width: size.width, + height: size.height + } + } + } + } + } + }); + } + async setMinSize(size) { + if (size && size.type !== "Logical" && size.type !== "Physical") { + throw new Error( + "the `size` argument must be either a LogicalSize or a PhysicalSize instance" + ); + } + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "setMinSize", + payload: size ? { + type: size.type, + data: { + width: size.width, + height: size.height + } + } : null + } + } + } + }); + } + async setMaxSize(size) { + if (size && size.type !== "Logical" && size.type !== "Physical") { + throw new Error( + "the `size` argument must be either a LogicalSize or a PhysicalSize instance" + ); + } + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "setMaxSize", + payload: size ? { + type: size.type, + data: { + width: size.width, + height: size.height + } + } : null + } + } + } + }); + } + async setPosition(position) { + if (!position || position.type !== "Logical" && position.type !== "Physical") { + throw new Error( + "the `position` argument must be either a LogicalPosition or a PhysicalPosition instance" + ); + } + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "setPosition", + payload: { + type: position.type, + data: { + x: position.x, + y: position.y + } + } + } + } + } + }); + } + async setFullscreen(fullscreen) { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "setFullscreen", + payload: fullscreen + } + } + } + }); + } + async setFocus() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "setFocus" + } + } + } + }); + } + async setIcon(icon) { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "setIcon", + payload: { + icon: typeof icon === "string" ? icon : Array.from(icon) + } + } + } + } + }); + } + async setSkipTaskbar(skip) { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "setSkipTaskbar", + payload: skip + } + } + } + }); + } + async setCursorGrab(grab) { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "setCursorGrab", + payload: grab + } + } + } + }); + } + async setCursorVisible(visible) { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "setCursorVisible", + payload: visible + } + } + } + }); + } + async setCursorIcon(icon) { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "setCursorIcon", + payload: icon + } + } + } + }); + } + async setCursorPosition(position) { + if (!position || position.type !== "Logical" && position.type !== "Physical") { + throw new Error( + "the `position` argument must be either a LogicalPosition or a PhysicalPosition instance" + ); + } + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "setCursorPosition", + payload: { + type: position.type, + data: { + x: position.x, + y: position.y + } + } + } + } + } + }); + } + async setIgnoreCursorEvents(ignore) { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "setIgnoreCursorEvents", + payload: ignore + } + } + } + }); + } + async startDragging() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + label: this.label, + cmd: { + type: "startDragging" + } + } + } + }); + } + async onResized(handler) { + return this.listen("tauri://resize" /* WINDOW_RESIZED */, handler); + } + async onMoved(handler) { + return this.listen("tauri://move" /* WINDOW_MOVED */, handler); + } + async onCloseRequested(handler) { + return this.listen("tauri://close-requested" /* WINDOW_CLOSE_REQUESTED */, (event) => { + const evt = new CloseRequestedEvent(event); + void Promise.resolve(handler(evt)).then(() => { + if (!evt.isPreventDefault()) { + return this.close(); + } + }); + }); + } + async onFocusChanged(handler) { + const unlistenFocus = await this.listen( + "tauri://focus" /* WINDOW_FOCUS */, + (event) => { + handler({ ...event, payload: true }); + } + ); + const unlistenBlur = await this.listen( + "tauri://blur" /* WINDOW_BLUR */, + (event) => { + handler({ ...event, payload: false }); + } + ); + return () => { + unlistenFocus(); + unlistenBlur(); + }; + } + async onScaleChanged(handler) { + return this.listen( + "tauri://scale-change" /* WINDOW_SCALE_FACTOR_CHANGED */, + handler + ); + } + async onMenuClicked(handler) { + return this.listen("tauri://menu" /* MENU */, handler); + } + async onFileDropEvent(handler) { + const unlistenFileDrop = await this.listen( + "tauri://file-drop" /* WINDOW_FILE_DROP */, + (event) => { + handler({ ...event, payload: { type: "drop", paths: event.payload } }); + } + ); + const unlistenFileHover = await this.listen( + "tauri://file-drop-hover" /* WINDOW_FILE_DROP_HOVER */, + (event) => { + handler({ ...event, payload: { type: "hover", paths: event.payload } }); + } + ); + const unlistenCancel = await this.listen( + "tauri://file-drop-cancelled" /* WINDOW_FILE_DROP_CANCELLED */, + (event) => { + handler({ ...event, payload: { type: "cancel" } }); + } + ); + return () => { + unlistenFileDrop(); + unlistenFileHover(); + unlistenCancel(); + }; + } + async onThemeChanged(handler) { + return this.listen("tauri://theme-changed" /* WINDOW_THEME_CHANGED */, handler); + } +}; +var CloseRequestedEvent = class { + constructor(event) { + this._preventDefault = false; + this.event = event.event; + this.windowLabel = event.windowLabel; + this.id = event.id; + } + preventDefault() { + this._preventDefault = true; + } + isPreventDefault() { + return this._preventDefault; + } +}; +var WebviewWindow = class extends WindowManager { + constructor(label, options = {}) { + super(label); + if (!options?.skip) { + invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "createWebview", + data: { + options: { + label, + ...options + } + } + } + }).then(async () => this.emit("tauri://created")).catch(async (e) => this.emit("tauri://error", e)); + } + } + static getByLabel(label) { + if (getAll().some((w) => w.label === label)) { + return new WebviewWindow(label, { skip: true }); + } + return null; + } +}; +var appWindow; +if ("__TAURI_METADATA__" in window) { + appWindow = new WebviewWindow( + window.__TAURI_METADATA__.__currentWindow.label, + { + skip: true + } + ); +} else { + console.warn( + `Could not find "window.__TAURI_METADATA__". The "appWindow" value will reference the "main" window label. +Note that this is not an issue if running this frontend on a browser instead of a Tauri window.` + ); + appWindow = new WebviewWindow("main", { + skip: true + }); +} +function mapMonitor(m) { + return m === null ? null : { + name: m.name, + scaleFactor: m.scaleFactor, + position: new PhysicalPosition(m.position.x, m.position.y), + size: new PhysicalSize(m.size.width, m.size.height) + }; +} +async function currentMonitor() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + cmd: { + type: "currentMonitor" + } + } + } + }).then(mapMonitor); +} +async function primaryMonitor() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + cmd: { + type: "primaryMonitor" + } + } + } + }).then(mapMonitor); +} +async function availableMonitors() { + return invokeTauriCommand({ + __tauriModule: "Window", + message: { + cmd: "manage", + data: { + cmd: { + type: "availableMonitors" + } + } + } + }).then((ms) => ms.map(mapMonitor)); +} + +// tauri/tooling/api/src/os.ts +var os_exports = {}; +__export(os_exports, { + EOL: () => EOL, + arch: () => arch, + platform: () => platform, + tempdir: () => tempdir, + type: () => type, + version: () => version +}); +var EOL = isWindows() ? "\r\n" : "\n"; +async function platform() { + return invokeTauriCommand({ + __tauriModule: "Os", + message: { + cmd: "platform" + } + }); +} +async function version() { + return invokeTauriCommand({ + __tauriModule: "Os", + message: { + cmd: "version" + } + }); +} +async function type() { + return invokeTauriCommand({ + __tauriModule: "Os", + message: { + cmd: "osType" + } + }); +} +async function arch() { + return invokeTauriCommand({ + __tauriModule: "Os", + message: { + cmd: "arch" + } + }); +} +async function tempdir() { + return invokeTauriCommand({ + __tauriModule: "Os", + message: { + cmd: "tempdir" + } + }); +} + +// tauri/tooling/api/src/index.ts +var invoke2 = invoke; +export { + app_exports as app, + cli_exports as cli, + clipboard_exports as clipboard, + dialog_exports as dialog, + event_exports as event, + fs_exports as fs, + globalShortcut_exports as globalShortcut, + http_exports as http, + invoke2 as invoke, + notification_exports as notification, + os_exports as os, + path_exports as path, + process_exports as process, + shell_exports as shell, + tauri_exports as tauri, + updater_exports as updater, + window_exports as window +}; diff --git a/dist/mocks.js b/src/mocks.js similarity index 100% rename from dist/mocks.js rename to src/mocks.js diff --git a/src/notification.js b/src/notification.js new file mode 100644 index 0000000..4ec6b9b --- /dev/null +++ b/src/notification.js @@ -0,0 +1,70 @@ +// tauri/tooling/api/src/tauri.ts +function uid() { + return window.crypto.getRandomValues(new Uint32Array(1))[0]; +} +function transformCallback(callback, once = false) { + const identifier = uid(); + const prop = `_${identifier}`; + Object.defineProperty(window, prop, { + value: (result) => { + if (once) { + Reflect.deleteProperty(window, prop); + } + return callback?.(result); + }, + writable: false, + configurable: true + }); + return identifier; +} +async function invoke(cmd, args = {}) { + return new Promise((resolve, reject) => { + const callback = transformCallback((e) => { + resolve(e); + Reflect.deleteProperty(window, `_${error}`); + }, true); + const error = transformCallback((e) => { + reject(e); + Reflect.deleteProperty(window, `_${callback}`); + }, true); + window.__TAURI_IPC__({ + cmd, + callback, + error, + ...args + }); + }); +} + +// tauri/tooling/api/src/helpers/tauri.ts +async function invokeTauriCommand(command) { + return invoke("tauri", command); +} + +// tauri/tooling/api/src/notification.ts +async function isPermissionGranted() { + if (window.Notification.permission !== "default") { + return Promise.resolve(window.Notification.permission === "granted"); + } + return invokeTauriCommand({ + __tauriModule: "Notification", + message: { + cmd: "isNotificationPermissionGranted" + } + }); +} +async function requestPermission() { + return window.Notification.requestPermission(); +} +function sendNotification(options) { + if (typeof options === "string") { + new window.Notification(options); + } else { + new window.Notification(options.title, options); + } +} +export { + isPermissionGranted, + requestPermission, + sendNotification +}; diff --git a/src/os.js b/src/os.js new file mode 100644 index 0000000..76dd323 --- /dev/null +++ b/src/os.js @@ -0,0 +1,98 @@ +// tauri/tooling/api/src/helpers/os-check.ts +function isWindows() { + return navigator.appVersion.includes("Win"); +} + +// tauri/tooling/api/src/tauri.ts +function uid() { + return window.crypto.getRandomValues(new Uint32Array(1))[0]; +} +function transformCallback(callback, once = false) { + const identifier = uid(); + const prop = `_${identifier}`; + Object.defineProperty(window, prop, { + value: (result) => { + if (once) { + Reflect.deleteProperty(window, prop); + } + return callback?.(result); + }, + writable: false, + configurable: true + }); + return identifier; +} +async function invoke(cmd, args = {}) { + return new Promise((resolve, reject) => { + const callback = transformCallback((e) => { + resolve(e); + Reflect.deleteProperty(window, `_${error}`); + }, true); + const error = transformCallback((e) => { + reject(e); + Reflect.deleteProperty(window, `_${callback}`); + }, true); + window.__TAURI_IPC__({ + cmd, + callback, + error, + ...args + }); + }); +} + +// tauri/tooling/api/src/helpers/tauri.ts +async function invokeTauriCommand(command) { + return invoke("tauri", command); +} + +// tauri/tooling/api/src/os.ts +var EOL = isWindows() ? "\r\n" : "\n"; +async function platform() { + return invokeTauriCommand({ + __tauriModule: "Os", + message: { + cmd: "platform" + } + }); +} +async function version() { + return invokeTauriCommand({ + __tauriModule: "Os", + message: { + cmd: "version" + } + }); +} +async function type() { + return invokeTauriCommand({ + __tauriModule: "Os", + message: { + cmd: "osType" + } + }); +} +async function arch() { + return invokeTauriCommand({ + __tauriModule: "Os", + message: { + cmd: "arch" + } + }); +} +async function tempdir() { + return invokeTauriCommand({ + __tauriModule: "Os", + message: { + cmd: "tempdir" + } + }); +} +export { + EOL, + arch, + platform, + tempdir, + type, + version +}; diff --git a/src/path.js b/src/path.js new file mode 100644 index 0000000..1250562 --- /dev/null +++ b/src/path.js @@ -0,0 +1,418 @@ +// tauri/tooling/api/src/tauri.ts +function uid() { + return window.crypto.getRandomValues(new Uint32Array(1))[0]; +} +function transformCallback(callback, once = false) { + const identifier = uid(); + const prop = `_${identifier}`; + Object.defineProperty(window, prop, { + value: (result) => { + if (once) { + Reflect.deleteProperty(window, prop); + } + return callback?.(result); + }, + writable: false, + configurable: true + }); + return identifier; +} +async function invoke(cmd, args = {}) { + return new Promise((resolve2, reject) => { + const callback = transformCallback((e) => { + resolve2(e); + Reflect.deleteProperty(window, `_${error}`); + }, true); + const error = transformCallback((e) => { + reject(e); + Reflect.deleteProperty(window, `_${callback}`); + }, true); + window.__TAURI_IPC__({ + cmd, + callback, + error, + ...args + }); + }); +} + +// tauri/tooling/api/src/helpers/tauri.ts +async function invokeTauriCommand(command) { + return invoke("tauri", command); +} + +// tauri/tooling/api/src/fs.ts +var BaseDirectory = /* @__PURE__ */ ((BaseDirectory2) => { + BaseDirectory2[BaseDirectory2["Audio"] = 1] = "Audio"; + BaseDirectory2[BaseDirectory2["Cache"] = 2] = "Cache"; + BaseDirectory2[BaseDirectory2["Config"] = 3] = "Config"; + BaseDirectory2[BaseDirectory2["Data"] = 4] = "Data"; + BaseDirectory2[BaseDirectory2["LocalData"] = 5] = "LocalData"; + BaseDirectory2[BaseDirectory2["Desktop"] = 6] = "Desktop"; + BaseDirectory2[BaseDirectory2["Document"] = 7] = "Document"; + BaseDirectory2[BaseDirectory2["Download"] = 8] = "Download"; + BaseDirectory2[BaseDirectory2["Executable"] = 9] = "Executable"; + BaseDirectory2[BaseDirectory2["Font"] = 10] = "Font"; + BaseDirectory2[BaseDirectory2["Home"] = 11] = "Home"; + BaseDirectory2[BaseDirectory2["Picture"] = 12] = "Picture"; + BaseDirectory2[BaseDirectory2["Public"] = 13] = "Public"; + BaseDirectory2[BaseDirectory2["Runtime"] = 14] = "Runtime"; + BaseDirectory2[BaseDirectory2["Template"] = 15] = "Template"; + BaseDirectory2[BaseDirectory2["Video"] = 16] = "Video"; + BaseDirectory2[BaseDirectory2["Resource"] = 17] = "Resource"; + BaseDirectory2[BaseDirectory2["App"] = 18] = "App"; + BaseDirectory2[BaseDirectory2["Log"] = 19] = "Log"; + BaseDirectory2[BaseDirectory2["Temp"] = 20] = "Temp"; + BaseDirectory2[BaseDirectory2["AppConfig"] = 21] = "AppConfig"; + BaseDirectory2[BaseDirectory2["AppData"] = 22] = "AppData"; + BaseDirectory2[BaseDirectory2["AppLocalData"] = 23] = "AppLocalData"; + BaseDirectory2[BaseDirectory2["AppCache"] = 24] = "AppCache"; + BaseDirectory2[BaseDirectory2["AppLog"] = 25] = "AppLog"; + return BaseDirectory2; +})(BaseDirectory || {}); + +// tauri/tooling/api/src/helpers/os-check.ts +function isWindows() { + return navigator.appVersion.includes("Win"); +} + +// tauri/tooling/api/src/path.ts +async function appDir() { + return appConfigDir(); +} +async function appConfigDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 21 /* AppConfig */ + } + }); +} +async function appDataDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 22 /* AppData */ + } + }); +} +async function appLocalDataDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 23 /* AppLocalData */ + } + }); +} +async function appCacheDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 24 /* AppCache */ + } + }); +} +async function audioDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 1 /* Audio */ + } + }); +} +async function cacheDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 2 /* Cache */ + } + }); +} +async function configDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 3 /* Config */ + } + }); +} +async function dataDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 4 /* Data */ + } + }); +} +async function desktopDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 6 /* Desktop */ + } + }); +} +async function documentDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 7 /* Document */ + } + }); +} +async function downloadDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 8 /* Download */ + } + }); +} +async function executableDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 9 /* Executable */ + } + }); +} +async function fontDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 10 /* Font */ + } + }); +} +async function homeDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 11 /* Home */ + } + }); +} +async function localDataDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 5 /* LocalData */ + } + }); +} +async function pictureDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 12 /* Picture */ + } + }); +} +async function publicDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 13 /* Public */ + } + }); +} +async function resourceDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 17 /* Resource */ + } + }); +} +async function resolveResource(resourcePath) { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: resourcePath, + directory: 17 /* Resource */ + } + }); +} +async function runtimeDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 14 /* Runtime */ + } + }); +} +async function templateDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 15 /* Template */ + } + }); +} +async function videoDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 16 /* Video */ + } + }); +} +async function logDir() { + return appLogDir(); +} +async function appLogDir() { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolvePath", + path: "", + directory: 25 /* AppLog */ + } + }); +} +var sep = isWindows() ? "\\" : "/"; +var delimiter = isWindows() ? ";" : ":"; +async function resolve(...paths) { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "resolve", + paths + } + }); +} +async function normalize(path) { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "normalize", + path + } + }); +} +async function join(...paths) { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "join", + paths + } + }); +} +async function dirname(path) { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "dirname", + path + } + }); +} +async function extname(path) { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "extname", + path + } + }); +} +async function basename(path, ext) { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "basename", + path, + ext + } + }); +} +async function isAbsolute(path) { + return invokeTauriCommand({ + __tauriModule: "Path", + message: { + cmd: "isAbsolute", + path + } + }); +} +export { + BaseDirectory, + appCacheDir, + appConfigDir, + appDataDir, + appDir, + appLocalDataDir, + appLogDir, + audioDir, + basename, + cacheDir, + configDir, + dataDir, + delimiter, + desktopDir, + dirname, + documentDir, + downloadDir, + executableDir, + extname, + fontDir, + homeDir, + isAbsolute, + join, + localDataDir, + logDir, + normalize, + pictureDir, + publicDir, + resolve, + resolveResource, + resourceDir, + runtimeDir, + sep, + templateDir, + videoDir +}; diff --git a/dist/process.js b/src/process.js similarity index 100% rename from dist/process.js rename to src/process.js diff --git a/src/shell.js b/src/shell.js new file mode 100644 index 0000000..006bca0 --- /dev/null +++ b/src/shell.js @@ -0,0 +1,230 @@ +// tauri/tooling/api/src/tauri.ts +function uid() { + return window.crypto.getRandomValues(new Uint32Array(1))[0]; +} +function transformCallback(callback, once = false) { + const identifier = uid(); + const prop = `_${identifier}`; + Object.defineProperty(window, prop, { + value: (result) => { + if (once) { + Reflect.deleteProperty(window, prop); + } + return callback?.(result); + }, + writable: false, + configurable: true + }); + return identifier; +} +async function invoke(cmd, args = {}) { + return new Promise((resolve, reject) => { + const callback = transformCallback((e) => { + resolve(e); + Reflect.deleteProperty(window, `_${error}`); + }, true); + const error = transformCallback((e) => { + reject(e); + Reflect.deleteProperty(window, `_${callback}`); + }, true); + window.__TAURI_IPC__({ + cmd, + callback, + error, + ...args + }); + }); +} + +// tauri/tooling/api/src/helpers/tauri.ts +async function invokeTauriCommand(command) { + return invoke("tauri", command); +} + +// tauri/tooling/api/src/shell.ts +async function execute(onEvent, program, args = [], options) { + if (typeof args === "object") { + Object.freeze(args); + } + return invokeTauriCommand({ + __tauriModule: "Shell", + message: { + cmd: "execute", + program, + args, + options, + onEventFn: transformCallback(onEvent) + } + }); +} +var EventEmitter = class { + constructor() { + this.eventListeners = /* @__PURE__ */ Object.create(null); + } + addListener(eventName, listener) { + return this.on(eventName, listener); + } + removeListener(eventName, listener) { + return this.off(eventName, listener); + } + on(eventName, listener) { + if (eventName in this.eventListeners) { + this.eventListeners[eventName].push(listener); + } else { + this.eventListeners[eventName] = [listener]; + } + return this; + } + once(eventName, listener) { + const wrapper = (...args) => { + this.removeListener(eventName, wrapper); + listener(...args); + }; + return this.addListener(eventName, wrapper); + } + off(eventName, listener) { + if (eventName in this.eventListeners) { + this.eventListeners[eventName] = this.eventListeners[eventName].filter( + (l) => l !== listener + ); + } + return this; + } + removeAllListeners(event) { + if (event) { + delete this.eventListeners[event]; + } else { + this.eventListeners = /* @__PURE__ */ Object.create(null); + } + return this; + } + emit(eventName, ...args) { + if (eventName in this.eventListeners) { + const listeners = this.eventListeners[eventName]; + for (const listener of listeners) + listener(...args); + return true; + } + return false; + } + listenerCount(eventName) { + if (eventName in this.eventListeners) + return this.eventListeners[eventName].length; + return 0; + } + prependListener(eventName, listener) { + if (eventName in this.eventListeners) { + this.eventListeners[eventName].unshift(listener); + } else { + this.eventListeners[eventName] = [listener]; + } + return this; + } + prependOnceListener(eventName, listener) { + const wrapper = (...args) => { + this.removeListener(eventName, wrapper); + listener(...args); + }; + return this.prependListener(eventName, wrapper); + } +}; +var Child = class { + constructor(pid) { + this.pid = pid; + } + async write(data) { + return invokeTauriCommand({ + __tauriModule: "Shell", + message: { + cmd: "stdinWrite", + pid: this.pid, + buffer: typeof data === "string" ? data : Array.from(data) + } + }); + } + async kill() { + return invokeTauriCommand({ + __tauriModule: "Shell", + message: { + cmd: "killChild", + pid: this.pid + } + }); + } +}; +var Command = class extends EventEmitter { + constructor(program, args = [], options) { + super(); + this.stdout = new EventEmitter(); + this.stderr = new EventEmitter(); + this.program = program; + this.args = typeof args === "string" ? [args] : args; + this.options = options ?? {}; + } + static sidecar(program, args = [], options) { + const instance = new Command(program, args, options); + instance.options.sidecar = true; + return instance; + } + async spawn() { + return execute( + (event) => { + switch (event.event) { + case "Error": + this.emit("error", event.payload); + break; + case "Terminated": + this.emit("close", event.payload); + break; + case "Stdout": + this.stdout.emit("data", event.payload); + break; + case "Stderr": + this.stderr.emit("data", event.payload); + break; + } + }, + this.program, + this.args, + this.options + ).then((pid) => new Child(pid)); + } + async execute() { + return new Promise((resolve, reject) => { + this.on("error", reject); + const stdout = []; + const stderr = []; + this.stdout.on("data", (line) => { + stdout.push(line); + }); + this.stderr.on("data", (line) => { + stderr.push(line); + }); + this.on("close", (payload) => { + resolve({ + code: payload.code, + signal: payload.signal, + stdout: stdout.join("\n"), + stderr: stderr.join("\n") + }); + }); + this.spawn().catch(reject); + }); + } +}; +async function open(path, openWith) { + return invokeTauriCommand({ + __tauriModule: "Shell", + message: { + cmd: "open", + path, + with: openWith + } + }); +} +export { + Child, + Command, + EventEmitter, + open +}; diff --git a/dist/tauri.js b/src/tauri.js similarity index 100% rename from dist/tauri.js rename to src/tauri.js diff --git a/src/updater.js b/src/updater.js new file mode 100644 index 0000000..43fb58a --- /dev/null +++ b/src/updater.js @@ -0,0 +1,185 @@ +// tauri/tooling/api/src/tauri.ts +function uid() { + return window.crypto.getRandomValues(new Uint32Array(1))[0]; +} +function transformCallback(callback, once3 = false) { + const identifier = uid(); + const prop = `_${identifier}`; + Object.defineProperty(window, prop, { + value: (result) => { + if (once3) { + Reflect.deleteProperty(window, prop); + } + return callback?.(result); + }, + writable: false, + configurable: true + }); + return identifier; +} +async function invoke(cmd, args = {}) { + return new Promise((resolve, reject) => { + const callback = transformCallback((e) => { + resolve(e); + Reflect.deleteProperty(window, `_${error}`); + }, true); + const error = transformCallback((e) => { + reject(e); + Reflect.deleteProperty(window, `_${callback}`); + }, true); + window.__TAURI_IPC__({ + cmd, + callback, + error, + ...args + }); + }); +} + +// tauri/tooling/api/src/helpers/tauri.ts +async function invokeTauriCommand(command) { + return invoke("tauri", command); +} + +// tauri/tooling/api/src/helpers/event.ts +async function _unlisten(event, eventId) { + return invokeTauriCommand({ + __tauriModule: "Event", + message: { + cmd: "unlisten", + event, + eventId + } + }); +} +async function emit(event, windowLabel, payload) { + await invokeTauriCommand({ + __tauriModule: "Event", + message: { + cmd: "emit", + event, + windowLabel, + payload + } + }); +} +async function listen(event, windowLabel, handler) { + return invokeTauriCommand({ + __tauriModule: "Event", + message: { + cmd: "listen", + event, + windowLabel, + handler: transformCallback(handler) + } + }).then((eventId) => { + return async () => _unlisten(event, eventId); + }); +} +async function once(event, windowLabel, handler) { + return listen(event, windowLabel, (eventData) => { + handler(eventData); + _unlisten(event, eventData.id).catch(() => { + }); + }); +} + +// tauri/tooling/api/src/event.ts +async function listen2(event, handler) { + return listen(event, null, handler); +} +async function once2(event, handler) { + return once(event, null, handler); +} +async function emit2(event, payload) { + return emit(event, void 0, payload); +} + +// tauri/tooling/api/src/updater.ts +async function onUpdaterEvent(handler) { + return listen2("tauri://update-status" /* STATUS_UPDATE */, (data) => { + handler(data?.payload); + }); +} +async function installUpdate() { + let unlistenerFn; + function cleanListener() { + if (unlistenerFn) { + unlistenerFn(); + } + unlistenerFn = void 0; + } + return new Promise((resolve, reject) => { + function onStatusChange(statusResult) { + if (statusResult.error) { + cleanListener(); + return reject(statusResult.error); + } + if (statusResult.status === "DONE") { + cleanListener(); + return resolve(); + } + } + onUpdaterEvent(onStatusChange).then((fn) => { + unlistenerFn = fn; + }).catch((e) => { + cleanListener(); + throw e; + }); + emit2("tauri://update-install" /* INSTALL_UPDATE */).catch((e) => { + cleanListener(); + throw e; + }); + }); +} +async function checkUpdate() { + let unlistenerFn; + function cleanListener() { + if (unlistenerFn) { + unlistenerFn(); + } + unlistenerFn = void 0; + } + return new Promise((resolve, reject) => { + function onUpdateAvailable(manifest) { + cleanListener(); + return resolve({ + manifest, + shouldUpdate: true + }); + } + function onStatusChange(statusResult) { + if (statusResult.error) { + cleanListener(); + return reject(statusResult.error); + } + if (statusResult.status === "UPTODATE") { + cleanListener(); + return resolve({ + shouldUpdate: false + }); + } + } + once2("tauri://update-available" /* UPDATE_AVAILABLE */, (data) => { + onUpdateAvailable(data?.payload); + }).catch((e) => { + cleanListener(); + throw e; + }); + onUpdaterEvent(onStatusChange).then((fn) => { + unlistenerFn = fn; + }).catch((e) => { + cleanListener(); + throw e; + }); + emit2("tauri://update" /* CHECK_UPDATE */).catch((e) => { + cleanListener(); + throw e; + }); + }); +} +export { + checkUpdate, + installUpdate, + onUpdaterEvent +}; diff --git a/dist/window.js b/src/window.js similarity index 100% rename from dist/window.js rename to src/window.js