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.
49 lines
1.7 KiB
Swift
49 lines
1.7 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.message("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.message("No window available")))
|
|
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.message("NFC is unavailable on macOS")))
|
|
}
|
|
|
|
func cancelNfcWrite() {}
|
|
}
|
|
#endif
|