fix project life and plug-and-replay on peripherals

This commit is contained in:
2025-11-11 20:13:27 +01:00
parent 621c1922ca
commit b094019ed9
12 changed files with 326 additions and 262 deletions

View File

@@ -65,21 +65,21 @@ func (a *App) UpdatePeripheralSettings(protocolName, peripheralID string, settin
}
// RemovePeripheral removes a peripheral from the project
func (a *App) RemovePeripheral(protocolName string, peripheralID string) error {
func (a *App) RemovePeripheral(peripheralData hardware.PeripheralInfo) error {
// Unregister the peripheral from the finder
f, err := a.hardwareManager.GetFinder(protocolName)
f, err := a.hardwareManager.GetFinder(peripheralData.ProtocolName)
if err != nil {
log.Err(err).Str("file", "peripherals").Str("protocolName", protocolName).Msg("unable to find the finder")
log.Err(err).Str("file", "peripherals").Str("protocolName", peripheralData.ProtocolName).Msg("unable to find the finder")
return fmt.Errorf("unable to find the finder")
}
err = f.UnregisterPeripheral(a.ctx, peripheralID)
err = f.UnregisterPeripheral(a.ctx, peripheralData)
if err != nil {
log.Err(err).Str("file", "peripherals").Str("peripheralID", peripheralID).Msg("unable to unregister this peripheral")
log.Err(err).Str("file", "peripherals").Str("peripheralID", peripheralData.SerialNumber).Msg("unable to unregister this peripheral")
return fmt.Errorf("unable to unregister this peripheral")
}
// Remove the peripheral ID from the project
delete(a.projectInfo.PeripheralsInfo, peripheralID)
log.Info().Str("file", "peripheral").Str("protocolName", protocolName).Str("periphID", peripheralID).Msg("peripheral removed from project")
delete(a.projectInfo.PeripheralsInfo, peripheralData.SerialNumber)
log.Info().Str("file", "peripheral").Str("protocolName", peripheralData.ProtocolName).Str("periphID", peripheralData.SerialNumber).Msg("peripheral removed from project")
return nil
}