migrate from ts-rs to tauri-specta

This commit is contained in:
2026-03-07 18:36:51 +08:00
parent f65d837841
commit 4d7e97771a
86 changed files with 766 additions and 609 deletions

281
src/lib/bindings.ts Normal file
View File

@@ -0,0 +1,281 @@
// 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 getAppData() : Promise<UserData> {
return await TAURI_INVOKE("get_app_data");
},
async refreshAppData() : Promise<UserData> {
return await TAURI_INVOKE("refresh_app_data");
},
async listFriends() : Promise<FriendshipResponseDto[]> {
return await TAURI_INVOKE("list_friends");
},
async searchUsers(username: string | null) : Promise<UserBasicDto[]> {
return await TAURI_INVOKE("search_users", { username });
},
async sendFriendRequest(request: SendFriendRequestDto) : Promise<FriendRequestResponseDto> {
return await TAURI_INVOKE("send_friend_request", { request });
},
async receivedFriendRequests() : Promise<FriendRequestResponseDto[]> {
return await TAURI_INVOKE("received_friend_requests");
},
async sentFriendRequests() : Promise<FriendRequestResponseDto[]> {
return await TAURI_INVOKE("sent_friend_requests");
},
async acceptFriendRequest(requestId: string) : Promise<FriendRequestResponseDto> {
return await TAURI_INVOKE("accept_friend_request", { requestId });
},
async denyFriendRequest(requestId: string) : Promise<FriendRequestResponseDto> {
return await TAURI_INVOKE("deny_friend_request", { requestId });
},
async unfriend(friendId: string) : Promise<null> {
return await TAURI_INVOKE("unfriend", { friendId });
},
async getDolls() : Promise<DollDto[]> {
return await TAURI_INVOKE("get_dolls");
},
async getDoll(id: string) : Promise<DollDto> {
return await TAURI_INVOKE("get_doll", { id });
},
async createDoll(dto: CreateDollDto) : Promise<DollDto> {
return await TAURI_INVOKE("create_doll", { dto });
},
async updateDoll(id: string, dto: UpdateDollDto) : Promise<DollDto> {
return await TAURI_INVOKE("update_doll", { id, dto });
},
async deleteDoll(id: string) : Promise<null> {
return await TAURI_INVOKE("delete_doll", { id });
},
async setActiveDoll(dollId: string) : Promise<null> {
return await TAURI_INVOKE("set_active_doll", { dollId });
},
async removeActiveDoll() : Promise<null> {
return await TAURI_INVOKE("remove_active_doll");
},
async recolorGifBase64(whiteColorHex: string, blackColorHex: string, applyTexture: boolean) : Promise<string> {
return await TAURI_INVOKE("recolor_gif_base64", { whiteColorHex, blackColorHex, applyTexture });
},
async encodePetDollGifBase64(doll: DollDto) : Promise<string> {
return await TAURI_INVOKE("encode_pet_doll_gif_base64", { doll });
},
async quitApp() : Promise<null> {
return await TAURI_INVOKE("quit_app");
},
async restartApp() : Promise<void> {
await TAURI_INVOKE("restart_app");
},
/**
* Attempt to re-establish the user session without restarting the app.
*
* Validates server health, checks for a valid session token,
* then reconstructs the user session (re-fetches app data + WebSocket).
*/
async retryConnection() : Promise<null> {
return await TAURI_INVOKE("retry_connection");
},
async getClientConfig() : Promise<AppConfig> {
return await TAURI_INVOKE("get_client_config");
},
async saveClientConfig(config: AppConfig) : Promise<null> {
return await TAURI_INVOKE("save_client_config", { config });
},
async openClientConfigManager() : Promise<null> {
return await TAURI_INVOKE("open_client_config_manager");
},
async openDollEditorWindow(dollId: string | null) : Promise<void> {
await TAURI_INVOKE("open_doll_editor_window", { dollId });
},
async getSceneInteractive() : Promise<boolean> {
return await TAURI_INVOKE("get_scene_interactive");
},
async setSceneInteractive(interactive: boolean, shouldClick: boolean) : Promise<void> {
await TAURI_INVOKE("set_scene_interactive", { interactive, shouldClick });
},
async setPetMenuState(id: string, open: boolean) : Promise<void> {
await TAURI_INVOKE("set_pet_menu_state", { id, open });
},
async login(email: string, password: string) : Promise<null> {
return await TAURI_INVOKE("login", { email, password });
},
async register(email: string, password: string, name: string | null, username: string | null) : Promise<string> {
return await TAURI_INVOKE("register", { email, password, name, username });
},
async changePassword(currentPassword: string, newPassword: string) : Promise<null> {
return await TAURI_INVOKE("change_password", { currentPassword, newPassword });
},
async resetPassword(oldPassword: string, newPassword: string) : Promise<null> {
return await TAURI_INVOKE("reset_password", { oldPassword, newPassword });
},
async logoutAndRestart() : Promise<null> {
return await TAURI_INVOKE("logout_and_restart");
},
async sendInteractionCmd(dto: SendInteractionDto) : Promise<null> {
return await TAURI_INVOKE("send_interaction_cmd", { dto });
},
async getModules() : Promise<ModuleMetadata[]> {
return await TAURI_INVOKE("get_modules");
}
}
/** user-defined events **/
export const events = __makeEvents__<{
appDataRefreshed: AppDataRefreshed,
createDoll: CreateDoll,
cursorMoved: CursorMoved,
editDoll: EditDoll,
friendActiveDollChanged: FriendActiveDollChanged,
friendCursorPositionUpdated: FriendCursorPositionUpdated,
friendDisconnected: FriendDisconnected,
friendRequestAccepted: FriendRequestAccepted,
friendRequestDenied: FriendRequestDenied,
friendRequestReceived: FriendRequestReceived,
friendUserStatusChanged: FriendUserStatusChanged,
interactionDeliveryFailed: InteractionDeliveryFailed,
interactionReceived: InteractionReceived,
sceneInteractiveChanged: SceneInteractiveChanged,
setInteractionOverlay: SetInteractionOverlay,
unfriended: Unfriended,
userStatusChanged: UserStatusChanged
}>({
appDataRefreshed: "app-data-refreshed",
createDoll: "create-doll",
cursorMoved: "cursor-moved",
editDoll: "edit-doll",
friendActiveDollChanged: "friend-active-doll-changed",
friendCursorPositionUpdated: "friend-cursor-position-updated",
friendDisconnected: "friend-disconnected",
friendRequestAccepted: "friend-request-accepted",
friendRequestDenied: "friend-request-denied",
friendRequestReceived: "friend-request-received",
friendUserStatusChanged: "friend-user-status-changed",
interactionDeliveryFailed: "interaction-delivery-failed",
interactionReceived: "interaction-received",
sceneInteractiveChanged: "scene-interactive-changed",
setInteractionOverlay: "set-interaction-overlay",
unfriended: "unfriended",
userStatusChanged: "user-status-changed"
})
/** user-defined constants **/
/** user-defined types **/
export type AppConfig = { api_base_url: string | null }
export type AppDataRefreshed = UserData
export type CreateDoll = null
export type CreateDollDto = { name: string; configuration: DollConfigurationDto | null }
export type CursorMoved = CursorPositions
export type CursorPosition = { x: number; y: number }
export type CursorPositions = { raw: CursorPosition; mapped: CursorPosition }
export type DisplayData = { screen_width: number; screen_height: number; monitor_scale_factor: number }
export type DollColorSchemeDto = { outline: string; body: string }
export type DollConfigurationDto = { colorScheme: DollColorSchemeDto }
export type DollDto = { id: string; name: string; configuration: DollConfigurationDto; createdAt: string; updatedAt: string }
export type EditDoll = string
export type FriendActiveDollChanged = FriendActiveDollChangedPayload
export type FriendActiveDollChangedPayload = { friendId: string; doll: DollDto | null }
export type FriendCursorPositionUpdated = OutgoingFriendCursorPayload
export type FriendDisconnected = FriendDisconnectedPayload
export type FriendDisconnectedPayload = { userId: string }
export type FriendRequestAccepted = FriendRequestAcceptedPayload
export type FriendRequestAcceptedPayload = { id: string; friend: UserBasicDto; acceptedAt: string }
export type FriendRequestDenied = FriendRequestDeniedPayload
export type FriendRequestDeniedPayload = { id: string; denier: UserBasicDto; deniedAt: string }
export type FriendRequestReceived = FriendRequestReceivedPayload
export type FriendRequestReceivedPayload = { id: string; sender: UserBasicDto; createdAt: string }
export type FriendRequestResponseDto = { id: string; sender: UserBasicDto; receiver: UserBasicDto; status: string; createdAt: string; updatedAt: string }
export type FriendUserStatusChanged = FriendUserStatusPayload
export type FriendUserStatusPayload = { userId: string; status: UserStatusPayload }
export type FriendshipResponseDto = { id: string; friend: UserBasicDto | null; createdAt: string }
export type InteractionDeliveryFailed = InteractionDeliveryFailedDto
export type InteractionDeliveryFailedDto = { recipientUserId: string; reason: string }
export type InteractionPayloadDto = { senderUserId: string; senderName: string; content: string; type: string; timestamp: string }
export type InteractionReceived = InteractionPayloadDto
export type ModuleMetadata = { id: string; name: string; version: string; description: string | null }
/**
* Outgoing friend cursor position to frontend
*/
export type OutgoingFriendCursorPayload = { userId: string; position: CursorPositions }
export type PresenceStatus = { title: string | null; subtitle: string | null; graphicsB64: string | null }
export type SceneData = { display: DisplayData; grid_size: number }
export type SceneInteractiveChanged = boolean
export type SendFriendRequestDto = { receiverId: string }
export type SendInteractionDto = { recipientUserId: string; content: string; type: string }
export type SetInteractionOverlay = boolean
export type Unfriended = UnfriendedPayload
export type UnfriendedPayload = { friendId: string }
export type UpdateDollDto = { name: string | null; configuration: DollConfigurationDto | null }
export type UserBasicDto = { id: string; name: string; username: string | null; activeDoll: DollDto | null }
export type UserData = { user: UserProfile | null; friends: FriendshipResponseDto[] | null; dolls: DollDto[] | null; scene: SceneData }
export type UserProfile = { id: string; name: string; email: string; username: string | null; roles: string[]; createdAt: string; updatedAt: string; lastLoginAt: string | null; activeDollId: string | null }
export type UserStatusChanged = UserStatusPayload
export type UserStatusPayload = { presenceStatus: PresenceStatus; state: UserStatusState }
export type UserStatusState = "idle" | "resting"
/** 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: 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);
}
},
});
},
},
);
}