centralize tauri event names
This commit is contained in:
@@ -2,6 +2,7 @@ import { writable } from "svelte/store";
|
||||
import { type UserData } from "../types/bindings/UserData";
|
||||
import { listen, type UnlistenFn } from "@tauri-apps/api/event";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { AppEvents } from "../types/bindings/AppEventsConstants";
|
||||
|
||||
export let appData = writable<UserData | null>(null);
|
||||
|
||||
@@ -12,7 +13,7 @@ export async function initAppDataListener() {
|
||||
try {
|
||||
if (isListening) return;
|
||||
appData.set(await invoke("get_app_data"));
|
||||
unlisten = await listen<UserData>("app-data-refreshed", (event) => {
|
||||
unlisten = await listen<UserData>(AppEvents.AppDataRefreshed, (event) => {
|
||||
console.log("app-data-refreshed", event.payload);
|
||||
appData.set(event.payload);
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ import { writable } from "svelte/store";
|
||||
import type { CursorPositions } from "../types/bindings/CursorPositions";
|
||||
import type { CursorPosition } from "../types/bindings/CursorPosition";
|
||||
import type { DollDto } from "../types/bindings/DollDto";
|
||||
import { AppEvents } from "../types/bindings/AppEventsConstants";
|
||||
|
||||
export let cursorPositionOnScreen = writable<CursorPositions>({
|
||||
raw: { x: 0, y: 0 },
|
||||
@@ -52,7 +53,7 @@ export async function initCursorTracking() {
|
||||
try {
|
||||
// Listen to cursor position events (each window subscribes independently)
|
||||
unlistenCursor = await listen<CursorPositions>(
|
||||
"cursor-position",
|
||||
AppEvents.CursorPosition,
|
||||
(event) => {
|
||||
cursorPositionOnScreen.set(event.payload);
|
||||
},
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { listen, type UnlistenFn } from "@tauri-apps/api/event";
|
||||
import { writable } from "svelte/store";
|
||||
import { AppEvents } from "../types/bindings/AppEventsConstants";
|
||||
|
||||
export const sceneInteractive = writable<boolean>(false);
|
||||
|
||||
@@ -12,7 +13,7 @@ export async function initSceneInteractiveListener() {
|
||||
try {
|
||||
// ensure initial default matches backend default
|
||||
sceneInteractive.set(false);
|
||||
unlisten = await listen<boolean>("scene-interactive", (event) => {
|
||||
unlisten = await listen<boolean>(AppEvents.SceneInteractive, (event) => {
|
||||
sceneInteractive.set(Boolean(event.payload));
|
||||
});
|
||||
isListening = true;
|
||||
|
||||
Reference in New Issue
Block a user