initial commit

This commit is contained in:
Jonas Kruckenberg 2022-11-01 15:19:25 +01:00
commit c3e5b84282
54 changed files with 2009 additions and 0 deletions

91
dist/app.js vendored Normal file
View 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
};

66
dist/clipboard.js vendored Normal file
View 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
};

123
dist/event.js vendored Normal file
View 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
};

30
dist/mocks.js vendored Normal file
View 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
};

46
dist/tauri.js vendored Normal file
View 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
};