chore: upgrade to tauri v2 rc
This commit is contained in:
140
src/commands.ts
140
src/commands.ts
@@ -1,11 +1,12 @@
|
||||
|
||||
// This file was generated by [tauri-specta](https://github.com/oscartbeaumont/tauri-specta). Do not edit this file manually.
|
||||
// This file was generated by [tauri-specta](https://github.com/oscartbeaumont/tauri-specta). Do not edit this file manually.
|
||||
|
||||
/** user-defined commands **/
|
||||
/** user-defined commands **/
|
||||
|
||||
export const commands = {
|
||||
|
||||
export const commands = {
|
||||
async getBootstrapRelays() : Promise<Result<string[], string>> {
|
||||
try {
|
||||
try {
|
||||
return { status: "ok", data: await TAURI_INVOKE("get_bootstrap_relays") };
|
||||
} catch (e) {
|
||||
if(e instanceof Error) throw e;
|
||||
@@ -13,7 +14,7 @@ try {
|
||||
}
|
||||
},
|
||||
async setBootstrapRelays(relays: string) : Promise<Result<null, string>> {
|
||||
try {
|
||||
try {
|
||||
return { status: "ok", data: await TAURI_INVOKE("set_bootstrap_relays", { relays }) };
|
||||
} catch (e) {
|
||||
if(e instanceof Error) throw e;
|
||||
@@ -21,7 +22,7 @@ try {
|
||||
}
|
||||
},
|
||||
async getInboxRelays(userId: string) : Promise<Result<string[], string>> {
|
||||
try {
|
||||
try {
|
||||
return { status: "ok", data: await TAURI_INVOKE("get_inbox_relays", { userId }) };
|
||||
} catch (e) {
|
||||
if(e instanceof Error) throw e;
|
||||
@@ -29,7 +30,7 @@ try {
|
||||
}
|
||||
},
|
||||
async setInboxRelays(relays: string[]) : Promise<Result<null, string>> {
|
||||
try {
|
||||
try {
|
||||
return { status: "ok", data: await TAURI_INVOKE("set_inbox_relays", { relays }) };
|
||||
} catch (e) {
|
||||
if(e instanceof Error) throw e;
|
||||
@@ -37,7 +38,7 @@ try {
|
||||
}
|
||||
},
|
||||
async connectInboxRelays(userId: string, ignoreCache: boolean) : Promise<Result<string[], string>> {
|
||||
try {
|
||||
try {
|
||||
return { status: "ok", data: await TAURI_INVOKE("connect_inbox_relays", { userId, ignoreCache }) };
|
||||
} catch (e) {
|
||||
if(e instanceof Error) throw e;
|
||||
@@ -45,7 +46,7 @@ try {
|
||||
}
|
||||
},
|
||||
async disconnectInboxRelays(userId: string) : Promise<Result<null, string>> {
|
||||
try {
|
||||
try {
|
||||
return { status: "ok", data: await TAURI_INVOKE("disconnect_inbox_relays", { userId }) };
|
||||
} catch (e) {
|
||||
if(e instanceof Error) throw e;
|
||||
@@ -53,7 +54,7 @@ try {
|
||||
}
|
||||
},
|
||||
async login(account: string, password: string) : Promise<Result<string, string>> {
|
||||
try {
|
||||
try {
|
||||
return { status: "ok", data: await TAURI_INVOKE("login", { account, password }) };
|
||||
} catch (e) {
|
||||
if(e instanceof Error) throw e;
|
||||
@@ -61,7 +62,7 @@ try {
|
||||
}
|
||||
},
|
||||
async deleteAccount(id: string) : Promise<Result<null, string>> {
|
||||
try {
|
||||
try {
|
||||
return { status: "ok", data: await TAURI_INVOKE("delete_account", { id }) };
|
||||
} catch (e) {
|
||||
if(e instanceof Error) throw e;
|
||||
@@ -69,7 +70,7 @@ try {
|
||||
}
|
||||
},
|
||||
async createAccount(name: string, about: string, picture: string, password: string) : Promise<Result<string, string>> {
|
||||
try {
|
||||
try {
|
||||
return { status: "ok", data: await TAURI_INVOKE("create_account", { name, about, picture, password }) };
|
||||
} catch (e) {
|
||||
if(e instanceof Error) throw e;
|
||||
@@ -77,7 +78,7 @@ try {
|
||||
}
|
||||
},
|
||||
async importKey(key: string, password: string | null) : Promise<Result<string, string>> {
|
||||
try {
|
||||
try {
|
||||
return { status: "ok", data: await TAURI_INVOKE("import_key", { key, password }) };
|
||||
} catch (e) {
|
||||
if(e instanceof Error) throw e;
|
||||
@@ -85,7 +86,7 @@ try {
|
||||
}
|
||||
},
|
||||
async connectAccount(uri: string) : Promise<Result<string, string>> {
|
||||
try {
|
||||
try {
|
||||
return { status: "ok", data: await TAURI_INVOKE("connect_account", { uri }) };
|
||||
} catch (e) {
|
||||
if(e instanceof Error) throw e;
|
||||
@@ -93,18 +94,18 @@ try {
|
||||
}
|
||||
},
|
||||
async getAccounts() : Promise<string[]> {
|
||||
return await TAURI_INVOKE("get_accounts");
|
||||
return await TAURI_INVOKE("get_accounts");
|
||||
},
|
||||
async getMetadata(id: string) : Promise<Result<string, string>> {
|
||||
try {
|
||||
return { status: "ok", data: await TAURI_INVOKE("get_metadata", { id }) };
|
||||
async getMetadata(userId: string) : Promise<Result<string, string>> {
|
||||
try {
|
||||
return { status: "ok", data: await TAURI_INVOKE("get_metadata", { userId }) };
|
||||
} catch (e) {
|
||||
if(e instanceof Error) throw e;
|
||||
else return { status: "error", error: e as any };
|
||||
}
|
||||
},
|
||||
async getContactList() : Promise<Result<string[], string>> {
|
||||
try {
|
||||
try {
|
||||
return { status: "ok", data: await TAURI_INVOKE("get_contact_list") };
|
||||
} catch (e) {
|
||||
if(e instanceof Error) throw e;
|
||||
@@ -112,7 +113,7 @@ try {
|
||||
}
|
||||
},
|
||||
async getChats() : Promise<Result<string[], string>> {
|
||||
try {
|
||||
try {
|
||||
return { status: "ok", data: await TAURI_INVOKE("get_chats") };
|
||||
} catch (e) {
|
||||
if(e instanceof Error) throw e;
|
||||
@@ -120,7 +121,7 @@ try {
|
||||
}
|
||||
},
|
||||
async getChatMessages(id: string) : Promise<Result<string[], string>> {
|
||||
try {
|
||||
try {
|
||||
return { status: "ok", data: await TAURI_INVOKE("get_chat_messages", { id }) };
|
||||
} catch (e) {
|
||||
if(e instanceof Error) throw e;
|
||||
@@ -128,7 +129,7 @@ try {
|
||||
}
|
||||
},
|
||||
async sendMessage(to: string, message: string) : Promise<Result<null, string>> {
|
||||
try {
|
||||
try {
|
||||
return { status: "ok", data: await TAURI_INVOKE("send_message", { to, message }) };
|
||||
} catch (e) {
|
||||
if(e instanceof Error) throw e;
|
||||
@@ -137,13 +138,13 @@ try {
|
||||
}
|
||||
}
|
||||
|
||||
/** user-defined events **/
|
||||
/** user-defined events **/
|
||||
|
||||
|
||||
|
||||
/** user-defined statics **/
|
||||
/** user-defined constants **/
|
||||
|
||||
|
||||
|
||||
|
||||
/** user-defined types **/
|
||||
|
||||
@@ -151,59 +152,60 @@ try {
|
||||
|
||||
/** tauri-specta globals **/
|
||||
|
||||
import { invoke as TAURI_INVOKE } from "@tauri-apps/api/core";
|
||||
import {
|
||||
invoke as TAURI_INVOKE,
|
||||
Channel as TAURI_CHANNEL,
|
||||
} from "@tauri-apps/api/core";
|
||||
import * as TAURI_API_EVENT from "@tauri-apps/api/event";
|
||||
import { type WebviewWindow as __WebviewWindow__ } from "@tauri-apps/api/webviewWindow";
|
||||
|
||||
type __EventObj__<T> = {
|
||||
listen: (
|
||||
cb: TAURI_API_EVENT.EventCallback<T>
|
||||
) => ReturnType<typeof TAURI_API_EVENT.listen<T>>;
|
||||
once: (
|
||||
cb: TAURI_API_EVENT.EventCallback<T>
|
||||
) => ReturnType<typeof TAURI_API_EVENT.once<T>>;
|
||||
emit: T extends null
|
||||
? (payload?: T) => ReturnType<typeof TAURI_API_EVENT.emit>
|
||||
: (payload: T) => ReturnType<typeof TAURI_API_EVENT.emit>;
|
||||
listen: (
|
||||
cb: TAURI_API_EVENT.EventCallback<T>,
|
||||
) => ReturnType<typeof TAURI_API_EVENT.listen<T>>;
|
||||
once: (
|
||||
cb: TAURI_API_EVENT.EventCallback<T>,
|
||||
) => ReturnType<typeof TAURI_API_EVENT.once<T>>;
|
||||
emit: T extends null
|
||||
? (payload?: T) => ReturnType<typeof TAURI_API_EVENT.emit>
|
||||
: (payload: T) => ReturnType<typeof TAURI_API_EVENT.emit>;
|
||||
};
|
||||
|
||||
export type Result<T, E> =
|
||||
| { status: "ok"; data: T }
|
||||
| { status: "error"; error: E };
|
||||
| { status: "ok"; data: T }
|
||||
| { status: "error"; error: E };
|
||||
|
||||
function __makeEvents__<T extends Record<string, any>>(
|
||||
mappings: Record<keyof T, string>
|
||||
mappings: Record<keyof T, string>,
|
||||
) {
|
||||
return new Proxy(
|
||||
{} as unknown as {
|
||||
[K in keyof T]: __EventObj__<T[K]> & {
|
||||
(handle: __WebviewWindow__): __EventObj__<T[K]>;
|
||||
};
|
||||
},
|
||||
{
|
||||
get: (_, event) => {
|
||||
const name = mappings[event as keyof T];
|
||||
return new Proxy(
|
||||
{} as unknown as {
|
||||
[K in keyof T]: __EventObj__<T[K]> & {
|
||||
(handle: __WebviewWindow__): __EventObj__<T[K]>;
|
||||
};
|
||||
},
|
||||
{
|
||||
get: (_, event) => {
|
||||
const name = mappings[event as keyof T];
|
||||
|
||||
return new Proxy((() => {}) as any, {
|
||||
apply: (_, __, [window]: [__WebviewWindow__]) => ({
|
||||
listen: (arg: any) => window.listen(name, arg),
|
||||
once: (arg: any) => window.once(name, arg),
|
||||
emit: (arg: any) => window.emit(name, arg),
|
||||
}),
|
||||
get: (_, command: keyof __EventObj__<any>) => {
|
||||
switch (command) {
|
||||
case "listen":
|
||||
return (arg: any) => TAURI_API_EVENT.listen(name, arg);
|
||||
case "once":
|
||||
return (arg: any) => TAURI_API_EVENT.once(name, arg);
|
||||
case "emit":
|
||||
return (arg: any) => TAURI_API_EVENT.emit(name, arg);
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
}
|
||||
);
|
||||
return new Proxy((() => {}) as any, {
|
||||
apply: (_, __, [window]: [__WebviewWindow__]) => ({
|
||||
listen: (arg: any) => window.listen(name, arg),
|
||||
once: (arg: any) => window.once(name, arg),
|
||||
emit: (arg: any) => window.emit(name, arg),
|
||||
}),
|
||||
get: (_, command: keyof __EventObj__<any>) => {
|
||||
switch (command) {
|
||||
case "listen":
|
||||
return (arg: any) => TAURI_API_EVENT.listen(name, arg);
|
||||
case "once":
|
||||
return (arg: any) => TAURI_API_EVENT.once(name, arg);
|
||||
case "emit":
|
||||
return (arg: any) => TAURI_API_EVENT.emit(name, arg);
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user