mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-22 04:17:05 +00:00
Part 1 — Simplified Chinese localization of the iOS app layer: - ios/Hapi/Resources/Localizable.xcstrings: hand-authored String Catalog (395 keys, zh-Hans; en implicit as source). Terminology mined from web/src/lib/locales/zh-CN.ts (会话/新建会话/权限模式/允许/拒绝/工作树/ 机器/语音输入/用量/草稿夹 …). - Mechanical edits only: merged multi-part string concatenations into single LocalizedStringKey literals, converted ternary/plain-String user copy to String(localized:), switched helper params (detailRow, DashboardCard, optionPicker, notice) to LocalizedStringKey. - LocalizedNoticeMapper (app layer): display-point translation of the 27 known HapiKit-emitted strings (ChatInteractor notices, dictation errors, window-sync warnings, files fallbacks, worktree-name validation) with verbatim passthrough for server-originated text; package stays language-free. - Deliberately untranslated (web parity / non-copy): event rows (EventPresentation — web renders presentation.ts verbatim), catalog option labels (Default/Auto/Sonnet/permission modes — web shows them verbatim), tool names, code-like titles (grep(pattern:), MCP:, Skill, Task), unit suffixes (B/KB/MB, m/h/d/w), decorative separators. - Language row wired: AppLanguage gains .system (follow system, new default); explicit picks write the AppleLanguages override, Follow system removes it; footer notes a relaunch applies it (no supported in-place SwiftUI locale swap). - project.pbxproj: zh-Hans added to knownRegions. Part 2 — #39 catalog dedupe (HapiProtocol): - NewSessionCatalogs.claudeModels/claudeEfforts now derive from ClaudeModels/ClaudeEfforts (single source shared with ModelCatalog); codexReasoningEfforts stays own data (web CODEX_REASONING_EFFORT_OPTIONS minus max); effortLabel delegates to ModelCatalog.capitalizedFirst. - New CatalogTests lock test for the derived option lists. Gate: bash ios/scripts/linux-test.sh — 459 tests green.
154 lines
5.6 KiB
Swift
154 lines
5.6 KiB
Swift
import HapiClient
|
|
import SwiftUI
|
|
|
|
/// Final confirmation step shared by every pairing path (deep link, QR scan,
|
|
/// manual entry): shows what is about to be paired, runs `AppModel.pair`
|
|
/// with progress, and renders ``PairingErrorView`` states on failure.
|
|
///
|
|
/// On success `AppModel` clears all pairing presentation state and flips to
|
|
/// `.paired`, which dismisses this view's container — nothing to do here.
|
|
struct PairingConfirmView: View {
|
|
let pending: PendingPairing
|
|
|
|
@Environment(AppModel.self) private var model
|
|
@State private var isPairing = false
|
|
@State private var failure: PairingFailure?
|
|
|
|
private var isAddingAnotherHub: Bool {
|
|
if case .paired = model.state { return true }
|
|
return false
|
|
}
|
|
|
|
var body: some View {
|
|
Form {
|
|
Section {
|
|
LabeledContent("Hub") {
|
|
Text(pending.hubUrl)
|
|
.multilineTextAlignment(.trailing)
|
|
.textSelection(.enabled)
|
|
}
|
|
LabeledContent("Access token") {
|
|
Text(HubDisplay.maskedToken(pending.accessToken))
|
|
.monospaced()
|
|
}
|
|
} footer: {
|
|
Text(isAddingAnotherHub
|
|
? String(localized: "This hub will be added to your paired hubs and become active.")
|
|
: String(localized: "The app checks the hub is reachable, then exchanges the token for a session."))
|
|
}
|
|
|
|
if let failure {
|
|
Section {
|
|
PairingErrorView(failure: failure)
|
|
}
|
|
}
|
|
|
|
Section {
|
|
Button {
|
|
pairNow()
|
|
} label: {
|
|
if isPairing {
|
|
HStack(spacing: 8) {
|
|
ProgressView()
|
|
Text("Pairing…")
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
} else {
|
|
Text(failure == nil ? String(localized: "Pair") : String(localized: "Try Again"))
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
}
|
|
.disabled(isPairing)
|
|
}
|
|
}
|
|
.navigationTitle(isAddingAnotherHub ? String(localized: "Add Hub") : String(localized: "Pair"))
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.interactiveDismissDisabled(isPairing)
|
|
}
|
|
|
|
private func pairNow() {
|
|
guard !isPairing else { return }
|
|
isPairing = true
|
|
failure = nil
|
|
Task {
|
|
do {
|
|
try await model.pair(hubUrl: pending.hubUrl, accessToken: pending.accessToken)
|
|
// Success: AppModel flipped to .paired and closed the pairing
|
|
// surfaces; this view is on its way out.
|
|
} catch let pairingFailure as PairingFailure {
|
|
failure = pairingFailure
|
|
} catch {
|
|
failure = .unreachable
|
|
}
|
|
isPairing = false
|
|
}
|
|
}
|
|
}
|
|
|
|
/// The pairing screen's error states, one presentation per
|
|
/// ``PairingFailure`` case.
|
|
struct PairingErrorView: View {
|
|
let failure: PairingFailure
|
|
|
|
var body: some View {
|
|
Label {
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
Text(title)
|
|
.font(.headline)
|
|
Text(message)
|
|
.font(.subheadline)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
} icon: {
|
|
Image(systemName: icon)
|
|
.foregroundStyle(.red)
|
|
}
|
|
}
|
|
|
|
private var icon: String {
|
|
switch failure {
|
|
case .invalidHubURL: "questionmark.circle"
|
|
case .unreachable: "wifi.exclamationmark"
|
|
case .protocolMismatch: "arrow.triangle.2.circlepath"
|
|
case .invalidAccessToken: "key"
|
|
case .hubError: "exclamationmark.triangle"
|
|
case .storageFailure: "externaldrive.badge.xmark"
|
|
}
|
|
}
|
|
|
|
private var title: String {
|
|
switch failure {
|
|
case .invalidHubURL: String(localized: "Invalid hub URL")
|
|
case .unreachable: String(localized: "Hub unreachable")
|
|
case .protocolMismatch: String(localized: "Version mismatch")
|
|
case .invalidAccessToken: String(localized: "Token rejected")
|
|
case .hubError: String(localized: "Hub error")
|
|
case .storageFailure: String(localized: "Could not save")
|
|
}
|
|
}
|
|
|
|
private var message: String {
|
|
switch failure {
|
|
case .invalidHubURL:
|
|
String(localized: "Enter the hub's full address, e.g. http://192.168.1.20:3006.")
|
|
case .unreachable:
|
|
String(localized: "No HAPI hub answered at this address. Check that the hub is running and that this device can reach it (same network, or the relay tunnel is up).")
|
|
case .protocolMismatch(let hubVersion, let supportedVersion):
|
|
String(
|
|
format: String(localized: "The hub speaks protocol v%lld, this app supports v%lld. Update the older side, then try again."),
|
|
Int64(hubVersion),
|
|
Int64(supportedVersion)
|
|
)
|
|
case .invalidAccessToken:
|
|
String(localized: "The hub rejected this access token — it may have been rotated. Get a fresh pairing code from the hub and try again.")
|
|
case .hubError(let status):
|
|
String(
|
|
format: String(localized: "The hub answered unexpectedly (HTTP %lld). Try again in a moment."),
|
|
Int64(status)
|
|
)
|
|
case .storageFailure:
|
|
String(localized: "Pairing succeeded but the credentials could not be stored on this device. Try again.")
|
|
}
|
|
}
|
|
}
|