mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 10:29:58 +02:00
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.
46 lines
1.4 KiB
Swift
46 lines
1.4 KiB
Swift
#if os(macOS)
|
|
import AppKit
|
|
import UniformTypeIdentifiers
|
|
|
|
@MainActor
|
|
func makeReceiveInvitationActions() -> ReceiveInvitationActions { MacReceiveInvitationActions() }
|
|
|
|
/// macOS invitation acquisition: file picker only. QR (camera) and NFC are hidden
|
|
/// on the desktop, matching the availability model.
|
|
final class MacReceiveInvitationActions: ReceiveInvitationActions {
|
|
var fileAvailability: ReceiveMethodAvailability { .available }
|
|
var qrAvailability: ReceiveMethodAvailability { .hidden }
|
|
var nfcAvailability: ReceiveMethodAvailability { .hidden }
|
|
|
|
func pickInvitation(onResult: @escaping (Result<String, Error>) -> Void) {
|
|
let panel = NSOpenPanel()
|
|
panel.canChooseFiles = true
|
|
panel.canChooseDirectories = false
|
|
panel.allowsMultipleSelection = false
|
|
if let vnd = UTType(filenameExtension: vniDropInvitationExtension) {
|
|
panel.allowedContentTypes = [vnd, .data, .text]
|
|
}
|
|
panel.begin { response in
|
|
guard response == .OK, let url = panel.url else {
|
|
onResult(.failure(InvitationError.cancelled))
|
|
return
|
|
}
|
|
onResult(Result {
|
|
let data = try Data(contentsOf: url)
|
|
return try decodeInvitationBytes(data)
|
|
})
|
|
}
|
|
}
|
|
|
|
func scanQrCode(onResult: @escaping (Result<String, Error>) -> Void) {
|
|
onResult(.failure(InvitationError.qrUnavailable))
|
|
}
|
|
|
|
func readNfcInvitation(onResult: @escaping (Result<String, Error>) -> Void) {
|
|
onResult(.failure(InvitationError.nfcUnavailable))
|
|
}
|
|
|
|
func cancel() {}
|
|
}
|
|
#endif
|