UPD: Type update event

This commit is contained in:
Robert Kossessa
2024-03-12 16:13:48 +01:00
parent ebc5ff751c
commit 24ece44191
4 changed files with 33 additions and 21 deletions

View File

@@ -36,6 +36,12 @@ interface Profile {
guiEnable: boolean
}
interface UpdateData {
a: number | undefined
t: number | undefined
v: number | undefined
}
const { nanoIpc } = window
export const useDeviceStore = defineStore('device', {
@@ -118,8 +124,14 @@ export const initializeDevices = () => {
const deviceStore = useDeviceStore()
// register event handlers
nanoIpc.on((eventid, deviceid, ...data) => {
console.log('Received event', eventid, deviceid, data)
nanoIpc.on((eventid, deviceid, dataString) => {
console.log('Received event', eventid, deviceid, dataString)
let update: UpdateData = {} as UpdateData
try {
update = JSON.parse(dataString) as UpdateData
} catch (e) {
console.error(e)
}
if (eventid === 'device-attached') {
deviceStore.attachDevice(deviceid)
if (deviceStore.attachedDeviceIds.length === 1) {
@@ -129,15 +141,15 @@ export const initializeDevices = () => {
if (eventid === 'device-detached') {
deviceStore.detachDevice(deviceid)
}
if (eventid === 'device-connected') {
if (eventid === 'connected') {
deviceStore.connectDevice(deviceid, false)
}
if (eventid === 'device-disconnected') {
if (eventid === 'disconnected') {
deviceStore.disconnectDevice(deviceid, false)
}
if (eventid === 'update') {
if ('a' in data) {
deviceStore.setAngle(data.a as number)
if (update.a) {
deviceStore.setAngle(update.a)
}
}
})