Skip to content

Commit

Permalink
Add appendSimpleModificationIfEmpty
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Aug 7, 2024
1 parent 682fb5d commit f13e608
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ struct SimpleModificationsView: View {
}
}
.padding()
.onAppear {
settings.appendSimpleModificationIfEmpty(
device: contentViewStates.simpleModificationsViewSelectedDevice)
}
.onChange(of: contentViewStates.simpleModificationsViewSelectedDevice) { newDevice in
// Add an entry if empty.
if settings.simpleModifications(connectedDevice: newDevice).count == 0 {
settings.appendSimpleModification(device: newDevice)
}
settings.appendSimpleModificationIfEmpty(device: newDevice)
}
}

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 @@ -214,6 +214,14 @@ extension LibKrbn {
// Do not to call `save()` here because partial settings will be erased at save.
}

public func appendSimpleModificationIfEmpty(device: ConnectedDevice?) {
let size = libkrbn_core_configuration_get_selected_profile_simple_modifications_size(
device?.libkrbnDeviceIdentifiers)
if size == 0 {
appendSimpleModification(device: device)
}
}

public func removeSimpleModification(
index: Int,
device: ConnectedDevice?
Expand Down

0 comments on commit f13e608

Please sign in to comment.