mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
Step 5 of the phone side (design §7), behind Settings › Experiments › Typing configs. - Counts (HEXShared/TypingLog/TypingConfigHealth.swift): per config and for Hex defaults, words finished, autocorrections, undone, kept as typed, fixed by hand, suggestions picked, from two hooks in Learn how I type's journal (TypingJournal.didFinish and record); no words kept. - Comparison: Apply records the config in use before it. "Seems worse" only with 400 words on each side, twice the trouble rate and at least 8 troubles. Best so far marks the lowest rate once two configs have 400 words. - Telling the person, at most once per config and never after Go back, Keep this one or Turn typing configs off: the keyboard's bar notice (Open Hex, ✕ for good; FullKeyboardView+TypingConfigNotice, a few one-line hooks in FullKeyboardView), then a quiet notification from the keyboard a day later if the notice wasn't acted on, and a Home card. Settings › Keyboard › Typing configs gains Alerts (off: no bar notice, no notification) and Compare with the one before. - The comparison sheet (hex-dictation://typing-configs/compare, from the notice, the notification or the card): each side's rate, words and counts; Go back, Keep this one, Turn typing configs off. - Notification permission asked on the applied sheet, the first time a config is applied, with the reason and Hex's own buttons before the system's prompt. - Start-up fallback (TypingConfigStartupGuard): the keyboard marks a start in viewDidLoad and clears it in viewDidAppear; after two starts that never came up it starts without the config, and the app goes back to the one before and says so on Home. - Review wording no longer promises a tap: zones "count for the key more often", the next-letter guess "can still pick its neighbour"; each zone says how far its touch area reaches. - Strings in English and Simplified Chinese; docs/typing-configs.md and the feature map. Verified on the Studio (iOS 27.2): TypingLogTests 17 of 17 (the comparison rule, the start-up guard); every state on iPhone 17 Pro and iPhone SE in English and 简体中文 with seeded counts (420 words, 30 troubles against 460 and 12), a backdated bar notice and a seeded start mark; the notification shown as a banner over Files and on the lock screen; code-shape.py --check.
110 lines
5.1 KiB
Swift
110 lines
5.1 KiB
Swift
import SwiftUI
|
||
import UIKit
|
||
import UserNotifications
|
||
|
||
@main
|
||
struct HEXMobileApp: App {
|
||
@Environment(\.scenePhase) private var scenePhase
|
||
@State private var dictation = DictationController.shared
|
||
@State private var openedFromKeyboard = Self.initialOpenedFromKeyboard
|
||
@State private var showSetup = SettingsSnapshotFixture.showsSetupSheet
|
||
@State private var openPage: SettingsPage?
|
||
@State private var typingConfigs = TypingConfigInbox.shared
|
||
|
||
init() {
|
||
FullKeyboardSettings().applyLaunchArguments()
|
||
TypingLogSettings().turnOffOnce()
|
||
TypingLogSettings().applyLaunchArguments()
|
||
HinglishSettings().applyLaunchArguments()
|
||
GreeklishSettings().applyLaunchArguments()
|
||
TwoLanguageDictationSettings().applyLaunchArguments()
|
||
VoiceIsolationSettings().applyLaunchArguments()
|
||
MultilingualParakeetSettings().applyLaunchArguments()
|
||
KeyboardParakeetSettings().applyLaunchArguments()
|
||
SettingsSnapshotFixture.applyDefaults()
|
||
UNUserNotificationCenter.current().delegate = TypingConfigNotificationDelegate.shared
|
||
}
|
||
|
||
private static var initialOpenedFromKeyboard: Bool {
|
||
let args = ProcessInfo.processInfo.arguments
|
||
guard let idx = args.firstIndex(of: "--snap-state"), idx + 1 < args.count else {
|
||
return false
|
||
}
|
||
return args[idx + 1].hasPrefix("handoff-")
|
||
}
|
||
|
||
var body: some Scene {
|
||
WindowGroup {
|
||
if ProcessInfo.processInfo.environment["XCTestConfigurationFilePath"] != nil {
|
||
Color.clear
|
||
} else if let keyboardScene = KeyboardSnapshotStage.requestedScene {
|
||
KeyboardSnapshotStage(scene: keyboardScene)
|
||
} else if let fullKeyboardScene = FullKeyboardSnapshotStage.requestedScene {
|
||
FullKeyboardSnapshotStage(scene: fullKeyboardScene)
|
||
} else if let experimentsScene = ExperimentsSnapshotStage.requestedScene {
|
||
ExperimentsSnapshotStage(scene: experimentsScene)
|
||
} else if let hostedScene = HostedKeyboardConversationStage.requestedScene {
|
||
HostedKeyboardConversationStage(scene: hostedScene, dictation: dictation)
|
||
} else {
|
||
ContentView(
|
||
dictation: dictation,
|
||
openedFromKeyboard: $openedFromKeyboard,
|
||
showSetup: $showSetup,
|
||
openPage: $openPage
|
||
)
|
||
.onOpenURL { url in
|
||
// A typing config (`.mhexconfig`) from Files or a share sheet: its own sheet.
|
||
if TypingConfigInbox.handles(url) {
|
||
openedFromKeyboard = false
|
||
typingConfigs.receive(url)
|
||
return
|
||
}
|
||
// The keyboard's notice that typing may be worse: the comparison.
|
||
if TypingConfigWatch.handles(url) {
|
||
openedFromKeyboard = false
|
||
TypingConfigWatch.shared.openCompare()
|
||
return
|
||
}
|
||
guard let request = KeyboardLaunchRequest(url: url) else { return }
|
||
if case .setup = request {
|
||
openedFromKeyboard = false
|
||
showSetup = true
|
||
} else if case .translationSettings = request {
|
||
openedFromKeyboard = false
|
||
openPage = .dictation
|
||
} else if case .pasteSettings = request {
|
||
openedFromKeyboard = false
|
||
openPage = .keyboard
|
||
if let settingsURL = URL(string: UIApplication.openSettingsURLString) {
|
||
UIApplication.shared.open(settingsURL)
|
||
}
|
||
} else {
|
||
openedFromKeyboard = true
|
||
}
|
||
dictation.handleKeyboardLaunch(request)
|
||
}
|
||
.onChange(of: scenePhase) { _, phase in
|
||
if phase == .background {
|
||
openedFromKeyboard = false
|
||
dictation.appMovedToBackground()
|
||
} else if phase == .active {
|
||
dictation.endStaleLiveActivities()
|
||
dictation.appBecameActive()
|
||
// Settings › Dictation › Speech model in keyboard: picks its download up.
|
||
dictation.startKeyboardParakeetDownloadIfWanted()
|
||
// Typing configs: a keyboard first used since the config was applied.
|
||
if TypingConfigSettings().isEnabled {
|
||
TypingConfigActivation.refreshActive()
|
||
TypingConfigWatch.shared.refresh()
|
||
}
|
||
}
|
||
}
|
||
.onChange(of: typingConfigs.opensExperiments) { _, opens in
|
||
guard opens else { return }
|
||
typingConfigs.opensExperiments = false
|
||
openPage = .experiments
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|