mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 02:29:55 +02:00
Replaces every stringly-typed localization key in the Apple app with compile-time-checked accessors generated from localization/strings.json. A mistyped key is now a build error instead of a silent fallback to the raw key at runtime. The runtime path is unchanged: plain keys are String.LocalizationValue constants resolved with String(localized:) and Apple's String Catalog still does the lookup; keys with arguments become typed, named functions applying args through String(format:). Generator: new renderSwiftAccessors emits apple/VniDrop/Generated/L10n.swift, wired into generate. Renamed generic arg1/arg2 tokens on four keys to semantic names (receiver, transferName, deviceId) and updated their context notes; positional output is unchanged so .xcstrings (bar the 4 comments) and the Android XML regenerate identical. Migration: every key-carrying value flipped to String.LocalizationValue end to end, resolved only at the leaf. Zero key literals and zero LocalizedStringKey remain in app or test code. macOS build passes; iOS test run pending.
74 lines
2.4 KiB
Swift
74 lines
2.4 KiB
Swift
import SwiftUI
|
|
|
|
/// Non-dismissable receiver-approval modal, presented as a native sheet that can't
|
|
/// be swiped away. The endpoint id is the trusted identity; display names are
|
|
/// peer-provided.
|
|
struct ApprovalModalHost: View {
|
|
let state: ApprovalState
|
|
let onAccept: (String) -> Void
|
|
let onRefuse: (String) -> Void
|
|
|
|
var body: some View {
|
|
Color.clear
|
|
.sheet(isPresented: .constant(state.current != nil)) {
|
|
if let request = state.current {
|
|
ApprovalSheet(state: state, request: request, onAccept: onAccept, onRefuse: onRefuse)
|
|
.interactiveDismissDisabled(true)
|
|
.modifier(ApprovalDetents())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private struct ApprovalDetents: ViewModifier {
|
|
func body(content: Content) -> some View {
|
|
#if os(iOS)
|
|
content.presentationDetents([.medium])
|
|
#else
|
|
content.frame(minWidth: 420, minHeight: 320)
|
|
#endif
|
|
}
|
|
}
|
|
|
|
private struct ApprovalSheet: View {
|
|
let state: ApprovalState
|
|
let request: PendingApproval
|
|
let onAccept: (String) -> Void
|
|
let onRefuse: (String) -> Void
|
|
|
|
var body: some View {
|
|
let busy = state.respondingIds.contains(request.id)
|
|
let receiver = request.receiverName ?? request.receiverDeviceName ?? String(localized: L10n.Approval.nearbyDevice)
|
|
VStack(spacing: 16) {
|
|
Image(systemName: "checkmark.shield.fill")
|
|
.font(.system(size: 44))
|
|
.foregroundStyle(.tint)
|
|
.padding(.top, 12)
|
|
Text(String(localized: L10n.Approval.connectionRequest))
|
|
.font(.title2).fontWeight(.semibold)
|
|
Text(L10n.Approval.requestBody(receiver: receiver, transferName: request.transferName))
|
|
.multilineTextAlignment(.center)
|
|
Text(L10n.Approval.endpointId(deviceId: request.remoteEndpointId))
|
|
.font(.caption).foregroundStyle(.secondary)
|
|
.multilineTextAlignment(.center)
|
|
if state.pending.count > 1 {
|
|
Text(L10n.Approval.pendingCount(count: state.pending.count))
|
|
.font(.caption).foregroundStyle(.secondary)
|
|
}
|
|
Spacer(minLength: 0)
|
|
if busy { ProgressView() }
|
|
VStack(spacing: 10) {
|
|
Button(action: { onAccept(request.id) }) {
|
|
Text(String(localized: L10n.Button.approve)).frame(maxWidth: .infinity)
|
|
}
|
|
.buttonStyle(.borderedProminent).controlSize(.large).disabled(busy)
|
|
Button(role: .destructive, action: { onRefuse(request.id) }) {
|
|
Text(String(localized: L10n.Button.refuse)).frame(maxWidth: .infinity)
|
|
}
|
|
.buttonStyle(.bordered).controlSize(.large).disabled(busy)
|
|
}
|
|
}
|
|
.padding(24)
|
|
}
|
|
}
|