mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 10:29:58 +02:00
refactor(apple): make InvitationError typed and localize NFC prompts
Replace the free-form InvitationError.message(String) case with semantic
cases mapped to L10n keys at the UI boundary (Error.uiText), so user-facing
error text is localized instead of substring-matched from English blobs.
.raw(String) remains only for genuinely dynamic system/core messages.
Localize the CoreNFC alertMessage prompts via existing L10n keys, and add
SwiftLint rules (raw_alert_message, raw_invitation_error) to catch raw
alert strings and literal .raw("…") errors going forward.
This commit is contained in:
@@ -5,6 +5,9 @@ import VnidropCore
|
||||
/// `ui/feedback/UserFacingError.kt`. Never exposes raw `reason=` blobs.
|
||||
extension Error {
|
||||
func toUiText() -> UiText {
|
||||
if let invitation = self as? InvitationError {
|
||||
return invitation.uiText
|
||||
}
|
||||
if let vni = self as? VnidropError {
|
||||
switch vni {
|
||||
case .Ticket:
|
||||
@@ -40,6 +43,7 @@ extension Error {
|
||||
|
||||
/// True when the user intentionally backed out of a flow.
|
||||
var isUserCancellation: Bool {
|
||||
if let invitation = self as? InvitationError, case .cancelled = invitation { return true }
|
||||
if let vni = self as? VnidropError, case .Cancelled = vni { return true }
|
||||
let haystack = technicalDetail.lowercased()
|
||||
if haystack.isEmpty {
|
||||
@@ -76,6 +80,39 @@ extension Error {
|
||||
}
|
||||
}
|
||||
|
||||
/// Maps each semantic `InvitationError` case to a localized user-facing message.
|
||||
/// This is the sole `InvitationError` → `L10n` boundary: no substring guessing,
|
||||
/// except for `.raw`, whose dynamic payload still falls through `reasonHints`.
|
||||
extension InvitationError {
|
||||
var uiText: UiText {
|
||||
switch self {
|
||||
case .empty:
|
||||
return .resource(L10n.Error.invitationEmpty)
|
||||
case .tooLarge, .unsupportedOperation, .noWindowAvailable,
|
||||
.viewControllerUnavailable, .qrUnavailable, .bugReportingUnavailable, .cancelled:
|
||||
return .resource(L10n.Error.generic)
|
||||
case .invalidEncoding, .invalidInvitationURL:
|
||||
return .resource(L10n.Error.invalidTicket)
|
||||
case .shareEmpty:
|
||||
return .resource(L10n.Error.shareEmpty)
|
||||
case .coreNotInitialized:
|
||||
return .resource(L10n.Error.startingUp)
|
||||
case .filesystemUnavailable:
|
||||
return .resource(L10n.Error.filesystem)
|
||||
case .nfcUnavailable, .nfcFailed:
|
||||
return .resource(L10n.Error.nfc)
|
||||
case .cameraUnavailable:
|
||||
return .resource(L10n.Error.camera)
|
||||
case .selectionFailed:
|
||||
return .resource(L10n.Error.selectionFailed)
|
||||
case .deleteRecordsFailed:
|
||||
return .resource(L10n.Error.repository)
|
||||
case .raw(let reason):
|
||||
return reasonHints(reason) ?? .resource(L10n.Error.generic)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Maps a receiver delivery/refusal reason code to a user-facing message, never
|
||||
/// surfacing the raw core code (e.g. `destination_exists`). Unknown codes fall back
|
||||
/// to the substring hints, then a generic message.
|
||||
|
||||
Reference in New Issue
Block a user