Skip to content

Commit

Permalink
Add an entry if empty in SimpleModificationsView
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Dec 3, 2023
1 parent 19994f7 commit bb3ff71
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/apps/SettingsWindow/src/View/SimpleModificationsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions src/apps/share/swift/LibKrbn/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit bb3ff71

Please sign in to comment.