migrate from ts-rs to tauri-specta
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
import { writable } from "svelte/store";
|
||||
import { type UserData } from "../types/bindings/UserData";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { AppEvents } from "../types/bindings/AppEventsConstants";
|
||||
import { commands, events, type UserData } from "$lib/bindings";
|
||||
import { createListenerSubscription, setupHmrCleanup } from "./listener-utils";
|
||||
|
||||
export const appData = writable<UserData | null>(null);
|
||||
@@ -16,13 +13,10 @@ const subscription = createListenerSubscription();
|
||||
export async function startAppData() {
|
||||
try {
|
||||
if (subscription.isListening()) return;
|
||||
appData.set(await invoke("get_app_data"));
|
||||
const unlisten = await listen<UserData>(
|
||||
AppEvents.AppDataRefreshed,
|
||||
(event) => {
|
||||
appData.set(event.payload);
|
||||
},
|
||||
);
|
||||
appData.set(await commands.getAppData());
|
||||
const unlisten = await events.appDataRefreshed.listen((event) => {
|
||||
appData.set(event.payload);
|
||||
});
|
||||
subscription.setUnlisten(unlisten);
|
||||
subscription.setListening(true);
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { writable } from "svelte/store";
|
||||
import type { CursorPositions } from "../types/bindings/CursorPositions";
|
||||
import { AppEvents } from "../types/bindings/AppEventsConstants";
|
||||
import { events, type CursorPositions } from "$lib/bindings";
|
||||
import { createListenerSubscription, setupHmrCleanup } from "./listener-utils";
|
||||
|
||||
export const cursorPositionOnScreen = writable<CursorPositions>({
|
||||
@@ -20,12 +17,9 @@ export async function startCursorTracking() {
|
||||
if (subscription.isListening()) return;
|
||||
|
||||
try {
|
||||
const unlisten = await listen<CursorPositions>(
|
||||
AppEvents.CursorPosition,
|
||||
(event) => {
|
||||
cursorPositionOnScreen.set(event.payload);
|
||||
},
|
||||
);
|
||||
const unlisten = await events.cursorMoved.listen((event) => {
|
||||
cursorPositionOnScreen.set(event.payload);
|
||||
});
|
||||
subscription.setUnlisten(unlisten);
|
||||
subscription.setListening(true);
|
||||
} catch (err) {
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { writable } from "svelte/store";
|
||||
import type { CursorPositions } from "../types/bindings/CursorPositions";
|
||||
import type { DollDto } from "../types/bindings/DollDto";
|
||||
import type { FriendDisconnectedPayload } from "../types/bindings/FriendDisconnectedPayload";
|
||||
import type { FriendActiveDollChangedPayload } from "../types/bindings/FriendActiveDollChangedPayload";
|
||||
import { AppEvents } from "../types/bindings/AppEventsConstants";
|
||||
import {
|
||||
events,
|
||||
type CursorPositions,
|
||||
type DollDto,
|
||||
type FriendActiveDollChangedPayload,
|
||||
type FriendDisconnectedPayload,
|
||||
type OutgoingFriendCursorPayload,
|
||||
} from "$lib/bindings";
|
||||
import {
|
||||
createMultiListenerSubscription,
|
||||
removeFromStore,
|
||||
setupHmrCleanup,
|
||||
} from "./listener-utils";
|
||||
|
||||
export type FriendCursorPosition = {
|
||||
userId: string;
|
||||
position: CursorPositions;
|
||||
};
|
||||
|
||||
type FriendCursorData = {
|
||||
position: CursorPositions;
|
||||
lastUpdated: number;
|
||||
@@ -40,10 +37,9 @@ export async function startFriendCursorTracking() {
|
||||
try {
|
||||
// TODO: Add initial sync for existing friends' cursors and dolls if needed
|
||||
|
||||
const unlistenFriendCursor = await listen<FriendCursorPosition>(
|
||||
AppEvents.FriendCursorPosition,
|
||||
const unlistenFriendCursor = await events.friendCursorPositionUpdated.listen(
|
||||
(event) => {
|
||||
const data = event.payload;
|
||||
const data: OutgoingFriendCursorPayload = event.payload;
|
||||
|
||||
friendCursorState[data.userId] = {
|
||||
position: data.position,
|
||||
@@ -60,8 +56,7 @@ export async function startFriendCursorTracking() {
|
||||
);
|
||||
subscription.addUnlisten(unlistenFriendCursor);
|
||||
|
||||
const unlistenFriendDisconnected = await listen<FriendDisconnectedPayload>(
|
||||
AppEvents.FriendDisconnected,
|
||||
const unlistenFriendDisconnected = await events.friendDisconnected.listen(
|
||||
(event) => {
|
||||
const data = event.payload;
|
||||
|
||||
@@ -77,8 +72,7 @@ export async function startFriendCursorTracking() {
|
||||
subscription.addUnlisten(unlistenFriendDisconnected);
|
||||
|
||||
const unlistenFriendActiveDollChanged =
|
||||
await listen<FriendActiveDollChangedPayload>(
|
||||
AppEvents.FriendActiveDollChanged,
|
||||
await events.friendActiveDollChanged.listen(
|
||||
(event) => {
|
||||
const payload = event.payload;
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { writable } from "svelte/store";
|
||||
import type { InteractionPayloadDto } from "../types/bindings/InteractionPayloadDto";
|
||||
import type { InteractionDeliveryFailedDto } from "../types/bindings/InteractionDeliveryFailedDto";
|
||||
import { AppEvents } from "../types/bindings/AppEventsConstants";
|
||||
import {
|
||||
events,
|
||||
type InteractionDeliveryFailedDto,
|
||||
type InteractionPayloadDto,
|
||||
} from "$lib/bindings";
|
||||
import {
|
||||
createMultiListenerSubscription,
|
||||
setupHmrCleanup,
|
||||
@@ -37,16 +38,12 @@ export async function startInteraction() {
|
||||
if (subscription.isListening()) return;
|
||||
|
||||
try {
|
||||
const unlistenReceived = await listen<InteractionPayloadDto>(
|
||||
AppEvents.InteractionReceived,
|
||||
(event) => {
|
||||
addInteraction(event.payload);
|
||||
},
|
||||
);
|
||||
const unlistenReceived = await events.interactionReceived.listen((event) => {
|
||||
addInteraction(event.payload);
|
||||
});
|
||||
subscription.addUnlisten(unlistenReceived);
|
||||
|
||||
const unlistenFailed = await listen<InteractionDeliveryFailedDto>(
|
||||
AppEvents.InteractionDeliveryFailed,
|
||||
const unlistenFailed = await events.interactionDeliveryFailed.listen(
|
||||
(event) => {
|
||||
console.error("Interaction delivery failed:", event.payload);
|
||||
alert(
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { writable } from "svelte/store";
|
||||
import { AppEvents } from "../types/bindings/AppEventsConstants";
|
||||
import { commands, events } from "$lib/bindings";
|
||||
import { createListenerSubscription, setupHmrCleanup } from "./listener-utils";
|
||||
|
||||
export const sceneInteractive = writable<boolean>(false);
|
||||
@@ -16,13 +14,10 @@ export async function startSceneInteractive() {
|
||||
if (subscription.isListening()) return;
|
||||
|
||||
try {
|
||||
sceneInteractive.set(await invoke("get_scene_interactive"));
|
||||
const unlisten = await listen<boolean>(
|
||||
AppEvents.SceneInteractive,
|
||||
(event) => {
|
||||
sceneInteractive.set(Boolean(event.payload));
|
||||
},
|
||||
);
|
||||
sceneInteractive.set(await commands.getSceneInteractive());
|
||||
const unlisten = await events.sceneInteractiveChanged.listen((event) => {
|
||||
sceneInteractive.set(Boolean(event.payload));
|
||||
});
|
||||
subscription.setUnlisten(unlisten);
|
||||
subscription.setListening(true);
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { writable } from "svelte/store";
|
||||
import type { FriendDisconnectedPayload } from "../types/bindings/FriendDisconnectedPayload";
|
||||
import type { FriendUserStatusPayload } from "../types/bindings/FriendUserStatusPayload";
|
||||
import type { UserStatusPayload } from "../types/bindings/UserStatusPayload";
|
||||
import { AppEvents } from "../types/bindings/AppEventsConstants";
|
||||
import {
|
||||
events,
|
||||
type FriendDisconnectedPayload,
|
||||
type UserStatusPayload,
|
||||
} from "$lib/bindings";
|
||||
import {
|
||||
createMultiListenerSubscription,
|
||||
removeFromStore,
|
||||
@@ -24,36 +24,31 @@ export async function startUserStatus() {
|
||||
if (subscription.isListening()) return;
|
||||
|
||||
try {
|
||||
const unlistenStatus = await listen<FriendUserStatusPayload>(
|
||||
AppEvents.FriendUserStatus,
|
||||
(event) => {
|
||||
const { userId, status } = event.payload;
|
||||
const unlistenStatus = await events.friendUserStatusChanged.listen((event) => {
|
||||
const { userId, status } = event.payload;
|
||||
|
||||
const hasValidName =
|
||||
(typeof status.presenceStatus.title === "string" &&
|
||||
status.presenceStatus.title.trim() !== "") ||
|
||||
(typeof status.presenceStatus.subtitle === "string" &&
|
||||
status.presenceStatus.subtitle.trim() !== "");
|
||||
if (!hasValidName) return;
|
||||
const hasValidName =
|
||||
(typeof status.presenceStatus.title === "string" &&
|
||||
status.presenceStatus.title.trim() !== "") ||
|
||||
(typeof status.presenceStatus.subtitle === "string" &&
|
||||
status.presenceStatus.subtitle.trim() !== "");
|
||||
if (!hasValidName) return;
|
||||
|
||||
friendsPresenceStates.update((current) => ({
|
||||
...current,
|
||||
[userId]: status,
|
||||
}));
|
||||
},
|
||||
);
|
||||
friendsPresenceStates.update((current) => ({
|
||||
...current,
|
||||
[userId]: status,
|
||||
}));
|
||||
});
|
||||
subscription.addUnlisten(unlistenStatus);
|
||||
|
||||
const unlistenUserStatusChanged = await listen<UserStatusPayload>(
|
||||
AppEvents.UserStatusChanged,
|
||||
const unlistenUserStatusChanged = await events.userStatusChanged.listen(
|
||||
(event) => {
|
||||
currentPresenceState.set(event.payload);
|
||||
},
|
||||
);
|
||||
subscription.addUnlisten(unlistenUserStatusChanged);
|
||||
|
||||
const unlistenFriendDisconnected = await listen<FriendDisconnectedPayload>(
|
||||
AppEvents.FriendDisconnected,
|
||||
const unlistenFriendDisconnected = await events.friendDisconnected.listen(
|
||||
(event) => {
|
||||
const { userId } = event.payload;
|
||||
friendsPresenceStates.update((current) =>
|
||||
|
||||
Reference in New Issue
Block a user