hex/ios/HEXMobile/HEXMobileApp.swift
Ryan Vogel 44f2eb22bd
iOS keyboard: Open Hex as the last row of the Hex key menu (#2791)
What: holding the full keyboard's Hex key now shows Open Hex as the menu's last
row, set apart by a line below the translation rows, in the menu's own row style
(no symbol: no other row leaves the keyboard). A tap closes the menu and opens
Hex at Home through a new KeyboardLaunchRequest.home (hex-dictation://keyboard/home),
which starts no session; Hex closes Settings or the setup sheet back to Home.
Uses the existing "Open Hex" string and its Chinese. Typing logs record
ui open_hex (from: hex_menu).

Why: a tester asked for a link to the app from that menu; Ryan agreed. It keeps
#2707's rule: the keyboard opens Hex only on a tap that says Open Hex. Without
Full Access a hold shows the Full Access hint instead of the menu, as before, so
the row isn't offered there. The dictation bar has no such menu (its styles are
a chip tray), so nothing changes there.

Verified: build-for-testing for iOS Simulator on basebook; code-shape check.
Tests added to HexKeyGestureTests (the row is last, only a tap reports),
FullKeyboardEngineTests+Suggestions (opening the menu opens nothing, the row's
tap opens Hex at Home and closes the menu) and KeyboardBridgeTests (the home URL
round trip). Suite not run yet.
2026-11-24 20:22:47 -05:00

95 lines
4.3 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?
/// Counts the keyboard's Open Hex taps from the Hex key menu: each one shows Home.
@State private var homeRequests = 0
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,
homeRequests: homeRequests
)
.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 .home = request {
openedFromKeyboard = false
showSetup = false
homeRequests += 1
} 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()
}
}
}
}
}
}