175 lines
5.2 KiB
TypeScript
175 lines
5.2 KiB
TypeScript
// This file was generated by [tauri-specta](https://github.com/oscartbeaumont/tauri-specta). Do not edit this file manually.
|
|
|
|
/** user-defined commands */
|
|
|
|
/** tauri-specta globals */
|
|
|
|
import type { WebviewWindow as __WebviewWindow__ } from '@tauri-apps/api/webviewWindow';
|
|
import {
|
|
invoke as TAURI_INVOKE,
|
|
} from '@tauri-apps/api/core';
|
|
import * as TAURI_API_EVENT from '@tauri-apps/api/event';
|
|
|
|
export const commands = {
|
|
async getUsers(): Promise<Result<Array<MinecraftCredentials>, SerializableError>> {
|
|
try {
|
|
return { status: 'ok', data: await TAURI_INVOKE('get_users') };
|
|
}
|
|
catch (e) {
|
|
if (e instanceof Error)
|
|
throw e;
|
|
else return { status: 'error', error: e as any };
|
|
}
|
|
},
|
|
async getUser(uuid: string): Promise<Result<MinecraftCredentials, SerializableError>> {
|
|
try {
|
|
return { status: 'ok', data: await TAURI_INVOKE('get_user', { uuid }) };
|
|
}
|
|
catch (e) {
|
|
if (e instanceof Error)
|
|
throw e;
|
|
else return { status: 'error', error: e as any };
|
|
}
|
|
},
|
|
async removeUser(uuid: string): Promise<Result<null, SerializableError>> {
|
|
try {
|
|
return { status: 'ok', data: await TAURI_INVOKE('remove_user', { uuid }) };
|
|
}
|
|
catch (e) {
|
|
if (e instanceof Error)
|
|
throw e;
|
|
else return { status: 'error', error: e as any };
|
|
}
|
|
},
|
|
async getDefaultUser(fallback: boolean | null): Promise<Result<MinecraftCredentials | null, SerializableError>> {
|
|
try {
|
|
return { status: 'ok', data: await TAURI_INVOKE('get_default_user', { fallback }) };
|
|
}
|
|
catch (e) {
|
|
if (e instanceof Error)
|
|
throw e;
|
|
else return { status: 'error', error: e as any };
|
|
}
|
|
},
|
|
async setDefaultUser(uuid: string | null): Promise<Result<null, SerializableError>> {
|
|
try {
|
|
return { status: 'ok', data: await TAURI_INVOKE('set_default_user', { uuid }) };
|
|
}
|
|
catch (e) {
|
|
if (e instanceof Error)
|
|
throw e;
|
|
else return { status: 'error', error: e as any };
|
|
}
|
|
},
|
|
async beginMsFlow(): Promise<Result<MinecraftCredentials | null, SerializableError>> {
|
|
try {
|
|
return { status: 'ok', data: await TAURI_INVOKE('begin_ms_flow') };
|
|
}
|
|
catch (e) {
|
|
if (e instanceof Error)
|
|
throw e;
|
|
else return { status: 'error', error: e as any };
|
|
}
|
|
},
|
|
async openDevTools(): Promise<void> {
|
|
await TAURI_INVOKE('open_dev_tools');
|
|
},
|
|
};
|
|
|
|
/** user-defined events */
|
|
|
|
export const events = __makeEvents__<{
|
|
launcherEvent: LauncherEvent;
|
|
}>({
|
|
launcherEvent: 'launcher-event',
|
|
});
|
|
|
|
/** user-defined constants */
|
|
|
|
/** user-defined types */
|
|
|
|
export interface IngressPayload { id: string; message: string; ingress_type: IngressType; percent: number | null; total: number }
|
|
export type IngressType = { Download: { file_name: string } } | 'JavaPrepare' | 'JavaCheck' | 'JavaLocate' | 'MinecraftDownload' | { PrepareCluster: { cluster_name: string } };
|
|
export type LauncherEvent = { Ingress: IngressPayload } | { Message: MessagePayload } | { Process: ProcessPayload };
|
|
export type MessageLevel = 'Info' | 'Warn' | 'Error';
|
|
export interface MessagePayload { level: MessageLevel; message: string }
|
|
/**
|
|
* A structure of all needed Minecraft credentials for logging in and account management.
|
|
*/
|
|
export interface MinecraftCredentials {
|
|
/**
|
|
* The uuid of the credentials.
|
|
*/
|
|
id: string;
|
|
/**
|
|
* The username of the Minecraft account.
|
|
*/
|
|
username: string;
|
|
/**
|
|
* The access token as a String.
|
|
*/
|
|
access_token: string;
|
|
/**
|
|
* The refresh token as a string for [`MinecraftState#refresh`].
|
|
*/
|
|
refresh_token: string;
|
|
/**
|
|
* The time that the access token expires as a [`DateTime<Utc>`].
|
|
*/
|
|
expires: string;
|
|
|
|
}
|
|
export interface Process { pid: number; started_at: string; cluster_id: bigint; post_hook: string | null; account_id: string }
|
|
export type ProcessPayload = { Starting: { command: string } } | { Started: { process: Process } } | { Stopped: { pid: number; exit_code: number } } | { Output: { pid: number; output: string } };
|
|
export interface SerializableError { kind: 'CoreError' }
|
|
|
|
interface __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: null extends T
|
|
? (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);
|
|
}
|
|
},
|
|
});
|
|
},
|
|
},
|
|
);
|
|
}
|