refactored svelte tauri events
This commit is contained in:
@@ -1,24 +1,29 @@
|
||||
<script>
|
||||
import { browser } from "$app/environment";
|
||||
import { onMount, onDestroy } from "svelte";
|
||||
import { initCursorTracking, stopCursorTracking } from "../events/cursor";
|
||||
import { initAppDataListener } from "../events/app-data";
|
||||
import { initInteractionListeners, stopInteractionListeners } from "../events/interaction";
|
||||
import { startCursorTracking, stopCursorTracking } from "../events/cursor";
|
||||
import {
|
||||
initSceneInteractiveListener,
|
||||
stopSceneInteractiveListener,
|
||||
startFriendCursorTracking,
|
||||
stopFriendCursorTracking,
|
||||
} from "../events/friend-cursor";
|
||||
import { startAppData } from "../events/app-data";
|
||||
import { startInteraction, stopInteraction } from "../events/interaction";
|
||||
import {
|
||||
startSceneInteractive,
|
||||
stopSceneInteractive,
|
||||
} from "../events/scene-interactive";
|
||||
import { initUserStatusListeners, stopUserStatusListeners } from "../events/user-status";
|
||||
import { startUserStatus, stopUserStatus } from "../events/user-status";
|
||||
|
||||
let { children } = $props();
|
||||
if (browser) {
|
||||
onMount(async () => {
|
||||
try {
|
||||
await initCursorTracking();
|
||||
await initAppDataListener();
|
||||
await initSceneInteractiveListener();
|
||||
await initInteractionListeners();
|
||||
await initUserStatusListeners();
|
||||
await startAppData();
|
||||
await startCursorTracking();
|
||||
await startFriendCursorTracking();
|
||||
await startSceneInteractive();
|
||||
await startInteraction();
|
||||
await startUserStatus();
|
||||
} catch (err) {
|
||||
console.error("Failed to initialize event listeners:", err);
|
||||
}
|
||||
@@ -26,9 +31,10 @@
|
||||
|
||||
onDestroy(() => {
|
||||
stopCursorTracking();
|
||||
stopSceneInteractiveListener();
|
||||
stopInteractionListeners();
|
||||
stopUserStatusListeners();
|
||||
stopFriendCursorTracking();
|
||||
stopSceneInteractive();
|
||||
stopInteraction();
|
||||
stopUserStatus();
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
cursorPositionOnScreen,
|
||||
friendsCursorPositions,
|
||||
} from "../../events/cursor";
|
||||
import { cursorPositionOnScreen } from "../../events/cursor";
|
||||
import { friendsCursorPositions } from "../../events/friend-cursor";
|
||||
import { appData } from "../../events/app-data";
|
||||
import { sceneInteractive } from "../../events/scene-interactive";
|
||||
import {
|
||||
friendsUserStatuses,
|
||||
currentUserStatus,
|
||||
friendsPresenceStates,
|
||||
currentPresenceState,
|
||||
} from "../../events/user-status";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import DebugBar from "./components/debug-bar.svelte";
|
||||
@@ -28,10 +26,10 @@
|
||||
<DebugBar
|
||||
isInteractive={$sceneInteractive}
|
||||
cursorPosition={$cursorPositionOnScreen}
|
||||
presenceStatus={$currentUserStatus?.presenceStatus ?? null}
|
||||
presenceStatus={$currentPresenceState?.presenceStatus ?? null}
|
||||
friendsCursorPositions={$friendsCursorPositions}
|
||||
friends={$appData?.friends ?? []}
|
||||
friendsUserStatuses={$friendsUserStatuses}
|
||||
friendsPresenceStates={$friendsPresenceStates}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import type { PresenceStatus } from "../../../types/bindings/PresenceStatus";
|
||||
import type { UserStatus } from "../../../events/user-status";
|
||||
import type { PresenceState } from "../../../events/user-status";
|
||||
|
||||
interface Friend {
|
||||
friend?: {
|
||||
@@ -15,7 +15,7 @@
|
||||
presenceStatus: PresenceStatus | null;
|
||||
friendsCursorPositions: Record<string, { mapped: { x: number; y: number } }>;
|
||||
friends: Friend[];
|
||||
friendsUserStatuses: Record<string, UserStatus>;
|
||||
friendsPresenceStates: Record<string, PresenceState>;
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -24,7 +24,7 @@
|
||||
presenceStatus,
|
||||
friendsCursorPositions,
|
||||
friends,
|
||||
friendsUserStatuses,
|
||||
friendsPresenceStates,
|
||||
}: Props = $props();
|
||||
|
||||
function getFriendById(userId: string) {
|
||||
@@ -33,7 +33,7 @@
|
||||
}
|
||||
|
||||
function getFriendStatus(userId: string) {
|
||||
return friendsUserStatuses[userId];
|
||||
return friendsPresenceStates[userId];
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user