Skip to content

Commit

Permalink
Add "Open System Settings > Function Keys..." button
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Oct 7, 2024
1 parent 1bbe0ea commit fb2046f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
11 changes: 1 addition & 10 deletions src/apps/SettingsWindow/src/SystemPreferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,5 @@ final class SystemPreferences: ObservableObject {
didSetEnabled = true
}

@Published var useFkeysAsStandardFunctionKeys: Bool = false {
didSet {
if didSetEnabled {
var domain =
UserDefaults.standard.persistentDomain(forName: UserDefaults.globalDomain) ?? [:]
domain["com.apple.keyboard.fnState"] = useFkeysAsStandardFunctionKeys
UserDefaults.standard.setPersistentDomain(domain, forName: UserDefaults.globalDomain)
}
}
}
@Published var useFkeysAsStandardFunctionKeys: Bool = false
}
34 changes: 29 additions & 5 deletions src/apps/SettingsWindow/src/View/FunctionKeysView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,36 @@ struct FunctionKeysView: View {
}
}

HStack {
Toggle(isOn: $systemPreferences.useFkeysAsStandardFunctionKeys) {
Text("Use all F1, F2, etc. keys as standard function keys")
}.switchToggleStyle()
VStack(alignment: .leading) {
// When using Apple's Vendor ID and Product ID with the virtual keyboard,
// useFkeysAsStandardFunctionKeys needs to be changed through the System Settings; otherwise,
// the setting will not be applied correctly.
// Therefore, instead of changing it directly here, providing a button to open the System Settings.

Spacer()
HStack {
Text("Use all F1, F2, etc. keys as standard function keys:")

if systemPreferences.useFkeysAsStandardFunctionKeys {
Text("On").foregroundColor(.accentColor).bold()
} else {
Text("Off")
}
}

Button(
action: {
if let url = URL(
string: "x-apple.systempreferences:com.apple.Keyboard-Settings.extension?FunctionKeys"
) {
NSWorkspace.shared.open(url)
}
},
label: {
Label(
"Open System Settings > Function Keys...",
systemImage: "arrow.up.forward.app")
}
)
}
}
.padding()
Expand Down

0 comments on commit fb2046f

Please sign in to comment.