mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
* iOS Privacy: Privacy policy and Support links, for App Review 5.1.1(i) App Review requires a privacy policy link inside the app. The Privacy page now has a card with two rows between Learn how I type and Advanced: - Privacy policy opens https://dev.anoma.ly/hex/privacy. - Support opens https://dev.anoma.ly/hex/iphone. Both open in Safari inside Hex (SFSafariViewController, SafariSheet). The URLs come from one base in HexLinks.swift (HexLinks.site). Moving to https://anoma.ly/hex is a one-line change once the site's production deploy serves those pages; https://anoma.ly/hex/privacy returns 404 today, while both dev.anoma.ly pages return 200. README's Privacy page entry says so. Verified: the build passes on an iPhone 18 Pro simulator (iOS 27.2). I looked at the settings-privacy render. A temporary, uncommitted hook opened the Privacy policy row's Safari sheet, which loaded the live dev.anoma.ly page. * iOS setup sheet: Continue, not Allow, before the microphone prompt App Review 5.1.1(iv) rejects a custom button that says "Allow" right before iOS's own permission prompt. The setup sheet's Microphone row had one. It now matches onboarding's Set up Hex page (#2058): the row says why ("For dictation", replacing "Required") and its button says Continue. Tapping Continue still calls requestMicrophone, so iOS asks right after. Allowed and Off are unchanged, and Off still shows Open Settings. New scene: --snap-state setup-sheet-microphone, the setup sheet before iOS has asked for the microphone. README's Setup and scene notes are updated. Verified: the build passes on an iPhone 18 Pro simulator (iOS 27.2). I looked at the setup-sheet-microphone render (For dictation, Continue) and the setup-sheet render (Allowed, no button). * iOS Privacy: Record typing logs says what it records and asks before turning on App Review 2.5.14 requires explicit consent before recording what people type. - The description now says what the feature records: "Records taps and the text you type for 14 days, on this iPhone, to export. Off by default." It replaces "Off by default. Stays on this iPhone to export" and fits on two lines. - Turning it on opens an alert before anything changes. Title: "Record typing logs?". Message: "Hex's keyboard will record each tap and the text you type or dictate with it, including the text around the cursor, for 14 days. The logs stay on this iPhone for you to export or delete. Password, code and card fields are never recorded." Turn On switches it on; Cancel leaves it off. Turning it off needs no dialog. The switch still writes only TypingLogSettings.isEnabled. - Every claim matches docs/typing-logs.md: touches on Hex's keys, the text each key produced, the text around the cursor, dictations, 14 days in the App Group, export and delete from Typing logs, and a "skipped" line only for password, one-time code and card fields. New scene: --snap-state settings-privacy-confirm opens the dialog (SettingsSnapshotFixture.confirmsTypingLogs). README and docs/typing-logs.md now describe the consent and the new path (Privacy › Advanced, no longer Experiments). Verified: the build passes on an iPhone 18 Pro simulator (iOS 27.2). I looked at the settings-privacy, settings-privacy-confirm and settings-privacy-on renders. * iOS home: Privacy policy and Support join Acknowledgements #2059 added an Acknowledgements row at the bottom of home's utility card. The privacy policy and support links read better beside it than on the Privacy page. Home's last card now has Privacy policy (hand.raised, ↗), Support (questionmark.circle, ↗) and Acknowledgements (doc.text, ›). Keyboard settings and Run setup again keep their own card above it. - Moved, not duplicated: the Privacy page's links card is removed. That page is back to "Everything stays on this iPhone", Learn how I type, and Advanced. - Links still come from HexLinks (dev.anoma.ly until production serves anoma.ly/hex/privacy) and open in Safari inside Hex. - README's Settings section now lists the links on home. Verified: the build passes on an iPhone 18 Pro simulator (iOS 27.2). I looked at the settings-home render, which still fits one screen without scrolling, and the settings-privacy render.
352 lines
13 KiB
Swift
352 lines
13 KiB
Swift
import AVFAudio
|
|
import Observation
|
|
import SwiftUI
|
|
import UIKit
|
|
|
|
/// Live keyboard setup state, read from the system and the App Group.
|
|
@MainActor
|
|
@Observable
|
|
final class KeyboardSetupMonitor {
|
|
static let keyboardBundleID = "anomaly.hex.mobile.keyboard"
|
|
|
|
private let bridge: KeyboardBridge
|
|
|
|
/// nil when iOS doesn't say which keyboards are enabled.
|
|
private(set) var keyboardAdded: Bool?
|
|
private(set) var fullAccessOn = false
|
|
private(set) var microphone = AVAudioApplication.shared.recordPermission
|
|
|
|
init(bridge: KeyboardBridge = KeyboardBridge()) {
|
|
self.bridge = bridge
|
|
refresh()
|
|
}
|
|
|
|
var keyboardReady: Bool {
|
|
keyboardAdded == true && fullAccessOn
|
|
}
|
|
|
|
func refresh() {
|
|
let args = ProcessInfo.processInfo.arguments
|
|
if let idx = args.firstIndex(of: "--snap-state"), idx + 1 < args.count {
|
|
switch args[idx + 1] {
|
|
case "setup", "setup-sheet", "onboarding-try", "onboarding-try-off":
|
|
keyboardAdded = true
|
|
fullAccessOn = false
|
|
microphone = .granted
|
|
case "onboarding-welcome", "onboarding-allow", "setup-sheet-microphone":
|
|
keyboardAdded = true
|
|
fullAccessOn = false
|
|
microphone = .undetermined
|
|
case "onboarding-tour":
|
|
let elapsed = OnboardingFixture.Tour.elapsed
|
|
keyboardAdded = elapsed >= OnboardingFixture.Tour.keyboardAdded
|
|
fullAccessOn = elapsed >= OnboardingFixture.Tour.fullAccess
|
|
microphone = elapsed >= OnboardingFixture.Tour.microphoneAllowed ? .granted : .undetermined
|
|
default:
|
|
keyboardAdded = true
|
|
fullAccessOn = true
|
|
microphone = .granted
|
|
}
|
|
return
|
|
}
|
|
|
|
fullAccessOn = bridge.fullAccessSeenAt != nil
|
|
if let keyboards = UserDefaults.standard.stringArray(forKey: "AppleKeyboards") {
|
|
keyboardAdded = keyboards.contains(Self.keyboardBundleID) || fullAccessOn
|
|
} else {
|
|
keyboardAdded = fullAccessOn ? true : nil
|
|
}
|
|
microphone = AVAudioApplication.shared.recordPermission
|
|
}
|
|
|
|
func requestMicrophone(then done: (@MainActor () -> Void)? = nil) {
|
|
AVAudioApplication.requestRecordPermission { _ in
|
|
Task { @MainActor [weak self] in
|
|
self?.refresh()
|
|
done?()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The four setup steps and how many are left. Full Access only counts as done once the
|
|
/// keyboard has run with it, so "not confirmed yet" is an ordinary step, not a failure.
|
|
extension KeyboardSetupMonitor {
|
|
func stepsLeft(modelReady: Bool) -> Int {
|
|
[keyboardAdded == true, fullAccessOn, microphone == .granted, modelReady]
|
|
.filter { !$0 }
|
|
.count
|
|
}
|
|
}
|
|
|
|
/// Home's one status line under the Hex header: "Ready", or "Finish setup · 1 step" opening
|
|
/// the sheet.
|
|
struct SetupStatusRow: View {
|
|
let stepsLeft: Int
|
|
let action: () -> Void
|
|
|
|
var body: some View {
|
|
Button(action: action) {
|
|
HStack(spacing: 9) {
|
|
Group {
|
|
if stepsLeft == 0 {
|
|
Image(systemName: "checkmark.circle.fill")
|
|
.font(.system(size: 13, weight: .medium))
|
|
.foregroundStyle(HexTheme.success)
|
|
} else {
|
|
Image(systemName: "circle.dotted")
|
|
.font(.system(size: 13, weight: .medium))
|
|
.foregroundStyle(HexTheme.textMuted)
|
|
}
|
|
}
|
|
.frame(width: 20)
|
|
|
|
HStack(spacing: 5) {
|
|
if stepsLeft == 0 {
|
|
Text("Ready")
|
|
.foregroundStyle(HexTheme.textMuted)
|
|
} else {
|
|
Text("Finish setup")
|
|
.foregroundStyle(HexTheme.textBase)
|
|
Text("· \(stepsLeft) \(stepsLeft == 1 ? "step" : "steps")")
|
|
.foregroundStyle(HexTheme.textMuted)
|
|
Image(systemName: "chevron.right")
|
|
.font(.system(size: 10, weight: .semibold))
|
|
.foregroundStyle(HexTheme.textMuted)
|
|
}
|
|
}
|
|
}
|
|
.font(.system(size: 13, weight: .medium))
|
|
.frame(minHeight: 30, alignment: .leading)
|
|
.contentShape(Rectangle())
|
|
}
|
|
.buttonStyle(.plain)
|
|
.accessibilityLabel(stepsLeft == 0 ? "Hex is ready" : "Finish setup, \(stepsLeft) left")
|
|
}
|
|
}
|
|
|
|
/// The setup checklist, opened from home's status line or the keyboard's Open Hex setup.
|
|
struct SetupSheet: View {
|
|
@Environment(\.openURL) private var openURL
|
|
@Environment(\.dismiss) private var dismiss
|
|
@Bindable var dictation: DictationController
|
|
let monitor: KeyboardSetupMonitor
|
|
@State private var checkText = ""
|
|
@State private var contentHeight: CGFloat = 360
|
|
@FocusState private var checkFocused: Bool
|
|
|
|
/// iOS only tells Hex about Full Access from inside its keyboard, so until the keyboard
|
|
/// has run once with it, the app can't tell "on" from "off".
|
|
private var needsKeyboardCheck: Bool {
|
|
monitor.keyboardAdded != false && !monitor.fullAccessOn
|
|
}
|
|
|
|
var body: some View {
|
|
content
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
.onGeometryChange(for: CGFloat.self) { $0.size.height } action: { contentHeight = $0 }
|
|
.frame(maxHeight: .infinity, alignment: .top)
|
|
.presentationDetents([.height(contentHeight)])
|
|
.presentationDragIndicator(.visible)
|
|
.presentationBackground(HexTheme.bgDeep)
|
|
.preferredColorScheme(.dark)
|
|
.onChange(of: monitor.fullAccessOn) { _, on in
|
|
if on { checkFocused = false }
|
|
}
|
|
}
|
|
|
|
private var content: some View {
|
|
VStack(alignment: .leading, spacing: 16) {
|
|
HStack(spacing: 12) {
|
|
Text(monitor.stepsLeft(modelReady: dictation.isModelReady) == 0 ? "Hex is ready" : "Finish setup")
|
|
.font(.system(size: 17, weight: .semibold))
|
|
.tracking(-0.2)
|
|
.foregroundStyle(HexTheme.textBase)
|
|
Spacer()
|
|
Button {
|
|
dismiss()
|
|
} label: {
|
|
Image(systemName: "xmark")
|
|
.font(.system(size: 12, weight: .semibold))
|
|
.foregroundStyle(HexTheme.textMuted)
|
|
.frame(width: 30, height: 30)
|
|
.background(Color.white.opacity(0.07), in: Circle())
|
|
.frame(width: 44, height: 44, alignment: .trailing)
|
|
.contentShape(Rectangle())
|
|
}
|
|
.buttonStyle(.plain)
|
|
.accessibilityLabel("Close")
|
|
}
|
|
.frame(height: 30)
|
|
|
|
VStack(spacing: 0) {
|
|
row(
|
|
title: "Hex Keyboard",
|
|
status: keyboardStatus,
|
|
icon: monitor.keyboardAdded == true ? .done : .todo
|
|
)
|
|
SettingsDivider(leading: 42)
|
|
row(
|
|
title: "Full Access",
|
|
status: monitor.fullAccessOn ? "On" : needsKeyboardCheck ? "Not confirmed yet" : "Off",
|
|
icon: monitor.fullAccessOn ? .done : needsKeyboardCheck ? .unconfirmed : .todo
|
|
)
|
|
SettingsDivider(leading: 42)
|
|
row(
|
|
title: "Microphone",
|
|
status: microphoneStatus,
|
|
icon: monitor.microphone == .granted ? .done : .todo
|
|
) {
|
|
// iOS asks right after this tap, so Hex's own button says Continue, never
|
|
// Allow (App Review 5.1.1(iv)), as onboarding's Set up Hex page does.
|
|
if monitor.microphone == .undetermined {
|
|
smallButton("Continue") { monitor.requestMicrophone() }
|
|
}
|
|
}
|
|
SettingsDivider(leading: 42)
|
|
row(
|
|
title: "Speech model",
|
|
status: modelStatus,
|
|
icon: dictation.isModelReady ? .done : .todo
|
|
)
|
|
}
|
|
.background(
|
|
HexTheme.bgBase,
|
|
in: RoundedRectangle(cornerRadius: HexTheme.cardRadius, style: .continuous)
|
|
)
|
|
|
|
if needsKeyboardCheck {
|
|
TextField(
|
|
"",
|
|
text: $checkText,
|
|
prompt: Text("Tap here, then switch to Hex with \(Image(systemName: "globe"))")
|
|
.foregroundStyle(HexTheme.textFaint)
|
|
)
|
|
.font(.system(size: 15))
|
|
.foregroundStyle(HexTheme.textBase)
|
|
.focused($checkFocused)
|
|
.padding(.horizontal, 16)
|
|
.frame(minHeight: 46)
|
|
.background(
|
|
HexTheme.bgBase,
|
|
in: RoundedRectangle(cornerRadius: HexTheme.cardRadius, style: .continuous)
|
|
)
|
|
}
|
|
|
|
if !monitor.keyboardReady || monitor.microphone == .denied {
|
|
Button {
|
|
if let url = URL(string: UIApplication.openSettingsURLString) {
|
|
openURL(url)
|
|
}
|
|
} label: {
|
|
Text("Open Settings")
|
|
.font(.system(size: 15, weight: .medium))
|
|
.foregroundStyle(HexTheme.textBase)
|
|
.frame(maxWidth: .infinity, minHeight: 44)
|
|
.background(Color.white.opacity(0.09), in: Capsule())
|
|
}
|
|
.buttonStyle(.plain)
|
|
}
|
|
}
|
|
.padding(.horizontal, 20)
|
|
.padding(.top, 24)
|
|
.padding(.bottom, 20)
|
|
}
|
|
|
|
private enum RowIcon {
|
|
case done
|
|
case unconfirmed
|
|
case todo
|
|
}
|
|
|
|
private var keyboardStatus: String {
|
|
switch monitor.keyboardAdded {
|
|
case true?: "Added"
|
|
case false?: "Not added"
|
|
case nil: "Not verified"
|
|
}
|
|
}
|
|
|
|
private var microphoneStatus: String {
|
|
switch monitor.microphone {
|
|
case .granted: "Allowed"
|
|
case .denied: "Off"
|
|
default: "For dictation"
|
|
}
|
|
}
|
|
|
|
private var modelStatus: String {
|
|
if dictation.isModelReady {
|
|
// "Norwegian Bokmål · Apple": the language it really transcribes, short enough
|
|
// for the row.
|
|
let code = Locale(identifier: dictation.transcriptionLanguageID).language.languageCode?.identifier ?? "en"
|
|
let language = Locale.current.localizedString(forLanguageCode: code).map {
|
|
$0.prefix(1).uppercased() + $0.dropFirst()
|
|
} ?? dictation.transcriptionLanguage
|
|
let engine = dictation.engineName == "Apple Speech" ? "Apple" : dictation.engineName
|
|
return "\(language) · \(engine)"
|
|
}
|
|
switch dictation.phase {
|
|
case .preparingModel:
|
|
return "\(Int(dictation.modelPreparation.fractionCompleted * 100))%"
|
|
case .failed:
|
|
return "Failed"
|
|
default:
|
|
return "Preparing"
|
|
}
|
|
}
|
|
|
|
private func row(title: String, status: String, icon: RowIcon) -> some View {
|
|
row(title: title, status: status, icon: icon) { EmptyView() }
|
|
}
|
|
|
|
private func row<Trailing: View>(
|
|
title: String,
|
|
status: String,
|
|
icon: RowIcon,
|
|
@ViewBuilder trailing: () -> Trailing
|
|
) -> some View {
|
|
HStack(alignment: .center, spacing: 10) {
|
|
Group {
|
|
switch icon {
|
|
case .done:
|
|
Image(systemName: "checkmark.circle.fill")
|
|
.foregroundStyle(HexTheme.success)
|
|
case .unconfirmed:
|
|
Image(systemName: "circle.dotted")
|
|
.foregroundStyle(HexTheme.textMuted)
|
|
case .todo:
|
|
Image(systemName: "circle")
|
|
.foregroundStyle(HexTheme.textFaint)
|
|
}
|
|
}
|
|
.font(.system(size: 16, weight: .medium))
|
|
.frame(width: 16)
|
|
|
|
Text(title)
|
|
.font(.system(size: 15, weight: .regular))
|
|
.foregroundStyle(HexTheme.textBase)
|
|
|
|
Spacer(minLength: 8)
|
|
|
|
Text(status)
|
|
.font(.system(size: 13))
|
|
.foregroundStyle(HexTheme.textMuted)
|
|
.lineLimit(1)
|
|
|
|
trailing()
|
|
}
|
|
.padding(.horizontal, 16)
|
|
.frame(minHeight: 46)
|
|
}
|
|
|
|
private func smallButton(_ title: String, action: @escaping () -> Void) -> some View {
|
|
Button(title, action: action)
|
|
.font(.system(size: 13, weight: .medium))
|
|
.foregroundStyle(HexTheme.textBase)
|
|
.padding(.horizontal, 12)
|
|
.frame(height: 28)
|
|
.background(Color.white.opacity(0.09), in: Capsule())
|
|
.buttonStyle(.plain)
|
|
}
|
|
}
|