remove build script
This commit is contained in:
parent
20442c1f43
commit
c9fa93de72
21 changed files with 4368 additions and 33 deletions
91
src/app.js
Normal file
91
src/app.js
Normal file
|
@ -0,0 +1,91 @@
|
|||
// 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/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"
|
||||
}
|
||||
});
|
||||
}
|
||||
export {
|
||||
getName,
|
||||
getTauriVersion,
|
||||
getVersion,
|
||||
hide,
|
||||
show
|
||||
};
|
55
src/cli.js
Normal file
55
src/cli.js
Normal file
|
@ -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
|
||||
};
|
66
src/clipboard.js
Normal file
66
src/clipboard.js
Normal file
|
@ -0,0 +1,66 @@
|
|||
// 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/clipboard.ts
|
||||
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
|
||||
}
|
||||
});
|
||||
}
|
||||
export {
|
||||
readText,
|
||||
writeText
|
||||
};
|
111
src/dialog.js
Normal file
111
src/dialog.js
Normal file
|
@ -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
|
||||
};
|
123
src/event.js
Normal file
123
src/event.js
Normal file
|
@ -0,0 +1,123 @@
|
|||
// 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
|
||||
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);
|
||||
}
|
||||
export {
|
||||
TauriEvent,
|
||||
emit2 as emit,
|
||||
listen2 as listen,
|
||||
once2 as once
|
||||
};
|
243
src/fs.js
Normal file
243
src/fs.js
Normal file
|
@ -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
|
||||
};
|
97
src/globalShortcut.js
Normal file
97
src/globalShortcut.js
Normal file
|
@ -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
|
||||
};
|
207
src/http.js
Normal file
207
src/http.js
Normal file
|
@ -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
|
||||
};
|
2402
src/index.js
Normal file
2402
src/index.js
Normal file
File diff suppressed because it is too large
Load diff
30
src/mocks.js
Normal file
30
src/mocks.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
// tauri/tooling/api/src/mocks.ts
|
||||
function mockIPC(cb) {
|
||||
window.__TAURI_IPC__ = async ({
|
||||
cmd,
|
||||
callback,
|
||||
error,
|
||||
...args
|
||||
}) => {
|
||||
try {
|
||||
window[`_${callback}`](await cb(cmd, args));
|
||||
} catch (err) {
|
||||
window[`_${error}`](err);
|
||||
}
|
||||
};
|
||||
}
|
||||
function mockWindows(current, ...additionalWindows) {
|
||||
window.__TAURI_METADATA__ = {
|
||||
__windows: [current, ...additionalWindows].map((label) => ({ label })),
|
||||
__currentWindow: { label: current }
|
||||
};
|
||||
}
|
||||
function clearMocks() {
|
||||
delete window.__TAURI_IPC__;
|
||||
delete window.__TAURI_METADATA__;
|
||||
}
|
||||
export {
|
||||
clearMocks,
|
||||
mockIPC,
|
||||
mockWindows
|
||||
};
|
70
src/notification.js
Normal file
70
src/notification.js
Normal file
|
@ -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
|
||||
};
|
98
src/os.js
Normal file
98
src/os.js
Normal file
|
@ -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
|
||||
};
|
418
src/path.js
Normal file
418
src/path.js
Normal file
|
@ -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
|
||||
};
|
65
src/process.js
Normal file
65
src/process.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
// 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/process.ts
|
||||
async function exit(exitCode = 0) {
|
||||
return invokeTauriCommand({
|
||||
__tauriModule: "Process",
|
||||
message: {
|
||||
cmd: "exit",
|
||||
exitCode
|
||||
}
|
||||
});
|
||||
}
|
||||
async function relaunch() {
|
||||
return invokeTauriCommand({
|
||||
__tauriModule: "Process",
|
||||
message: {
|
||||
cmd: "relaunch"
|
||||
}
|
||||
});
|
||||
}
|
||||
export {
|
||||
exit,
|
||||
relaunch
|
||||
};
|
230
src/shell.js
Normal file
230
src/shell.js
Normal file
|
@ -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
|
||||
};
|
46
src/tauri.js
Normal file
46
src/tauri.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
// 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
|
||||
});
|
||||
});
|
||||
}
|
||||
function convertFileSrc(filePath, protocol = "asset") {
|
||||
const path = encodeURIComponent(filePath);
|
||||
return navigator.userAgent.includes("Windows") ? `https://${protocol}.localhost/${path}` : `${protocol}://localhost/${path}`;
|
||||
}
|
||||
export {
|
||||
convertFileSrc,
|
||||
invoke,
|
||||
transformCallback
|
||||
};
|
185
src/updater.js
Normal file
185
src/updater.js
Normal file
|
@ -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
|
||||
};
|
1004
src/window.js
Normal file
1004
src/window.js
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue