From db82b1e8fbabc34db728a499c68f7d46a480066c Mon Sep 17 00:00:00 2001 From: Youwen Wu Date: Fri, 1 Mar 2024 18:53:22 -0800 Subject: [PATCH] fix: patch bug setting connected state to wrong value --- client/src/lib/utils/initializeTelemetry.ts | 44 ++++++++++----------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/client/src/lib/utils/initializeTelemetry.ts b/client/src/lib/utils/initializeTelemetry.ts index 0d3839b..c5a9e87 100644 --- a/client/src/lib/utils/initializeTelemetry.ts +++ b/client/src/lib/utils/initializeTelemetry.ts @@ -1,6 +1,6 @@ -import { get } from 'svelte/store' -import { telemetryStore } from '../stores/telemetryStore' -import { emit, listen } from '@tauri-apps/api/event' +import { get } from "svelte/store"; +import { telemetryStore } from "../stores/telemetryStore"; +import { emit, listen } from "@tauri-apps/api/event"; /** * Connects to sockets and subscribes to specified topics to receive telemetry data. @@ -11,9 +11,9 @@ import { emit, listen } from '@tauri-apps/api/event' */ const onUpdate = (data: TelemetryData) => { - telemetryStore.update(data) + telemetryStore.update(data); // console.log(data) -} +}; export const initializeTelemetry = async ( topics: TelemetryTopics, @@ -22,28 +22,28 @@ export const initializeTelemetry = async ( // Make sure refreshRate is valid if (!Number.isInteger(refreshRate) || refreshRate < 1) { throw new Error( - 'refreshRate must be an integer greater than or equal to 1.' - ) + "refreshRate must be an integer greater than or equal to 1." + ); } - const unlistenStatus = await listen('telemetry_status', event => { - if (event.payload === 'connected') { - telemetryStore.set('connected', false) - } else if (event.payload === 'disconnected') { - telemetryStore.set('connected', false) + const unlistenStatus = await listen("telemetry_status", (event) => { + if (event.payload === "connected") { + telemetryStore.set("connected", true); + } else if (event.payload === "disconnected") { + telemetryStore.set("connected", false); } - }) + }); - const unlistenTelemetry = await listen('telemetry_data', event => { - const data = JSON.parse(event.payload as string) + const unlistenTelemetry = await listen("telemetry_data", (event) => { + const data = JSON.parse(event.payload as string); // console.log(JSON.parse) - telemetryStore.set(data['topic_name'], data['data']) - }) + telemetryStore.set(data["topic_name"], data["data"]); + }); const unlistenAll = () => { - unlistenStatus() - unlistenTelemetry() - } + unlistenStatus(); + unlistenTelemetry(); + }; - return unlistenAll -} + return unlistenAll; +};