From 9dbfcd7a1a124eda46c569e565800f04516e461f Mon Sep 17 00:00:00 2001 From: Robert Kossessa Date: Fri, 22 Mar 2024 15:33:30 +0100 Subject: [PATCH] UPD: Display generic messages --- src/renderer/src/App.vue | 8 ++++---- src/renderer/src/deviceStore.ts | 11 +++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/renderer/src/App.vue b/src/renderer/src/App.vue index dcf24ee..078f013 100644 --- a/src/renderer/src/App.vue +++ b/src/renderer/src/App.vue @@ -3,16 +3,16 @@ import ProfileManager from '@renderer/components/profile/ProfileManager.vue' import DevicePreview from '@renderer/components/device/DevicePreview.vue' import ConfigPane from '@renderer/components/config/ConfigPane.vue' import Navbar from '@renderer/components/navbar/Navbar.vue' -import { useDeviceStore, initializeDevices, onDeviceError } from '@renderer/deviceStore' +import { useDeviceStore, initializeDevices, onDeviceMessage } from '@renderer/deviceStore' import { Toaster } from '@renderer/components/ui/sonner' import { toast } from 'vue-sonner' const deviceStore = useDeviceStore() initializeDevices() -onDeviceError((error) => { - toast('Error', { - description: error +onDeviceMessage((title, message) => { + toast(title, { + description: message }) }) diff --git a/src/renderer/src/deviceStore.ts b/src/renderer/src/deviceStore.ts index 665d049..9ab49ed 100644 --- a/src/renderer/src/deviceStore.ts +++ b/src/renderer/src/deviceStore.ts @@ -52,7 +52,7 @@ interface UpdateData { const { nanoIpc } = window -const errorCallbacks: ((error: string) => void)[] = [] +const messageCallbacks: ((title: string, message: string) => void)[] = [] export const useDeviceStore = defineStore('device', { state: () => ({ @@ -284,7 +284,10 @@ export const initializeDevices = () => { nanoIpc.on((eventid, deviceid, dataString) => { console.log('Received event', eventid, deviceid, dataString) if (eventid === 'error') { - errorCallbacks.forEach((callback) => callback(dataString)) + messageCallbacks.forEach((callback) => callback('Error', dataString)) + } + if (eventid === 'saved') { + messageCallbacks.forEach((callback) => callback('Saved', 'Changes saved to device')) } if (eventid === 'device-attached') { deviceStore.attachDevice(deviceid) @@ -353,8 +356,8 @@ export const initializeDevices = () => { }) } -export const onDeviceError = (callback: (error: string) => void) => { - errorCallbacks.push(callback) +export const onDeviceMessage = (callback: (title: string, message: string) => void) => { + messageCallbacks.push(callback) } // // devices, device attachment, connection, and disconnection