diff --git a/src/apps/SettingsWindow/src/View/SimpleModificationsView.swift b/src/apps/SettingsWindow/src/View/SimpleModificationsView.swift index 367ca10ca..c252b2794 100644 --- a/src/apps/SettingsWindow/src/View/SimpleModificationsView.swift +++ b/src/apps/SettingsWindow/src/View/SimpleModificationsView.swift @@ -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) } } diff --git a/src/apps/share/swift/LibKrbn/Settings.swift b/src/apps/share/swift/LibKrbn/Settings.swift index c2d9c00a7..ef7c00261 100644 --- a/src/apps/share/swift/LibKrbn/Settings.swift +++ b/src/apps/share/swift/LibKrbn/Settings.swift @@ -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?