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

View File

@@ -3,14 +3,13 @@
import Preferences from "./tabs/preferences.svelte";
import Modules from "./tabs/modules.svelte";
import YourDolls from "./tabs/your-dolls/index.svelte";
import { listen } from "@tauri-apps/api/event";
import { events } from "$lib/bindings";
import { onMount } from "svelte";
import { AppEvents } from "../../types/bindings/AppEventsConstants";
let showInteractionOverlay = false;
onMount(() => {
const unlisten = listen(AppEvents.SetInteractionOverlay, (event) => {
const unlisten = events.setInteractionOverlay.listen((event) => {
showInteractionOverlay = event.payload as boolean;
});

View File

@@ -1,12 +1,13 @@
<script lang="ts">
import { onMount, onDestroy } from "svelte";
import { listen } from "@tauri-apps/api/event";
import { invoke } from "@tauri-apps/api/core";
import {
commands,
events,
type FriendRequestResponseDto,
type FriendshipResponseDto,
type UserBasicDto,
} from "$lib/bindings";
import { appData } from "../../../events/app-data";
import { AppEvents } from "../../../types/bindings/AppEventsConstants";
import type { FriendRequestResponseDto } from "../../../types/bindings/FriendRequestResponseDto.js";
import type { FriendshipResponseDto } from "../../../types/bindings/FriendshipResponseDto.js";
import type { UserBasicDto } from "../../../types/bindings/UserBasicDto.js";
let received: FriendRequestResponseDto[] = [];
let sent: FriendRequestResponseDto[] = [];
@@ -51,27 +52,27 @@
refreshSent();
unlisteners.push(
await listen(AppEvents.FriendRequestReceived, () => {
await events.friendRequestReceived.listen(() => {
refreshReceived();
}),
);
unlisteners.push(
await listen(AppEvents.FriendRequestAccepted, () => {
await events.friendRequestAccepted.listen(() => {
refreshSent();
invoke("refresh_app_data");
commands.refreshAppData();
}),
);
unlisteners.push(
await listen(AppEvents.FriendRequestDenied, () => {
await events.friendRequestDenied.listen(() => {
refreshSent();
}),
);
unlisteners.push(
await listen(AppEvents.Unfriended, () => {
invoke("refresh_app_data");
await events.unfriended.listen(() => {
commands.refreshAppData();
}),
);
});
@@ -83,7 +84,7 @@
async function refreshReceived() {
loading.received = true;
try {
received = await invoke("received_friend_requests");
received = await commands.receivedFriendRequests();
} catch (e) {
error = (e as Error)?.message ?? String(e);
} finally {
@@ -94,7 +95,7 @@
async function refreshSent() {
loading.sent = true;
try {
sent = await invoke("sent_friend_requests");
sent = await commands.sentFriendRequests();
} catch (e) {
error = (e as Error)?.message ?? String(e);
} finally {
@@ -105,8 +106,8 @@
async function handleAccept(id: string) {
loading.action = true;
try {
await invoke("accept_friend_request", { requestId: id });
await Promise.all([refreshReceived(), invoke("refresh_app_data")]);
await commands.acceptFriendRequest(id);
await Promise.all([refreshReceived(), commands.refreshAppData()]);
} catch (e) {
error = (e as Error)?.message ?? String(e);
} finally {
@@ -117,7 +118,7 @@
async function handleDeny(id: string) {
loading.action = true;
try {
await invoke("deny_friend_request", { requestId: id });
await commands.denyFriendRequest(id);
await refreshReceived();
} catch (e) {
error = (e as Error)?.message ?? String(e);
@@ -129,8 +130,8 @@
async function handleUnfriend(friendId: string) {
loading.action = true;
try {
await invoke("unfriend", { friendId });
await invoke("refresh_app_data");
await commands.unfriend(friendId);
await commands.refreshAppData();
} catch (e) {
error = (e as Error)?.message ?? String(e);
} finally {
@@ -157,9 +158,7 @@
error = null;
try {
const results = await invoke<UserBasicDto[]>("search_users", {
username: sanitizedTerm,
});
const results = await commands.searchUsers(sanitizedTerm);
const match = results.find(
(user) => user.username?.toLowerCase() === normalizedTerm,
);
@@ -181,9 +180,7 @@
async function handleSendRequest(receiverId: string) {
loading.action = true;
try {
await invoke("send_friend_request", {
request: { receiverId },
});
await commands.sendFriendRequest({ receiverId });
await refreshSent();
} catch (e) {
const msg = (e as Error)?.message ?? String(e);

View File

@@ -1,7 +1,6 @@
<script lang="ts">
import { onMount } from "svelte";
import { invoke } from "@tauri-apps/api/core";
import type { ModuleMetadata } from "../../../types/bindings/ModuleMetadata";
import { commands, type ModuleMetadata } from "$lib/bindings";
let modules: ModuleMetadata[] = [];
let loading = false;
@@ -10,7 +9,7 @@
onMount(async () => {
loading = true;
try {
modules = await invoke("get_modules");
modules = await commands.getModules();
} catch (e) {
error = (e as Error)?.message ?? String(e);
} finally {

View File

@@ -1,5 +1,5 @@
<script>
import { invoke } from "@tauri-apps/api/core";
<script lang="ts">
import { commands } from "$lib/bindings";
import { appData } from "../../../events/app-data";
import Power from "../../../assets/icons/power.svelte";
@@ -17,7 +17,7 @@
if (signingOut) return;
signingOut = true;
try {
await invoke("logout_and_restart");
await commands.logoutAndRestart();
} catch (error) {
console.error("Failed to sign out", error);
signingOut = false;
@@ -26,7 +26,7 @@
const openClientConfigManager = async () => {
try {
await invoke("open_client_config_manager");
await commands.openClientConfigManager();
} catch (error) {
console.error("Failed to open client config manager", error);
}
@@ -49,10 +49,10 @@
isChangingPassword = true;
try {
await invoke("change_password", {
currentPassword: passwordForm.currentPassword,
newPassword: passwordForm.newPassword,
});
await commands.changePassword(
passwordForm.currentPassword,
passwordForm.newPassword,
);
passwordSuccess = "Password updated";
passwordForm.currentPassword = "";
passwordForm.newPassword = "";
@@ -131,7 +131,7 @@
<button
class="btn btn-error btn-square btn-soft"
onclick={async () => {
await invoke("quit_app");
await commands.quitApp();
}}
>
<div class="scale-50">

View File

@@ -1,6 +1,5 @@
<script lang="ts">
import type { DollDto } from "../../../../types/bindings/DollDto";
import type { UserProfile } from "../../../../types/bindings/UserProfile";
import type { DollDto, UserProfile } from "$lib/bindings";
import DollPreview from "../../components/doll-preview.svelte";
import PawPrint from "../../../../assets/icons/paw-print.svelte";
import Backpack from "../../../../assets/icons/backpack.svelte";

View File

@@ -1,8 +1,6 @@
<script lang="ts">
import { invoke } from "@tauri-apps/api/core";
import { commands, type DollDto, type UserProfile } from "$lib/bindings";
import { appData } from "../../../../events/app-data";
import type { DollDto } from "../../../../types/bindings/DollDto";
import type { UserProfile } from "../../../../types/bindings/UserProfile";
import DollsList from "./dolls-list.svelte";
let loading = false;
@@ -16,17 +14,17 @@
$: initialLoading = $appData === null;
async function openCreateModal() {
await invoke("open_doll_editor_window", { dollId: null });
await commands.openDollEditorWindow(null);
}
async function openEditModal(doll: DollDto) {
await invoke("open_doll_editor_window", { dollId: doll.id });
await commands.openDollEditorWindow(doll.id);
}
async function handleSetActiveDoll(dollId: string) {
try {
loading = true;
await invoke("set_active_doll", { dollId });
await commands.setActiveDoll(dollId);
// No manual refresh needed - backend will refresh and emit app-data-refreshed
} catch (e) {
error = (e as Error)?.message ?? String(e);
@@ -38,7 +36,7 @@
async function handleRemoveActiveDoll() {
try {
loading = true;
await invoke("remove_active_doll");
await commands.removeActiveDoll();
// No manual refresh needed - backend will refresh and emit app-data-refreshed
} catch (e) {
error = (e as Error)?.message ?? String(e);

View File

@@ -1,10 +1,6 @@
<script lang="ts">
import { onMount } from "svelte";
import { invoke } from "@tauri-apps/api/core";
type AppConfig = {
api_base_url?: string | null;
};
import { commands, type AppConfig } from "$lib/bindings";
let form: AppConfig = {
api_base_url: "",
@@ -17,7 +13,7 @@
const loadConfig = async () => {
try {
const config = (await invoke("get_client_config")) as AppConfig;
const config = await commands.getClientConfig();
form = {
api_base_url: config.api_base_url ?? "",
};
@@ -55,10 +51,8 @@
successMessage = "";
restartError = "";
try {
await invoke("save_client_config", {
config: {
api_base_url: form.api_base_url?.trim() || null,
},
await commands.saveClientConfig({
api_base_url: form.api_base_url?.trim() || null,
});
successMessage = "Success. Restart to apply changes.";
@@ -72,7 +66,7 @@
const restart = async () => {
restartError = "";
try {
await invoke("restart_app");
await commands.restartApp();
} catch (err) {
restartError = `Restart failed: ${err}`;
}

View File

@@ -1,10 +1,12 @@
<script lang="ts">
import { onMount } from "svelte";
import { invoke } from "@tauri-apps/api/core";
import {
commands,
type CreateDollDto,
type DollDto,
type UpdateDollDto,
} from "$lib/bindings";
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
import type { DollDto } from "../../types/bindings/DollDto";
import type { CreateDollDto } from "../../types/bindings/CreateDollDto";
import type { UpdateDollDto } from "../../types/bindings/UpdateDollDto";
import DollPreview from "../app-menu/components/doll-preview.svelte";
let mode: "create" | "edit" = "create";
@@ -35,7 +37,7 @@
async function fetchDoll(id: string) {
loading = true;
try {
const doll: DollDto = await invoke("get_doll", { id });
const doll: DollDto = await commands.getDoll(id);
name = doll.name;
bodyColor = doll.configuration.colorScheme.body;
outlineColor = doll.configuration.colorScheme.outline;
@@ -62,7 +64,7 @@
},
},
};
await invoke("create_doll", { dto });
await commands.createDoll(dto);
} else if (dollId) {
const dto: UpdateDollDto = {
name,
@@ -73,7 +75,7 @@
},
},
};
await invoke("update_doll", { id: dollId, dto });
await commands.updateDoll(dollId, dto);
}
// Close window on success

View File

@@ -1,6 +1,6 @@
<script lang="ts">
import { onMount } from "svelte";
import { invoke } from "@tauri-apps/api/core";
import { commands } from "$lib/bindings";
import { page } from "$app/stores";
let errorMessage = "";
@@ -15,7 +15,7 @@
isRetrying = true;
errorMessage = "";
try {
await invoke("retry_connection");
await commands.retryConnection();
} catch (err) {
errorMessage = `${err}`;
isRetrying = false;
@@ -55,7 +55,7 @@
class="btn btn-outline"
onclick={async () => {
try {
await invoke("open_client_config_manager");
await commands.openClientConfigManager();
} catch (err) {
errorMessage = `Failed to open config manager: ${err}`;
}

View File

@@ -7,7 +7,7 @@
friendsPresenceStates,
currentPresenceState,
} from "../../events/user-status";
import { invoke } from "@tauri-apps/api/core";
import { commands } from "$lib/bindings";
import DebugBar from "./components/debug-bar.svelte";
</script>
@@ -16,10 +16,7 @@
class="absolute inset-0 z-10 size-full"
aria-label="Deactive scene interactive"
onmousedown={async () => {
await invoke("set_scene_interactive", {
interactive: false,
shouldClick: true,
});
await commands.setSceneInteractive(false, true);
}}>&nbsp;</button
>
<div id="debug-bar">

View File

@@ -1,6 +1,5 @@
<script lang="ts">
import type { PresenceStatus } from "../../../types/bindings/PresenceStatus";
import type { UserStatusPayload } from "../../../types/bindings/UserStatusPayload";
import type { PresenceStatus, UserStatusPayload } from "$lib/bindings";
interface Friend {
friend?: {

View File

@@ -1,5 +1,5 @@
<script lang="ts">
import { invoke } from "@tauri-apps/api/core";
import { commands } from "$lib/bindings";
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
import DollPreview from "../app-menu/components/doll-preview.svelte";
import ExternalLink from "../../assets/icons/external-link.svelte";
@@ -31,22 +31,19 @@
errorMessage = "";
try {
if (useRegister) {
await invoke("register", {
email: form.email.trim(),
password: form.password,
name: form.name.trim() || null,
username: form.username.trim() || null,
});
await commands.register(
form.email.trim(),
form.password,
form.name.trim() || null,
form.username.trim() || null,
);
useRegister = false;
resetRegisterFields();
form.password = "";
return;
}
await invoke("login", {
email: form.email.trim(),
password: form.password,
});
await commands.login(form.email.trim(), form.password);
await getCurrentWebviewWindow().close();
} catch (error) {
console.error("Failed to authenticate", error);
@@ -62,7 +59,7 @@
const openClientConfigManager = async () => {
try {
await invoke("open_client_config_manager");
await commands.openClientConfigManager();
} catch (error) {
console.error("Failed to open client config manager", error);
}