mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-22 21:23:02 +01:00
* iOS: onboarding's practice says how to bring up Hex's keyboard David (iPhone 17 Pro Max, iOS 26.6.2, TestFlight) switched to Hex with the globe in onboarding's practice and saw "a big blank bar" with no Hex key, so he used iOS's own dictation mic instead. Not reproduced in the iOS 27.2 (iPhone 17 Pro) and 26.4 (iPhone 17 Pro Max) simulators, from first launch with Full Access granted before and while the keyboard ran: the keys, suggestions and Hex key are up in the first screenshot after the switch (0.5 s) every time. In the keyboard only the recording bar hides the Hex key with the keys up, and nothing in onboarding starts it, so the blank bar was most likely iOS's empty panel before the keyboard's first frame on that iPhone (as in #2185's report). The app couldn't tell, and the page kept saying "tap the Hex key". What changed - The keyboard notes in the App Group when its view has appeared (viewDidAppear, after its first frame) and when it goes away (viewWillDisappear): KeyboardBridge.recordKeyboardShown/Hidden. - KeyboardPresence.isShown: shown since it last appeared and not hidden since, with a sign of life (that appearance or the Full Access report it repeats every 5 s while shown) under 7 s old. - The practice page: after a keyboard switch by hand, when Hex's keyboard isn't on screen within 2 s (another keyboard, iOS's dictation, or Hex's never drew), it says "Don't see the Hex key? Tap the globe until Hex's keyboard comes up", gone as soon as Hex's keyboard is up. Only with Full Access, which the keyboard needs to write the App Group; without it the existing Full Access note shows. The three practice notes share one view (practiceNote); zh-Hans string added; README. Verified (anomastudio, ad-hoc signed Debug build, iPhone 17 Pro iOS 27.2, onboarding from first launch): switching from Hex to Apple's keyboard shows the note after 2 s, switching back hides it; tapping iOS's mic under Hex's keyboard takes Hex's keyboard off screen (hiddenAt written). Not verified on a physical iPhone. * iOS: onboarding's practice finishes only on Hex's own input David finished onboarding's practice with iOS's dictation (the system mic at the bottom right), not Hex: the practice counted any three words in its field once a keyboard had ever reported Full Access, so iOS's dictation, or Apple's keyboard, passed it. Reproduced on an iOS 27.2 simulator: three words typed on Apple's keyboard showed "That's Hex". What changed - Words count as typed only when they arrive while Hex's keyboard is on screen (KeyboardPresence, from the previous change): iOS's dictation and other keyboards take Hex's keyboard off screen, so their text never counts. OnboardingPractice.isDone takes typedWithHex (the words Hex's keyboard was up for, never more than the field holds) in place of the field's word count; wordsAdded works out a change's new words. - Text that arrives while Hex's keyboard is off screen shows "That came from iOS dictation or another keyboard, not Hex. Tap the Hex key on Hex's keyboard." and the practice doesn't finish; Hex's own input clears it, as does emptying the field. Only with Full Access (without it the Full Access note shows). zh-Hans string added; README. - Unchanged: a dictation Hex's keyboard inserted (lastInsertedResultID) still finishes it at once, and snapshot fixtures count their text. Verified (anomastudio, ad-hoc signed Debug build, iPhone 17 Pro iOS 27.2, practice reached from first launch): - Before: "See you at" typed on Apple's keyboard showed "That's Hex". - After: the same text keeps "Your turn" and shows the note; switching to Hex and typing "we" clears the note and still isn't done; "go now" with Hex's keys shows "That's Hex". - Tapping iOS's mic under Hex's keyboard takes Hex's keyboard off screen (the simulator has no microphone, so iOS's dictation inserted nothing). - xcodebuild test (both changes): 620 passed, 1 skipped, 0 failures. Not verified on a physical iPhone.
175 lines
6.3 KiB
Swift
175 lines
6.3 KiB
Swift
import Foundation
|
|
|
|
/// The first-run pages, in the desktop's order: Setting up Hex (the model starts downloading),
|
|
/// the demo, permissions, Almost ready (only while the model downloads), the practice, and
|
|
/// Hex is ready.
|
|
enum OnboardingPage: String, CaseIterable {
|
|
case setup
|
|
case demo
|
|
case permissions
|
|
case waiting
|
|
case practice = "try"
|
|
case ready
|
|
|
|
/// A saved page, including the ones earlier builds saved.
|
|
init?(saved: String) {
|
|
switch saved {
|
|
case "welcome": self = .setup
|
|
case "allow": self = .permissions
|
|
default: self.init(rawValue: saved)
|
|
}
|
|
}
|
|
|
|
var number: Int {
|
|
(Self.allCases.firstIndex(of: self) ?? 0) + 1
|
|
}
|
|
|
|
/// The demo and the practice: the pages setup doesn't need, which show a quiet Skip.
|
|
var isOptional: Bool {
|
|
self == .demo || self == .practice
|
|
}
|
|
}
|
|
|
|
/// The practice counts once it has really been tried: a dictation inserted, or a few words
|
|
/// typed with the Hex keyboard (Full Access on), not a first letter.
|
|
enum OnboardingPractice {
|
|
static let wordsToCount = 3
|
|
|
|
/// A dictation Hex's keyboard inserted, or `wordsToCount` words typed while Hex's keyboard
|
|
/// was on screen (`typedWithHex`): never words from iOS's dictation or another keyboard.
|
|
static func isDone(text: String, dictated: Bool, typedWithHex: Int, fullAccessOn: Bool) -> Bool {
|
|
if dictated { return true }
|
|
return fullAccessOn && min(typedWithHex, words(in: text)) >= wordsToCount
|
|
}
|
|
|
|
/// The words a change of the field's text added (none for a deletion).
|
|
static func wordsAdded(from old: String, to new: String) -> Int {
|
|
max(0, words(in: new) - words(in: old))
|
|
}
|
|
|
|
/// Words as the language splits them, so Chinese counts without spaces.
|
|
static func words(in text: String) -> Int {
|
|
var count = 0
|
|
text.enumerateSubstrings(in: text.startIndex..., options: [.byWords, .substringNotRequired]) { _, _, _, _ in
|
|
count += 1
|
|
}
|
|
return count
|
|
}
|
|
}
|
|
|
|
/// First-run progress in the app's own UserDefaults: "onboarding.completed" once it's done
|
|
/// or skipped, and "onboarding.page" so a quit part-way resumes on the same page.
|
|
@MainActor
|
|
enum OnboardingProgress {
|
|
static let completedKey = "onboarding.completed"
|
|
static let pageKey = "onboarding.page"
|
|
|
|
/// The page to open at launch, decided once per process.
|
|
static let launchPage: OnboardingPage? = decideLaunchPage(defaults: .standard)
|
|
|
|
static func decideLaunchPage(defaults: UserDefaults) -> OnboardingPage? {
|
|
if OnboardingFixture.isSnapshot {
|
|
return OnboardingFixture.current?.page
|
|
}
|
|
if defaults.bool(forKey: completedKey) {
|
|
return nil
|
|
}
|
|
if let saved = defaults.string(forKey: pageKey).flatMap(OnboardingPage.init(saved:)) {
|
|
return saved
|
|
}
|
|
// Someone whose keyboard and microphone already work (an earlier build) never sees it.
|
|
let monitor = KeyboardSetupMonitor()
|
|
if monitor.keyboardReady && monitor.microphone == .granted {
|
|
defaults.set(true, forKey: completedKey)
|
|
return nil
|
|
}
|
|
return .setup
|
|
}
|
|
|
|
static func save(_ page: OnboardingPage, defaults: UserDefaults = .standard) {
|
|
guard !OnboardingFixture.isSnapshot else { return }
|
|
defaults.set(false, forKey: completedKey)
|
|
defaults.set(page.rawValue, forKey: pageKey)
|
|
}
|
|
|
|
static func complete(defaults: UserDefaults = .standard) {
|
|
guard !OnboardingFixture.isSnapshot else { return }
|
|
defaults.set(true, forKey: completedKey)
|
|
defaults.removeObject(forKey: pageKey)
|
|
}
|
|
}
|
|
|
|
/// "--snap-state onboarding-<page>[-<state>]" on Simulator, and "onboarding-tour", which walks
|
|
/// the whole flow by itself for a screen recording. "KeyboardSetupMonitor.refresh" supplies the
|
|
/// matching setup state.
|
|
enum OnboardingFixture: String {
|
|
case setup = "onboarding-setup"
|
|
case demo = "onboarding-demo"
|
|
case permissions = "onboarding-permissions"
|
|
case permissionsDone = "onboarding-permissions-done"
|
|
case waiting = "onboarding-waiting"
|
|
case failed = "onboarding-failed"
|
|
case tryKeyboard = "onboarding-try"
|
|
case tryDone = "onboarding-try-done"
|
|
case tryEmpty = "onboarding-try-empty"
|
|
case tryOff = "onboarding-try-off"
|
|
case ready = "onboarding-ready"
|
|
case tour = "onboarding-tour"
|
|
|
|
static let isSnapshot = ProcessInfo.processInfo.arguments.contains("--snap-state")
|
|
|
|
/// Pages move on by themselves (after a beat, or once a step is done), except in
|
|
/// snapshots, where the tour moves them instead.
|
|
static var autoAdvances: Bool { !isSnapshot }
|
|
|
|
static let current: OnboardingFixture? = {
|
|
let args = ProcessInfo.processInfo.arguments
|
|
guard let idx = args.firstIndex(of: "--snap-state"), idx + 1 < args.count else { return nil }
|
|
return OnboardingFixture(rawValue: args[idx + 1])
|
|
}()
|
|
|
|
var page: OnboardingPage {
|
|
switch self {
|
|
case .setup, .tour: .setup
|
|
case .demo: .demo
|
|
case .permissions, .permissionsDone: .permissions
|
|
case .waiting, .failed: .waiting
|
|
case .tryKeyboard, .tryDone, .tryEmpty, .tryOff: .practice
|
|
case .ready: .ready
|
|
}
|
|
}
|
|
|
|
/// How far the fixture's model download is; nil once it's ready.
|
|
var modelFraction: Double? {
|
|
switch self {
|
|
case .setup, .demo, .permissions, .permissionsDone: 0.31
|
|
case .waiting: 0.62
|
|
case .tour: 0.05
|
|
default: nil
|
|
}
|
|
}
|
|
|
|
/// The tour's timeline, in seconds after its clock starts.
|
|
enum Tour {
|
|
/// Page 1 holds this long first: the simulator's screen recording stalls during launch.
|
|
static let leadIn = 4.0
|
|
static let toDemo = 3.0
|
|
static let toPermissions = 9.0
|
|
static let keyboardAdded = 11.0
|
|
static let microphoneAllowed = 12.5
|
|
static let toWaiting = 14.0
|
|
static let modelReady = 17.0
|
|
static let toTry = 17.8
|
|
static let fullAccess = 19.0
|
|
static let text = 21.0
|
|
static let toReady = 24.0
|
|
static let done = 28.0
|
|
|
|
/// Set when the onboarding first shows (plus the lead-in), so a slow launch doesn't eat page 1.
|
|
@MainActor static var start: Date?
|
|
|
|
@MainActor static var elapsed: TimeInterval {
|
|
start.map { Date().timeIntervalSince($0) } ?? 0
|
|
}
|
|
}
|
|
}
|