hex/ios/HEXShared/FullKeyboard/FullKeyboardSettings.swift
Ryan Vogel 635a6c5a2e
iOS: add a Haptics switch to the full keyboard (#2030)
A tester asked to turn off typing haptics. Experiments › Full keyboard › Haptics (on by default) now gates the keyboard's allowsHaptics alongside Full Access, so key presses, accent picks and trackpad steps stop tapping when it's off. Typing logs record the setting.

Verified HEXMobileTests on the iPhone 18 Pro simulator and a render of the toggle.
2026-11-20 11:59:34 +00:00

54 lines
2 KiB
Swift

import Foundation
/// The full keyboard's switches in the shared App Group.
///
/// Without Full Access the keyboard cannot read the App Group, so `isEnabled` reads
/// `false` there and the keyboard keeps today's setup card.
@MainActor
struct FullKeyboardSettings {
static let launchArgument = "--experiment-full-keyboard"
private enum Key {
static let fullKeyboard = "experiments.fullKeyboard"
static let autocorrect = "settings.keyboardAutocorrect"
static let keyPopups = "settings.keyboardKeyPopups"
static let haptics = "settings.keyboardHaptics"
}
private let defaults: UserDefaults?
init(defaults: UserDefaults? = UserDefaults(suiteName: KeyboardBridge.appGroup)) {
self.defaults = defaults
}
/// Experiment: Hex shows a full QWERTY keyboard instead of the dictation bar. Off by default.
var isEnabled: Bool {
get { defaults?.bool(forKey: Key.fullKeyboard) ?? false }
nonmutating set { defaults?.set(newValue, forKey: Key.fullKeyboard) }
}
/// Cautious autocorrect on space. On by default.
var autocorrect: Bool {
get { defaults?.object(forKey: Key.autocorrect) as? Bool ?? true }
nonmutating set { defaults?.set(newValue, forKey: Key.autocorrect) }
}
/// The enlarged letter that pops up over a pressed key. On by default.
var keyPopups: Bool {
get { defaults?.object(forKey: Key.keyPopups) as? Bool ?? true }
nonmutating set { defaults?.set(newValue, forKey: Key.keyPopups) }
}
/// A light tap under your finger for each key press. On by default.
var haptics: Bool {
get { defaults?.object(forKey: Key.haptics) as? Bool ?? true }
nonmutating set { defaults?.set(newValue, forKey: Key.haptics) }
}
/// Simulator scenes pass `--experiment-full-keyboard` to turn the experiment on.
func applyLaunchArguments(_ arguments: [String] = ProcessInfo.processInfo.arguments) {
if arguments.contains(Self.launchArgument) {
isEnabled = true
}
}
}