mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 18:39:55 +02:00
Add a native SwiftUI VniDrop app (Send/Receive/Settings) talking to the Rust core via generated UniFFI Swift bindings, plus the uniffi-bindgen helper crate. iOS uses a TabView, macOS a NavigationSplitView sidebar.
46 lines
1.5 KiB
Swift
46 lines
1.5 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.message("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.message("QR scanning is unavailable on macOS")))
|
|
}
|
|
|
|
func readNfcInvitation(onResult: @escaping (Result<String, Error>) -> Void) {
|
|
onResult(.failure(InvitationError.message("NFC is unavailable on macOS")))
|
|
}
|
|
|
|
func cancel() {}
|
|
}
|
|
#endif
|