mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
Review on #2345: for Hex, "on this iPhone", "never leaves" and "not sent" are facts people need at that moment, not reassurance. Restored: - Microphone prompt: "...Audio never leaves it and is deleted once it's transcribed." Speech Recognition prompt keeps "Nothing you say is sent to a server." (Info.plist, project.yml, zh-Hans InfoPlist.strings) - Learn how I type and Record typing logs say "on this iPhone" again. - Clean up what I say is back to "Drops ums, repeats and corrected words". - "Allow Speech Recognition. It stays on this iPhone." and "...in Settings. It runs on this iPhone." back to the originals. - On-device put back in the shortest form: Checking on-device speech recognition; the Parakeet memory fallback names Apple's on-device speech recognition; Adaptive touch learns "on this iPhone"; the Shortcut, Control Center and Live Activity descriptions say "on device" / "on-device" (not "iPhone": KeyboardBridgeTests forbids Apple platform names in intent strings). Keyboard strip: Undo dictation, Paste, Paste dictation, Code from Messages (and its VoiceOver hint), Undoes the autocorrection, the Full Access hint (title, Settings path, spoken path, Open Hex, its hint) and the dictation bar's Full Access path were plain strings, so Chinese users saw English. They now go through String(localized:); the keyboard extension already bundles HEXMobile/Localizable.xcstrings, so no wiring was needed. 10 new catalog entries with zh-Hans, using the app's terms (粘贴听写, 完全访问). Verified: the built HEXKeyboard.appex zh-Hans Localizable.strings carries the new keys; zh screenshots show 撤销听写 in the strip and the translated path in the dictation bar; scripts/code-shape.py has no hard problems; xcodebuild test on a fresh iPhone 17 Pro sim: TEST SUCCEEDED.
94 lines
3.7 KiB
Swift
94 lines
3.7 KiB
Swift
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()
|
||
typingLog?.edit("paste", [TypingLogField("inserted", .string(text))])
|
||
engine.forgetTextAroundKeys()
|
||
engine.target.insertText(text)
|
||
engine.textDidChange()
|
||
typingLog?.context("paste")
|
||
if pointsToSetting { showAllowPasteHint() }
|
||
refreshStrip()
|
||
onTextEdit?()
|
||
}
|
||
|
||
/// For a few seconds after a paste iOS asked about (or refused), the strip says where
|
||
/// to stop it asking: Settings › Apps › Hex › Paste from Other Apps › Allow.
|
||
private 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)
|
||
}
|
||
|
||
/// 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()
|
||
}
|
||
}
|