mirror of
https://github.com/seemoo-lab/openhaystack.git
synced 2026-03-27 13:26:50 +00:00
Supporting ESP32 as tags for OpenHaystack (#19)
* Moving microbit firmware to a subfolder in /Firmware to prepare integration of ESP32 * Add firmware for ESP32 and update workflows * Integrated ESP32 firmware from @fhessel to OpenHaystack App Co-authored-by: Frank Hessel <fhessel@seemoo.tu-darmstadt.de>
This commit is contained in:
committed by
GitHub
parent
f88663f5e7
commit
898563ca0b
@@ -6,14 +6,22 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
class AccessoryController: ObservableObject {
|
||||
static let shared = AccessoryController()
|
||||
|
||||
@Published var accessories: [Accessory]
|
||||
|
||||
var accessoryObserver: AnyCancellable?
|
||||
|
||||
init() {
|
||||
self.accessories = KeychainController.loadAccessoriesFromKeychain()
|
||||
self.accessoryObserver = self.accessories.publisher
|
||||
.sink { _ in
|
||||
try? self.save()
|
||||
}
|
||||
}
|
||||
|
||||
init(accessories: [Accessory]) {
|
||||
@@ -46,4 +54,30 @@ class AccessoryController: ObservableObject {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func delete(accessory: Accessory) throws {
|
||||
var accessories = self.accessories
|
||||
guard let idx = accessories.firstIndex(of: accessory) else { return }
|
||||
|
||||
accessories.remove(at: idx)
|
||||
|
||||
withAnimation {
|
||||
self.accessories = accessories
|
||||
}
|
||||
try self.save()
|
||||
}
|
||||
|
||||
func addAccessory(with name: String, color: Color, icon: String) throws -> Accessory {
|
||||
let accessory = try Accessory(name: name, color: color, iconName: icon)
|
||||
|
||||
let accessories = self.accessories + [accessory]
|
||||
|
||||
withAnimation {
|
||||
self.accessories = accessories
|
||||
}
|
||||
|
||||
try self.save()
|
||||
|
||||
return accessory
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user