diff --git a/src/apps/SettingsWindow/src/View/SimpleModificationsView.swift b/src/apps/SettingsWindow/src/View/SimpleModificationsView.swift index 29a0c0f40..5998ee596 100644 --- a/src/apps/SettingsWindow/src/View/SimpleModificationsView.swift +++ b/src/apps/SettingsWindow/src/View/SimpleModificationsView.swift @@ -20,6 +20,12 @@ struct SimpleModificationsView: View { } } .padding() + .onChange(of: contentViewStates.simpleModificationsViewSelectedDevice) { newDevice in + // Add an entry if empty. + if settings.simpleModifications(connectedDevice: newDevice).count == 0 { + settings.appendSimpleModification(device: newDevice) + } + } } struct SimpleModificationView: View { @@ -30,11 +36,8 @@ struct SimpleModificationsView: View { init(selectedDevice: LibKrbn.ConnectedDevice?) { self.selectedDevice = selectedDevice - self.simpleModifications = - selectedDevice == nil - ? LibKrbn.Settings.shared.simpleModifications - : LibKrbn.Settings.shared.findConnectedDeviceSetting(selectedDevice!)?.simpleModifications - ?? [] + self.simpleModifications = LibKrbn.Settings.shared.simpleModifications( + connectedDevice: selectedDevice) } var body: some View { diff --git a/src/apps/share/swift/LibKrbn/Settings.swift b/src/apps/share/swift/LibKrbn/Settings.swift index 9e295358c..caa317e5d 100644 --- a/src/apps/share/swift/LibKrbn/Settings.swift +++ b/src/apps/share/swift/LibKrbn/Settings.swift @@ -176,6 +176,14 @@ extension LibKrbn { return result } + public func simpleModifications(connectedDevice: ConnectedDevice?) -> [SimpleModification] { + if let connectedDevice = connectedDevice { + return findConnectedDeviceSetting(connectedDevice)?.simpleModifications ?? [] + } else { + return simpleModifications + } + } + public func updateSimpleModification( index: Int, fromJsonString: String,