mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
Ryan approved graduating both full-keyboard experiments. Swipe typing (#2106) and the emoji key and panel (#2051) are on for new users and move out of Experiments. - Defaults: FullKeyboardSettings.emoji and .swipeTyping read experiments.emoji and experiments.swipeTyping as object-or-true (was bool(forKey:), unset meaning off), as spatialAutocorrect did in #2097. Only their Experiments switches ever wrote those keys, and only on a change, so unset means never touched: fresh installs and testers who never touched them get them on, a stored false stays off, a stored true stays on. The keys keep their names; no migration. Without the App Group (no Full Access on an iPhone) both read as on, like the keyboard's other on-by-default switches. --experiment-emoji and --experiment-swipe still turn them on. - Settings › Keyboard: a card under the main one with Swipe typing and Emoji, plus Clear emoji history while Emoji is on. Both keep "Needs the full keyboard" while the Dictation bar is chosen (now from the page's own Full/Dictation bar choice). Settings › Experiments keeps Hinglish and Clean up with Apple Intelligence. No new strings; every string already had zh-Hans. - Record typing logs' session line adds swipeTyping and emoji, beside spatialAutocorrect and cleanupTagger. - settings-<page> scenes write both switches on, as for spatialAutocorrect. Doc comments and README point at Settings › Keyboard. - Test: KeyboardLayoutTests.testSwipeTypingAndEmojiAreOnByDefaultAnd- AStoredOffStaysOff (unset, no App Group, stored off, launch arguments). Held back: Clean up what I say stays off by default. On the held-out generated set its false deletes match the reference (0.5% of words; 3.9% of clean and 2.7% of literal sentences lose a word; 1/43 hand-written clean sentences), and "late" was never deleted (0/247). But it deletes every hyphenated name tried: "Tell Hye-jin I said thanks." became "Tell thanks.", and Jean-Luc, Anne-Marie, Mary-Kate, Ji-woo, Marie-Claire, Smith-Jones and Zeta-Jones all went (P(DELETE) 0.996-1.0), with "follow-up" and "re-entry". It also drops a literal "maybe" ("Call me later, maybe after dinner"). Verified on iPhone 17 simulators (iOS 27.2) on the Mac Studio: - xcodebuild test: 383 tests, 1 skipped (needs HEX_SPEECH_CLIPS), 0 failures. - Swipe on vs off, taps unchanged: the hex-vs-apple held-out sets (2,000 English and 2,000 Spanish sentences) typed through a real KeyboardKeyPlaneView with a temporary, uncommitted harness gave identical output in every sentence and 0 swipes from 116,253 letter touches, for still taps, motion drawn from Record typing logs, every letter dragged 30-95% of a key's pitch, and overlapping (rollover) taps. English WER 5.94%, 79/9,203 correct words broken (still) both ways; Spanish 8.61%, 23/7,978. A control dragging 1.05-1.5 pitches made 7,000/7,000 swipes with it on, 0 off. In the typing logs, 1 of about 1,000 letter touches moved more than a pitch. - Live keyboard in Messages: with no stored keys the emoji key shows and a drag from h to e swipes "He" (strip: Here, Her, He's); with both stored false (an upgrade that turned them off) there's no emoji key and the same drag slides and types "E". - Keyboard memory (Release, Full Access, mock mic, probe transcript, vmmap physical footprint, resident/peak MB, 2 runs each; a temporary, uncommitted probe faked the transcript and headroom): typing, emoji and swipe off 34.0 / 46.1 typing, both on 35.0-39.9 / 47.0-51.8 + in-keyboard dictation, Clean up off 35.0 / 46.6 + dictation, Clean up on 37.6-43.6 / 46.5-51.9 + emoji panel, a few picks 38.3-38.8 / 51.4-52.2 + every emoji category browsed 58.8-59.3 / 68.2-68.3 + all that, then dictation, Clean up 69.2 / 73.7 Typing sets the peak, not the tagger (loaded after recording stops, about 2.6 MB). With a faked 60 MB headroom the 80 MB cleanup guard skipped the tagger and the transcript went in as heard (2/2). The simulator reports no headroom, so #2045's 32 MB start guard can't fire there. On a 4 GB iPhone (reported limits 60-77 MB), browsing every emoji category approaches the limit, and a dictation after it would open Hex instead. Unverified on a device.
297 lines
10 KiB
Swift
297 lines
10 KiB
Swift
import SwiftUI
|
||
|
||
/// The home screen's four settings pages.
|
||
enum SettingsPage: String, Hashable, CaseIterable {
|
||
case dictation
|
||
case keyboard
|
||
case privacy
|
||
case experiments
|
||
|
||
var title: String {
|
||
switch self {
|
||
case .dictation: String(localized: "Dictation")
|
||
case .keyboard: String(localized: "Keyboard")
|
||
case .privacy: String(localized: "Privacy")
|
||
case .experiments: String(localized: "Experiments")
|
||
}
|
||
}
|
||
|
||
var icon: String {
|
||
switch self {
|
||
case .dictation: "waveform"
|
||
case .keyboard: "keyboard"
|
||
case .privacy: "lock"
|
||
case .experiments: "testtube.2"
|
||
}
|
||
}
|
||
}
|
||
|
||
/// A settings page: a short scrolling column of cards under an inline title.
|
||
struct SettingsPageScaffold<Content: View>: View {
|
||
let title: LocalizedStringKey
|
||
@ViewBuilder var content: Content
|
||
|
||
var body: some View {
|
||
ScrollView {
|
||
VStack(alignment: .leading, spacing: 12) {
|
||
content
|
||
}
|
||
.frame(maxWidth: 500)
|
||
.padding(.horizontal, 20)
|
||
.padding(.top, 8)
|
||
.padding(.bottom, 28)
|
||
.frame(maxWidth: .infinity)
|
||
}
|
||
.scrollBounceBehavior(.basedOnSize)
|
||
.scrollDismissesKeyboard(.interactively)
|
||
.defaultScrollAnchor(SettingsSnapshotFixture.scrollsToEnd ? .bottom : .top)
|
||
.background(HexTheme.bgDeep.ignoresSafeArea())
|
||
.navigationTitle(title)
|
||
.navigationBarTitleDisplayMode(.inline)
|
||
.toolbarBackground(HexTheme.bgDeep, for: .navigationBar)
|
||
}
|
||
}
|
||
|
||
/// Rows on `bgBase` with the theme's corner radius.
|
||
struct SettingsCard<Content: View>: View {
|
||
@ViewBuilder var content: Content
|
||
|
||
var body: some View {
|
||
VStack(spacing: 0) {
|
||
content
|
||
}
|
||
.background(
|
||
HexTheme.bgBase,
|
||
in: RoundedRectangle(cornerRadius: HexTheme.cardRadius, style: .continuous)
|
||
)
|
||
}
|
||
}
|
||
|
||
/// A small label above a card, such as Privacy's "Advanced".
|
||
struct SettingsSectionHeader: View {
|
||
let title: LocalizedStringKey
|
||
|
||
var body: some View {
|
||
Text(title)
|
||
.font(.system(size: 13, weight: .medium))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.padding(.leading, 16)
|
||
.padding(.top, 12)
|
||
}
|
||
}
|
||
|
||
struct SettingsDivider: View {
|
||
var leading: CGFloat = 16
|
||
|
||
var body: some View {
|
||
Rectangle()
|
||
.fill(HexTheme.borderWeak)
|
||
.frame(height: 0.5)
|
||
.padding(.leading, leading)
|
||
}
|
||
}
|
||
|
||
/// A row's title, and its one-line description when it has one.
|
||
struct SettingsRowLabel: View {
|
||
let title: String
|
||
var detail: String?
|
||
|
||
var body: some View {
|
||
VStack(alignment: .leading, spacing: 2) {
|
||
Text(title)
|
||
.font(.system(size: 15, weight: .regular))
|
||
.foregroundStyle(HexTheme.textBase)
|
||
if let detail {
|
||
Text(detail)
|
||
.font(.system(size: 12))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// A switch with its one-line description.
|
||
struct SettingsToggleRow: View {
|
||
let title: String
|
||
var detail: String?
|
||
@Binding var isOn: Bool
|
||
|
||
var body: some View {
|
||
Toggle(isOn: $isOn) {
|
||
SettingsRowLabel(title: title, detail: detail)
|
||
}
|
||
.tint(HexTheme.success)
|
||
.padding(.horizontal, 16)
|
||
.padding(.vertical, 10)
|
||
.frame(minHeight: 50)
|
||
}
|
||
}
|
||
|
||
/// A row that opens something: a page (chevron) or another app (arrow).
|
||
struct SettingsLinkLabel: View {
|
||
let title: String
|
||
var icon: String?
|
||
var trailingIcon = "chevron.right"
|
||
|
||
var body: some View {
|
||
HStack(spacing: 12) {
|
||
if let icon {
|
||
Image(systemName: icon)
|
||
.font(.system(size: 15, weight: .regular))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.frame(width: 22)
|
||
}
|
||
Text(title)
|
||
.font(.system(size: 15, weight: .regular))
|
||
.foregroundStyle(HexTheme.textBase)
|
||
Spacer(minLength: 8)
|
||
Image(systemName: trailingIcon)
|
||
.font(.system(size: 13, weight: .medium))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
}
|
||
.padding(.horizontal, 16)
|
||
.frame(minHeight: 50)
|
||
.contentShape(Rectangle())
|
||
}
|
||
}
|
||
|
||
/// A menu's current value with the up-down chevron.
|
||
struct SettingsMenuValue: View {
|
||
let value: String
|
||
|
||
var body: some View {
|
||
HStack(spacing: 5) {
|
||
Text(value)
|
||
.font(.system(size: 15, weight: .regular))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
.lineLimit(1)
|
||
Image(systemName: "chevron.up.chevron.down")
|
||
.font(.system(size: 11, weight: .medium))
|
||
.foregroundStyle(HexTheme.textMuted)
|
||
}
|
||
.padding(.vertical, 6)
|
||
.contentShape(Rectangle())
|
||
}
|
||
}
|
||
|
||
/// A small segmented control in the settings rows' style.
|
||
struct SettingsSegments<Item: Hashable>: View {
|
||
let items: [Item]
|
||
let selected: Item
|
||
let label: KeyPath<Item, String>
|
||
let onSelect: (Item) -> Void
|
||
|
||
var body: some View {
|
||
HStack(spacing: 2) {
|
||
ForEach(items, id: \.self) { item in
|
||
let isSelected = item == selected
|
||
Button {
|
||
onSelect(item)
|
||
} label: {
|
||
Text(item[keyPath: label])
|
||
.font(.system(size: 13, weight: .medium))
|
||
.lineLimit(1)
|
||
.fixedSize(horizontal: true, vertical: false)
|
||
.foregroundStyle(isSelected ? HexTheme.textBase : HexTheme.textMuted)
|
||
.padding(.horizontal, 10)
|
||
.frame(height: 28)
|
||
.background(
|
||
isSelected ? Color.white.opacity(0.14) : Color.clear,
|
||
in: RoundedRectangle(cornerRadius: 7, style: .continuous)
|
||
)
|
||
.contentShape(RoundedRectangle(cornerRadius: 7, style: .continuous))
|
||
}
|
||
.buttonStyle(.plain)
|
||
}
|
||
}
|
||
.fixedSize(horizontal: true, vertical: false)
|
||
.padding(2)
|
||
.background(
|
||
Color.white.opacity(0.055),
|
||
in: RoundedRectangle(cornerRadius: 9, style: .continuous)
|
||
)
|
||
}
|
||
}
|
||
|
||
/// Simulator scenes for the home screen and its pages (`--snap-state <name>`):
|
||
///
|
||
/// - `settings-home`: home, everything ready. `setup`: home, keyboard added but Full Access
|
||
/// not confirmed yet. `setup-sheet`: the same, with the setup sheet open;
|
||
/// `setup-sheet-microphone`: the sheet before iOS has asked for the microphone.
|
||
/// - `settings-<page>` opens a page (`dictation`, `keyboard`, `privacy`, `experiments`) with
|
||
/// every switch at its default; `-on` turns the switches on, `-end` starts scrolled to the end.
|
||
/// `settings-keyboard-languages[-on]` opens Keyboard › Languages.
|
||
/// `settings-privacy-confirm` opens Record typing logs' consent dialog.
|
||
///
|
||
/// `KeyboardSetupMonitor.refresh` and `DictationController` supply the matching state.
|
||
enum SettingsSnapshotFixture {
|
||
static let scene: String? = {
|
||
let args = ProcessInfo.processInfo.arguments
|
||
guard let idx = args.firstIndex(of: "--snap-state"), idx + 1 < args.count else { return nil }
|
||
let value = args[idx + 1]
|
||
return value.hasPrefix("settings-") || value.hasPrefix("setup-sheet") ? value : nil
|
||
}()
|
||
|
||
static var initialPath: [SettingsPage] {
|
||
guard let scene else { return [] }
|
||
let name = scene.dropFirst("settings-".count).split(separator: "-").first.map(String.init)
|
||
return name.flatMap(SettingsPage.init(rawValue:)).map { [$0] } ?? []
|
||
}
|
||
|
||
static var showsSetupSheet: Bool {
|
||
scene?.hasPrefix("setup-sheet") == true
|
||
}
|
||
|
||
/// `settings-privacy-confirm`: Record typing logs' consent dialog, open.
|
||
static var confirmsTypingLogs: Bool {
|
||
scene?.hasSuffix("-confirm") == true
|
||
}
|
||
|
||
static var scrollsToEnd: Bool {
|
||
scene?.hasSuffix("-end") == true
|
||
}
|
||
|
||
/// `settings-keyboard-languages[-on]`: Keyboard › Languages, open (Automatic, or with
|
||
/// `-on` English, Français and Русский with Switch dictation too).
|
||
static var opensKeyboardLanguages: Bool {
|
||
scene?.hasPrefix("settings-keyboard-languages") == true
|
||
}
|
||
|
||
/// Writes the page's switches to the App Group so every run renders the same.
|
||
@MainActor
|
||
static func applyDefaults() {
|
||
guard let scene, scene.hasPrefix("settings-") else { return }
|
||
let on = scene.contains("-on")
|
||
let keyboard = FullKeyboardSettings()
|
||
keyboard.isEnabled = on || opensKeyboardLanguages
|
||
keyboard.autoCapitalization = true
|
||
// `--hex-key left` renders the page with the Hex key on the left.
|
||
let args = ProcessInfo.processInfo.arguments
|
||
keyboard.hexKeyOnLeft = args.firstIndex(of: FullKeyboardSettings.hexKeyLaunchArgument)
|
||
.flatMap { $0 + 1 < args.count ? args[$0 + 1] : nil } == "left"
|
||
keyboard.autocorrect = true
|
||
keyboard.spatialAutocorrect = true
|
||
keyboard.suggestSwearWords = on
|
||
keyboard.keyPopups = true
|
||
keyboard.haptics = true
|
||
keyboard.emoji = true
|
||
keyboard.swipeTyping = true
|
||
let emojiUsage = EmojiUsageStore()
|
||
emojiUsage.clear()
|
||
if on {
|
||
emojiUsage.record("🎉")
|
||
}
|
||
LanguageSettings().keyboardLanguages = on ? [.english, .french, .russian] : []
|
||
LanguageSettings().currentKeyboardLanguage = nil
|
||
LanguageSettings().dictationFollowsKeyboard = on
|
||
CleanupTaggerSettings().isEnabled = on
|
||
AppleIntelligenceCleanupSettings().isEnabled = false
|
||
CustomVocabularySettings().isEnabled = on
|
||
CustomVocabularySettings().terms = on ? ["OpenCode", "SwiftUI", "TestFlight"] : []
|
||
DictationTranslationSettings().isEnabled = on
|
||
DictationTranslationSettings().targetLanguage = "ja"
|
||
TypingJournalSettings().isEnabled = on
|
||
TypingLogSettings().isEnabled = on
|
||
HinglishSettings().isEnabled = on
|
||
}
|
||
}
|