212 lines
6.5 KiB
TypeScript
212 lines
6.5 KiB
TypeScript
|
|
// This file was generated by [tauri-specta](https://github.com/oscartbeaumont/tauri-specta). Do not edit this file manually.
|
|
|
|
/** user-defined commands **/
|
|
|
|
|
|
export const commands = {
|
|
async getBootstrapRelays() : Promise<Result<string[], string>> {
|
|
try {
|
|
return { status: "ok", data: await TAURI_INVOKE("get_bootstrap_relays") };
|
|
} catch (e) {
|
|
if(e instanceof Error) throw e;
|
|
else return { status: "error", error: e as any };
|
|
}
|
|
},
|
|
async setBootstrapRelays(relays: string) : Promise<Result<null, string>> {
|
|
try {
|
|
return { status: "ok", data: await TAURI_INVOKE("set_bootstrap_relays", { relays }) };
|
|
} catch (e) {
|
|
if(e instanceof Error) throw e;
|
|
else return { status: "error", error: e as any };
|
|
}
|
|
},
|
|
async collectInboxRelays(userId: string) : Promise<Result<string[], string>> {
|
|
try {
|
|
return { status: "ok", data: await TAURI_INVOKE("collect_inbox_relays", { userId }) };
|
|
} catch (e) {
|
|
if(e instanceof Error) throw e;
|
|
else return { status: "error", error: e as any };
|
|
}
|
|
},
|
|
async setInboxRelays(relays: string[]) : Promise<Result<null, string>> {
|
|
try {
|
|
return { status: "ok", data: await TAURI_INVOKE("set_inbox_relays", { relays }) };
|
|
} catch (e) {
|
|
if(e instanceof Error) throw e;
|
|
else return { status: "error", error: e as any };
|
|
}
|
|
},
|
|
async connectInboxRelays(userId: string, ignoreCache: boolean) : Promise<Result<string[], string>> {
|
|
try {
|
|
return { status: "ok", data: await TAURI_INVOKE("connect_inbox_relays", { userId, ignoreCache }) };
|
|
} catch (e) {
|
|
if(e instanceof Error) throw e;
|
|
else return { status: "error", error: e as any };
|
|
}
|
|
},
|
|
async disconnectInboxRelays(userId: string) : Promise<Result<null, string>> {
|
|
try {
|
|
return { status: "ok", data: await TAURI_INVOKE("disconnect_inbox_relays", { userId }) };
|
|
} catch (e) {
|
|
if(e instanceof Error) throw e;
|
|
else return { status: "error", error: e as any };
|
|
}
|
|
},
|
|
async login(account: string, password: string) : Promise<Result<string, string>> {
|
|
try {
|
|
return { status: "ok", data: await TAURI_INVOKE("login", { account, password }) };
|
|
} catch (e) {
|
|
if(e instanceof Error) throw e;
|
|
else return { status: "error", error: e as any };
|
|
}
|
|
},
|
|
async deleteAccount(id: string) : Promise<Result<null, string>> {
|
|
try {
|
|
return { status: "ok", data: await TAURI_INVOKE("delete_account", { id }) };
|
|
} catch (e) {
|
|
if(e instanceof Error) throw e;
|
|
else return { status: "error", error: e as any };
|
|
}
|
|
},
|
|
async createAccount(name: string, about: string, picture: string, password: string) : Promise<Result<string, string>> {
|
|
try {
|
|
return { status: "ok", data: await TAURI_INVOKE("create_account", { name, about, picture, password }) };
|
|
} catch (e) {
|
|
if(e instanceof Error) throw e;
|
|
else return { status: "error", error: e as any };
|
|
}
|
|
},
|
|
async importKey(key: string, password: string | null) : Promise<Result<string, string>> {
|
|
try {
|
|
return { status: "ok", data: await TAURI_INVOKE("import_key", { key, password }) };
|
|
} catch (e) {
|
|
if(e instanceof Error) throw e;
|
|
else return { status: "error", error: e as any };
|
|
}
|
|
},
|
|
async connectAccount(uri: string) : Promise<Result<string, string>> {
|
|
try {
|
|
return { status: "ok", data: await TAURI_INVOKE("connect_account", { uri }) };
|
|
} catch (e) {
|
|
if(e instanceof Error) throw e;
|
|
else return { status: "error", error: e as any };
|
|
}
|
|
},
|
|
async getAccounts() : Promise<string[]> {
|
|
return await TAURI_INVOKE("get_accounts");
|
|
},
|
|
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 {
|
|
return { status: "ok", data: await TAURI_INVOKE("get_contact_list") };
|
|
} catch (e) {
|
|
if(e instanceof Error) throw e;
|
|
else return { status: "error", error: e as any };
|
|
}
|
|
},
|
|
async getChats() : Promise<Result<string[], string>> {
|
|
try {
|
|
return { status: "ok", data: await TAURI_INVOKE("get_chats") };
|
|
} catch (e) {
|
|
if(e instanceof Error) throw e;
|
|
else return { status: "error", error: e as any };
|
|
}
|
|
},
|
|
async getChatMessages(id: string) : Promise<Result<string[], string>> {
|
|
try {
|
|
return { status: "ok", data: await TAURI_INVOKE("get_chat_messages", { id }) };
|
|
} catch (e) {
|
|
if(e instanceof Error) throw e;
|
|
else return { status: "error", error: e as any };
|
|
}
|
|
},
|
|
async sendMessage(to: string, message: string) : Promise<Result<null, string>> {
|
|
try {
|
|
return { status: "ok", data: await TAURI_INVOKE("send_message", { to, message }) };
|
|
} catch (e) {
|
|
if(e instanceof Error) throw e;
|
|
else return { status: "error", error: e as any };
|
|
}
|
|
}
|
|
}
|
|
|
|
/** user-defined events **/
|
|
|
|
|
|
|
|
/** user-defined constants **/
|
|
|
|
|
|
|
|
/** user-defined types **/
|
|
|
|
|
|
|
|
/** tauri-specta globals **/
|
|
|
|
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>;
|
|
};
|
|
|
|
export type Result<T, E> =
|
|
| { status: "ok"; data: T }
|
|
| { status: "error"; error: E };
|
|
|
|
function __makeEvents__<T extends Record<string, any>>(
|
|
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 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);
|
|
}
|
|
},
|
|
});
|
|
},
|
|
},
|
|
);
|
|
}
|