mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 02:29:55 +02:00
feat(apple): native SwiftUI app for iOS and macOS
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.
This commit is contained in:
45
apple/VniDrop/Platform/ReceiveInvitationActions+macOS.swift
Normal file
45
apple/VniDrop/Platform/ReceiveInvitationActions+macOS.swift
Normal file
@@ -0,0 +1,45 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user