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;
|
||||
|
||||
3
src/types/bindings/AppEvents.ts
Normal file
3
src/types/bindings/AppEvents.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
||||
|
||||
export type AppEvents = "cursor-position" | "scene-interactive" | "app-data-refreshed" | "set-interaction-overlay" | "edit-doll" | "create-doll" | "user-status-changed";
|
||||
14
src/types/bindings/AppEventsConstants.ts
Normal file
14
src/types/bindings/AppEventsConstants.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
// Auto-generated constants - DO NOT EDIT
|
||||
// Generated from Rust AppEvents enum
|
||||
|
||||
export const AppEvents = {
|
||||
CursorPosition: "cursor-position",
|
||||
SceneInteractive: "scene-interactive",
|
||||
AppDataRefreshed: "app-data-refreshed",
|
||||
SetInteractionOverlay: "set-interaction-overlay",
|
||||
EditDoll: "edit-doll",
|
||||
CreateDoll: "create-doll",
|
||||
UserStatusChanged: "user-status-changed",
|
||||
} as const;
|
||||
|
||||
export type AppEvents = typeof AppEvents[keyof typeof AppEvents];
|
||||
Reference in New Issue
Block a user