hex/ios/HEXMobile/HEXMobileApp.swift
Ryan Vogel 4e7ef4720f iOS: Speech model in keyboard moves to Settings › Dictation; the keyboard logs resident and compressed memory
What changed
- The row (switch, detail and status) leaves Experiments for its own card in Settings ›
  Dictation (iOS 26 and later, where the keyboard can use it): it is the default engine for the
  keyboard's English dictation now, not an experiment. KeyboardParakeetRow (in
  KeyboardParakeetDownload.swift) owns the switch's state, the change handler and the status
  view that ExperimentsSettingsPage held; wording and behaviour unchanged.
- KeyboardProbeLog.memory() adds the keyboard's resident (task_vm_info internal) and compressed
  memory to every memory line, the recording's start and stop included, so the next long run
  can tell what the one-time step of about 15 MB at the ninth dictation is.
- Comments and README say Settings › Dictation.

Why
- Recommended once the switch became a default (#2390); the step needs these two numbers.

Verified
- Studio suite in the pull request.
2026-11-22 15:22:54 -05:00

89 lines
4 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()
MultilingualParakeetSettings().applyLaunchArguments()
KeyboardParakeetSettings().applyLaunchArguments()
SettingsSnapshotFixture.applyDefaults()
}
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
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()
}
}
}
}
// Speech model in keyboard's download, started by the keyboard: iOS wakes Hex to take
// in files that finished while the keyboard wasn't running.
.backgroundTask(.urlSession(SpeechModelBackgroundDownload.identifier)) {
await SpeechModelBackgroundDownload.shared.handleEvents()
}
}
}