Skip to content

Commit

Permalink
Add reflect* into Settings.swift
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Jun 23, 2024
1 parent 94529d4 commit cc4f1de
Showing 1 changed file with 71 additions and 2 deletions.
73 changes: 71 additions & 2 deletions src/apps/share/swift/LibKrbn/Settings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ extension LibKrbn {
fnFunctionKeys = makeFnFunctionKeys(nil)

updateComplexModificationsRules()

complexModificationsParameterToIfAloneTimeoutMilliseconds = Int(
libkrbn_core_configuration_get_selected_profile_complex_modifications_parameter(
"basic.to_if_alone_timeout_milliseconds"
Expand All @@ -99,6 +100,7 @@ extension LibKrbn {
))

updateConnectedDeviceSettings()

delayMillisecondsBeforeOpenDevice = Int(
libkrbn_core_configuration_get_selected_profile_parameters_delay_milliseconds_before_open_device()
)
Expand Down Expand Up @@ -183,6 +185,14 @@ extension LibKrbn {
}
}

private func reflectSimpleModificationChanges(_ connectedDevice: ConnectedDevice?) {
if connectedDevice == nil {
simpleModifications = makeSimpleModifications(nil)
} else {
updateConnectedDeviceSettings()
}
}

public func updateSimpleModification(
index: Int,
fromJsonString: String,
Expand All @@ -195,15 +205,18 @@ extension LibKrbn {
toJsonString.cString(using: .utf8),
device?.libkrbnDeviceIdentifiers)

reflectSimpleModificationChanges(device)

save()
}

public func appendSimpleModification(device: ConnectedDevice?) {
libkrbn_core_configuration_push_back_selected_profile_simple_modification(
device?.libkrbnDeviceIdentifiers)

reflectSimpleModificationChanges(device)

// Do not to call `save()` here because partial settings will be erased at save.
updateProperties()
}

public func appendSimpleModification(
Expand Down Expand Up @@ -231,8 +244,9 @@ extension LibKrbn {
toJsonString.cString(using: .utf8),
device?.libkrbnDeviceIdentifiers)

reflectSimpleModificationChanges(device)

// Do not to call `save()` here because partial settings will be erased at save.
updateProperties()
}
}
}
Expand All @@ -245,6 +259,8 @@ extension LibKrbn {
index,
device?.libkrbnDeviceIdentifiers)

reflectSimpleModificationChanges(device)

save()
}

Expand Down Expand Up @@ -294,6 +310,14 @@ extension LibKrbn {
return result
}

private func reflectFnFunctionKeyChanges(_ connectedDevice: ConnectedDevice?) {
if connectedDevice == nil {
fnFunctionKeys = makeFnFunctionKeys(nil)
} else {
updateConnectedDeviceSettings()
}
}

public func updateFnFunctionKey(
fromJsonString: String,
toJsonString: String,
Expand All @@ -304,6 +328,8 @@ extension LibKrbn {
toJsonString.cString(using: .utf8),
device?.libkrbnDeviceIdentifiers)

reflectFnFunctionKeyChanges(device)

save()
}

Expand Down Expand Up @@ -344,6 +370,10 @@ extension LibKrbn {
complexModificationsRules = newComplexModificationsRules
}

private func reflectComplexModificationsRuleChanges() {
updateComplexModificationsRules()
}

public func replaceComplexModificationsRule(
_ complexModificationRule: ComplexModificationsRule,
_ jsonString: String
Expand All @@ -361,6 +391,8 @@ extension LibKrbn {
return errorMessage
}

reflectComplexModificationsRuleChanges()

save()
return nil
}
Expand All @@ -380,6 +412,8 @@ extension LibKrbn {
return errorMessage
}

reflectComplexModificationsRuleChanges()

save()
return nil
}
Expand All @@ -389,6 +423,9 @@ extension LibKrbn {
sourceIndex,
destinationIndex
)

reflectComplexModificationsRuleChanges()

save()
}

Expand All @@ -397,6 +434,9 @@ extension LibKrbn {
libkrbn_core_configuration_erase_selected_profile_complex_modifications_rule(
complexModificationRule.index
)

reflectComplexModificationsRuleChanges()

save()
}

Expand All @@ -407,6 +447,9 @@ extension LibKrbn {
libkrbn_complex_modifications_assets_manager_add_rule_to_core_configuration_selected_profile(
rule.fileIndex, rule.ruleIndex)
}

reflectComplexModificationsRuleChanges()

save()
}

Expand All @@ -415,6 +458,9 @@ extension LibKrbn {
) {
libkrbn_complex_modifications_assets_manager_add_rule_to_core_configuration_selected_profile(
complexModificationsAssetRule.fileIndex, complexModificationsAssetRule.ruleIndex)

reflectComplexModificationsRuleChanges()

save()
}

Expand Down Expand Up @@ -577,25 +623,42 @@ extension LibKrbn {
profiles = newProfiles
}

private func reflectProfileChanges() {
updateProfiles()
}

public func selectProfile(_ profile: Profile) {
libkrbn_core_configuration_select_profile(profile.index)

// To update all settings to the new profile’s contents, it is necessary to call `updateProperties`.
updateProperties()

save()
}

public func updateProfileName(_ profile: Profile, _ name: String) {
libkrbn_core_configuration_set_profile_name(
profile.index, name.cString(using: .utf8)
)

reflectProfileChanges()

save()
}

public func appendProfile() {
libkrbn_core_configuration_push_back_profile()

reflectProfileChanges()

save()
}

public func duplicateProfile(_ profile: Profile) {
libkrbn_core_configuration_duplicate_profile(profile.index)

reflectProfileChanges()

save()
}

Expand All @@ -604,11 +667,17 @@ extension LibKrbn {
sourceIndex,
destinationIndex
)

reflectProfileChanges()

save()
}

public func removeProfile(_ profile: Profile) {
libkrbn_core_configuration_erase_profile(profile.index)

reflectProfileChanges()

save()
}

Expand Down

0 comments on commit cc4f1de

Please sign in to comment.