hex/ios/HEXShared/FullKeyboard/FullKeyboardView+FullAccess.swift
Ryan Vogel 845b8141d2 iOS keyboard: the speech model notice can be dismissed for good
What: the New speech model notice gets an ✕ at the end away from its Open Hex chip (where the
Hex key is on the left, at the right). Tapping it removes the notice at once and it never shows
again on this iPhone, whatever the counts (experiments.keyboardParakeet.notice.dismissed in the
App Group, beside shown, day and opened). It opens nothing and doesn't count as Open Hex. Drawn
as Home's card draws its dismiss (xmark, 11 pt semibold, the muted text colour), with a touch
area the notice's full height and 34 pt wide; the words move over by that much and the chip
keeps its size and place, so a miss on the ✕ lands on the words, never on the chip.
KeyboardStripNotice gains dismissible (false for every other notice), FullAccessHintView draws
the ✕ only for it, and KeyboardStripView reports it as onDismissNotice. VoiceOver: a button
labelled with the existing "Dismiss" (关闭); no new strings.

Why: Ryan: "Just make sure that the bar in the keyboard, the notice bar, is able to be turned off."

Verified: KeyboardBridgeTests on the Studio simulator (37; new: the ✕ is there, at least 34 by
28 pt, not overlapping Open Hex; after it the notice is gone, nothing opened, not recorded as
opened, one showing counted, and it's never offered again the next day, a month on, when the
keyboard appears again or in a new keyboard on a new day; the chip still opens Hex).
2026-11-22 17:49:46 -05:00

158 lines
6.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 UIKit
/// The strip's Full Access hints in the full keyboard: the Hex key tapped without Allow Full
/// Access says what dictation needs and where to turn it on, and a paste iOS asked about or
/// refused says where to stop it asking. Each is a strip notice for a few seconds, and only
/// the hint's own chip opens Hex.
extension FullKeyboardView {
// MARK: - Without Full Access
/// The Hex key without Full Access: the keys keep typing, and the strip says, for a few
/// seconds, that dictation needs Allow Full Access and where to turn it on. Only its
/// Open Hex chip opens Hex; nothing opens it by itself.
func showFullAccessHint() {
dismissStyleMenu()
showsFullAccessHint = true
refreshStrip()
UIAccessibility.post(
notification: .announcement,
argument: "\(FullAccessHintView.title). \(FullAccessHintView.spokenPath)."
)
fullAccessHintHideWork?.cancel()
let work = DispatchWorkItem { [weak self] in self?.hideFullAccessHint() }
fullAccessHintHideWork = work
DispatchQueue.main.asyncAfter(deadline: .now() + Self.fullAccessHintDuration, execute: work)
}
func hideFullAccessHint() {
fullAccessHintHideWork?.cancel()
fullAccessHintHideWork = nil
guard showsFullAccessHint else { return }
showsFullAccessHint = false
refreshStrip()
}
func openSetupFromHint() {
keyFeedback()
hideFullAccessHint()
model.onOpenURL?(KeyboardLaunchRequest.setup.url)
}
func pasteFromClipboard() {
if stripOffer == .dictation {
keyFeedback()
typingLog?.ui("paste_dictation")
model.onPasteDictation?()
refreshStrip()
return
}
let pasteboard = UIPasteboard.general
// The read blocks while iOS asks Allow Paste, so its length tells whether it asked.
let start = ProcessInfo.processInfo.systemUptime
let read = KeyboardClipboardTracker.read(pasteboard)
let readDuration = ProcessInfo.processInfo.systemUptime - start
let text = read.flatMap { $0.isEmpty ? nil : $0 }
let refused = text == nil && (pasteboard.hasStrings || pasteboard.hasURLs)
let pointsToSetting = clipboard.shouldPointToAllowPaste(readDuration: readDuration, refused: refused)
guard let text else {
if pointsToSetting { showAllowPasteHint() }
return
}
keyFeedback()
clipboard.markPasted()
if !pointsToSetting && readDuration < KeyboardClipboardTracker.askedReadDuration {
clipboard.recordSilentPaste(pasteboard: pasteboard)
}
typingLog?.edit("paste", [TypingLogField("inserted", .string(text))])
engine.commitHangulComposition()
engine.forgetTextAroundKeys()
engine.target.insertText(text)
engine.textDidChange()
typingLog?.context("paste")
if pointsToSetting { showAllowPasteHint() }
refreshStrip()
onTextEdit?()
}
/// Two-line notice with a Settings chip after iOS asks Allow Paste or refuses a read.
var allowPasteNotice: KeyboardStripNotice? {
showsAllowPasteHint ? KeyboardClipboardTracker.allowPasteNotice : nil
}
/// For a few seconds after a paste iOS asked about (or refused), the strip offers a
/// Settings chip pointing straight to Paste from Other Apps › Allow.
func showAllowPasteHint() {
showsAllowPasteHint = true
refreshStrip()
UIAccessibility.post(notification: .announcement, argument: KeyboardClipboardTracker.allowPasteHintAnnouncement)
allowPasteHintHideWork?.cancel()
let work = DispatchWorkItem { [weak self] in self?.hideAllowPasteHint() }
allowPasteHintHideWork = work
DispatchQueue.main.asyncAfter(deadline: .now() + Self.allowPasteHintDuration, execute: work)
}
/// Opens Hex to jump straight to iOS Settings › Apps › Hex.
func openPasteSettingsFromHint() {
hideAllowPasteHint()
model.onOpenURL?(KeyboardLaunchRequest.pasteSettings.url)
}
/// Typing takes the strip back before the hint's time is up.
func hideAllowPasteHint() {
allowPasteHintHideWork?.cancel()
allowPasteHintHideWork = nil
guard showsAllowPasteHint else { return }
showsAllowPasteHint = false
refreshStrip()
}
// MARK: New speech model
/// Two-line notice with an Open Hex chip while the model the keyboard would dictate with
/// isn't downloaded (`KeyboardParakeetNotice`).
var modelNotice: KeyboardStripNotice? {
guard showsModelNotice, !isDictating else { return nil }
return KeyboardStripNotice(
title: String(localized: "New speech model"),
detail: String(localized: "Downloads in Hex on Wi-Fi"),
button: String(localized: "Open Hex"),
dismissible: true
)
}
/// When the keyboard appears: only with Full Access (the App Group, where the model and the
/// counts are, and opening Hex need it), never in a password or one-time-code field, never
/// while dictating, and as often as `KeyboardParakeetNotice` allows.
func offerModelNotice(now: Date = Date(), awaitsDownload: Bool = KeyboardParakeetNotice.modelAwaitsDownload()) {
let notice = KeyboardParakeetNotice()
guard !showsModelNotice, model.hasFullAccess, !isDictating,
engine.target.isSecureTextEntry != true, engine.target.textContentType != .oneTimeCode,
awaitsDownload, notice.mayShow(now: now) else { return }
notice.recordShown(now: now)
showsModelNotice = true
typingLog?.ui("model_notice")
refreshStrip()
}
private var isDictating: Bool { model.stagePhase == .recording || model.stagePhase == .transcribing }
func openHexForModel() {
KeyboardParakeetNotice().recordOpened()
hideModelNotice()
model.onOpenURL?(KeyboardParakeetNotice.opensHex)
}
/// The notice's ✕: gone at once and never shown again on this iPhone.
func dismissModelNotice() {
KeyboardParakeetNotice().recordDismissed()
hideModelNotice()
}
/// Typing or dictating takes the strip back.
func hideModelNotice() {
guard showsModelNotice else { return }
showsModelNotice = false
refreshStrip()
}
}