mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 02:29:55 +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.
49 lines
1.6 KiB
Swift
49 lines
1.6 KiB
Swift
#if os(macOS)
|
|
import AppKit
|
|
import SwiftUI
|
|
|
|
@MainActor
|
|
func makePlatformShareActions() -> TransferShareActions { MacTransferShareActions() }
|
|
|
|
/// macOS invitation delivery, mirroring the iOS actions: save panel export and
|
|
/// `NSSharingServicePicker` native share. NFC is unavailable on macOS.
|
|
final class MacTransferShareActions: TransferShareActions {
|
|
var canUseNativeShare: Bool { true }
|
|
var nfcAvailability: NfcShareAvailability { .hidden }
|
|
|
|
func exportInvitation(ticket: String, transferName: String, onResult: @escaping (Result<Void, Error>) -> Void) {
|
|
let panel = NSSavePanel()
|
|
panel.nameFieldStringValue = invitationFileName(transferName)
|
|
panel.allowedContentTypes = []
|
|
panel.begin { response in
|
|
guard response == .OK, let url = panel.url else {
|
|
onResult(.failure(InvitationError.cancelled))
|
|
return
|
|
}
|
|
onResult(Result { try ticket.write(to: url, atomically: true, encoding: .utf8) })
|
|
}
|
|
}
|
|
|
|
func shareInvitation(ticket: String, transferName: String, onResult: @escaping (Result<Void, Error>) -> Void) {
|
|
do {
|
|
let url = try writeTemporaryInvitation(ticket: ticket, transferName: transferName)
|
|
guard let view = NSApp.keyWindow?.contentView else {
|
|
onResult(.failure(InvitationError.noWindowAvailable))
|
|
return
|
|
}
|
|
let picker = NSSharingServicePicker(items: [url])
|
|
picker.show(relativeTo: .zero, of: view, preferredEdge: .minY)
|
|
onResult(.success(()))
|
|
} catch {
|
|
onResult(.failure(error))
|
|
}
|
|
}
|
|
|
|
func writeInvitationToNfc(ticket: String, onResult: @escaping (Result<Void, Error>) -> Void) {
|
|
onResult(.failure(InvitationError.nfcUnavailable))
|
|
}
|
|
|
|
func cancelNfcWrite() {}
|
|
}
|
|
#endif
|