hex/ios/HEXMobile/HEXMobileApp.swift
Ryan Vogel 56209138f2 iOS: Word replacements, opening and exporting Hex words files, behind Custom vocabulary
Word replacements: a new list (heard -> write, up to 1,000, the words
file's limits, no empty or blank outputs yet) under Settings > Dictation >
Custom vocabulary, shown and applied only while that switch is on. They
apply in DictationPipeline, so in the app and in-keyboard dictation alike,
right before the learned fixes with DictationCorrections.apply's matching
(now taking up to 8 words for them), and win over a learned fix with the
same heard words. Learned fixes are never changed. A dictation Translate
what I say translates gets none; one that goes in as spoken does.

Opening: Info.plist (project.yml) exports anomaly.hex.words (public.json,
.hexwords, application/vnd.anomaly.hex-words+json) and owns it as a
document type copied in (LSSupportsOpeningDocumentsInPlace NO). HexInbox,
a small inbox shaped for another file kind later (#2529), copies the file
privately, reads it, shows HexWordsReviewSheet over whatever is on screen
and deletes both copies when the sheet closes; it logs counts and reasons
only. The sheet shows what is added, already there, clashes (Keep mine by
default), what this iPhone can't use, what the file skipped, a switch per
part, and offers to turn Custom vocabulary on. Strings from the file are
Text(verbatim:), direction-isolated and shortened. Add shows a one-line
confirmation with Undo; "Undo last import" stays in settings until either
list changes or another file is imported.

Export: Export words opens a sheet with "Include fixes Hex learned" (off),
what is left out and why, then the share sheet with hex-words.hexwords,
deleted after sharing. ShareSheet.present gains an optional completion.

Every new string has English and Simplified Chinese. Docs: dictation.md
and settings-and-home.md.

Checked on anomastudio (iOS 27.2 simulator): HexWordsSharedCasesTests
(read 59/59, merge 11/11 phone, write 2/2 phone), WordReplacementsTests,
CustomVocabulary, DictationLearning, DictationSSOT, DictationController,
Greeklish and TranscriptCleanup tests all pass.
2026-11-24 18:13:04 -05:00

88 lines
3.9 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import SwiftUI
import UIKit
@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?
init() {
FullKeyboardSettings().applyLaunchArguments()
TypingLogSettings().turnOffOnce()
TypingLogSettings().applyLaunchArguments()
HinglishSettings().applyLaunchArguments()
GreeklishSettings().applyLaunchArguments()
TwoLanguageDictationSettings().applyLaunchArguments()
VoiceIsolationSettings().applyLaunchArguments()
MultilingualParakeetSettings().applyLaunchArguments()
KeyboardParakeetSettings().applyLaunchArguments()
SettingsSnapshotFixture.applyDefaults()
HexInbox.sweep()
}
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 Hex words file from AirDrop, Files or Open in Hex: its review sheet.
if HexInbox.open(url) { 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()
}
}
}
}
}
}