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 DevicePreview from '@renderer/components/device/DevicePreview.vue'
|
||||||
import ConfigPane from '@renderer/components/config/ConfigPane.vue'
|
import ConfigPane from '@renderer/components/config/ConfigPane.vue'
|
||||||
import Navbar from '@renderer/components/navbar/Navbar.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 { Toaster } from '@renderer/components/ui/sonner'
|
||||||
import { toast } from 'vue-sonner'
|
import { toast } from 'vue-sonner'
|
||||||
|
|
||||||
const deviceStore = useDeviceStore()
|
const deviceStore = useDeviceStore()
|
||||||
initializeDevices()
|
initializeDevices()
|
||||||
|
|
||||||
onDeviceError((error) => {
|
onDeviceMessage((title, message) => {
|
||||||
toast('Error', {
|
toast(title, {
|
||||||
description: error
|
description: message
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ interface UpdateData {
|
|||||||
|
|
||||||
const { nanoIpc } = window
|
const { nanoIpc } = window
|
||||||
|
|
||||||
const errorCallbacks: ((error: string) => void)[] = []
|
const messageCallbacks: ((title: string, message: string) => void)[] = []
|
||||||
|
|
||||||
export const useDeviceStore = defineStore('device', {
|
export const useDeviceStore = defineStore('device', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@@ -284,7 +284,10 @@ export const initializeDevices = () => {
|
|||||||
nanoIpc.on((eventid, deviceid, dataString) => {
|
nanoIpc.on((eventid, deviceid, dataString) => {
|
||||||
console.log('Received event', eventid, deviceid, dataString)
|
console.log('Received event', eventid, deviceid, dataString)
|
||||||
if (eventid === 'error') {
|
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') {
|
if (eventid === 'device-attached') {
|
||||||
deviceStore.attachDevice(deviceid)
|
deviceStore.attachDevice(deviceid)
|
||||||
@@ -353,8 +356,8 @@ export const initializeDevices = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const onDeviceError = (callback: (error: string) => void) => {
|
export const onDeviceMessage = (callback: (title: string, message: string) => void) => {
|
||||||
errorCallbacks.push(callback)
|
messageCallbacks.push(callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
// // devices, device attachment, connection, and disconnection
|
// // devices, device attachment, connection, and disconnection
|
||||||
|
|||||||
Reference in New Issue
Block a user