diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte
index 4c2939e..6f1d10d 100644
--- a/frontend/src/App.svelte
+++ b/frontend/src/App.svelte
@@ -9,17 +9,17 @@
import Show from './components/Show/Show.svelte';
import GeneralConsole from './components/Console/GeneralConsole.svelte';
import RoundIconButton from './components/General/RoundIconButton.svelte';
- import { showInformation, needProjectSave, peripherals } from './stores';
+ import { generateToast, showInformation, needProjectSave, peripherals } from './stores';
import { SaveProject } from '../wailsjs/go/main/App.js';
import { construct_svelte_component } from 'svelte/internal';
import { EventsOn } from '../wailsjs/runtime'
import { CreateProject, GetPeripherals } from "../wailsjs/go/main/App";
import { WindowSetTitle } from "../wailsjs/runtime/runtime"
import { get } from "svelte/store"
+ import ToastNotification from './components/General/ToastNotification.svelte';
// Handle the event when a new peripheral is detected
EventsOn('PERIPHERAL_ARRIVAL', function(peripheralInfo){
- console.log("Hardware has been added to the system");
// When a new peripheral is detected, add it to the map and:
// - Pass the isDetected key to true
// - Set the isSaved key to the last value
@@ -31,6 +31,8 @@
peripherals[peripheralInfo.SerialNumber] = peripheralInfo
return {...peripherals}
})
+ console.log("Hardware has been added to the system");
+ generateToast('info', 'bxs-hdd', 'Your ' + peripheralInfo.Name + ' device has been detected')
})
// Handle the event when a peripheral is removed from the system
@@ -49,6 +51,7 @@
storedPeripherals[peripheralInfo.SerialNumber].isDetected = false
return {...storedPeripherals}
})
+ generateToast('warning', 'bxs-hdd', 'Your ' + peripheralInfo.Name + ' device has been removed')
})
// Set the window title
@@ -67,8 +70,10 @@
SaveProject().then((filePath) => {
needProjectSave.set(false)
console.log("Project has been saved to " + filePath)
+ generateToast('info', 'bxs-save', 'The project has been saved')
}).catch((error) => {
console.error(`Unable to save the project: ${error}`)
+ generateToast('danger', 'bx-error', 'Unable to save the project: ' + error)
})
}
@@ -79,8 +84,9 @@
})
// Request the list of peripherals
- // TODO: Handle the error here
- GetPeripherals()
+ GetPeripherals().catch((error) => {
+ generateToast('danger', 'bx-error', 'Unable to get the list of peripherals: ' + error)
+ })
// Handle window shortcuts
document.addEventListener('keydown', function(event) {
@@ -116,6 +122,7 @@
{:else if selectedMenu === "console"}
Others
diff --git a/frontend/src/components/Settings/Settings.svelte b/frontend/src/components/Settings/Settings.svelte index b6f7b86..941be9d 100644 --- a/frontend/src/components/Settings/Settings.svelte +++ b/frontend/src/components/Settings/Settings.svelte @@ -1,5 +1,5 @@ diff --git a/frontend/src/stores.js b/frontend/src/stores.js index 6afbf68..a060938 100644 --- a/frontend/src/stores.js +++ b/frontend/src/stores.js @@ -7,6 +7,16 @@ export let needProjectSave = writable(true) // Show settings export let showInformation = writable({}) +// Toasts notifications +export let messages = writable([]) +export function generateToast(type, icon, text){ + messages.update((value) => { + value.push( { id: Date.now(), type: type, icon: icon, text: text } ) + return value.slice(-5) + }) +} + + // Application colors export const colors = writable({ first: "#1B262C", diff --git a/hardware/MIDIDriver.go b/hardware/MIDIDriver.go index c6c8629..b9e4018 100644 --- a/hardware/MIDIDriver.go +++ b/hardware/MIDIDriver.go @@ -10,25 +10,6 @@ import ( "github.com/mattrtaylor/go-rtmidi" ) -/* - DMXConnect - DMXUSBProtocol.go - - Copyright (c) Valentin Boulanger - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0.txt - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - // MIDIDriver represents how the protocol is defined type MIDIDriver struct { peripherals map[string]Peripheral // The list of peripherals @@ -109,7 +90,8 @@ func (d *MIDIDriver) Scan(ctx context.Context) error { } fmt.Printf("New MIDI device found: %s on %i\n", name, location) // Add the peripheral to the temporary list - midiPeripherals[portName] = NewMIDIPeripheral(name, location) + sn := strings.ToLower(strings.Replace(name, " ", "_", -1)) + midiPeripherals[sn] = NewMIDIPeripheral(name, location, sn) } // Compare with the current peripherals to detect arrivals/removals removedList, addedList := comparePeripherals(d.peripherals, midiPeripherals) diff --git a/hardware/MIDIPeripheral.go b/hardware/MIDIPeripheral.go index a7dd461..8d9e073 100644 --- a/hardware/MIDIPeripheral.go +++ b/hardware/MIDIPeripheral.go @@ -2,15 +2,17 @@ package hardware // MIDIPeripheral contains the data of a MIDI peripheral type MIDIPeripheral struct { - name string // The name of the peripheral - location int // The location of the peripheral + name string // The name of the peripheral + location int // The location of the peripheral + serialNumber string // The S/N of the peripheral } // NewMIDIPeripheral creates a new MIDI peripheral -func NewMIDIPeripheral(name string, location int) *MIDIPeripheral { +func NewMIDIPeripheral(name string, location int, serialNumber string) *MIDIPeripheral { return &MIDIPeripheral{ - name: name, - location: location, + name: name, + location: location, + serialNumber: serialNumber, } } @@ -44,5 +46,6 @@ func (p *MIDIPeripheral) GetInfo() PeripheralInfo { return PeripheralInfo{ Name: p.name, ProtocolName: "MIDI", + SerialNumber: p.serialNumber, } } diff --git a/hardware/OS2LDriver.go b/hardware/OS2LDriver.go index 7ead8f7..b7fc7ea 100644 --- a/hardware/OS2LDriver.go +++ b/hardware/OS2LDriver.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "math/rand" + "strings" ) // OS2LDriver represents how the protocol is defined @@ -27,7 +28,7 @@ func (d *OS2LDriver) Initialize() error { // CreatePeripheral creates a new OS2L peripheral func (d *OS2LDriver) CreatePeripheral(ctx context.Context) (Peripheral, error) { // Create a random serial number for this peripheral - randomSerialNumber := fmt.Sprintf("%08x", rand.Intn(1<<32)) + randomSerialNumber := strings.ToUpper(fmt.Sprintf("%08x", rand.Intn(1<<32))) peripheral := NewOS2LPeripheral("OS2L", randomSerialNumber) d.peripherals[randomSerialNumber] = peripheral return peripheral, nil diff --git a/hardware/hardware.go b/hardware/hardware.go index 6c2ada3..71b63c5 100644 --- a/hardware/hardware.go +++ b/hardware/hardware.go @@ -152,11 +152,11 @@ func (h *HardwareManager) Scan(ctx context.Context) error { return fmt.Errorf("No peripherals driver registered") } for _, driver := range h.drivers { - finder := driver + driverCopy := driver go func() { - err := driver.Scan(ctx) + err := driverCopy.Scan(ctx) if err != nil { - fmt.Printf("Unable to scan peripherals with the %s driver: %s\n", finder.GetName(), err) + fmt.Printf("Unable to scan peripherals with the %s driver: %s\n", driverCopy.GetName(), err) return } }()