UPD: Display generic messages
This commit is contained in:
@@ -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
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user