mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 10:29:58 +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:
48
apple/VniDrop/Platform/TransferShareActions+macOS.swift
Normal file
48
apple/VniDrop/Platform/TransferShareActions+macOS.swift
Normal file
@@ -0,0 +1,48 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user