PrintToVeraeTimeStamp/platform/macos/airdrop/main.swift
Cursor Agent 927229ab4f
AirDrop stamped PDFs from the macOS menu bar.
The menu-bar app, not the root daemon, opens the AirDrop share sheet for each finished job when the setting is on. The unsigned arm64 package installs the daemon and LaunchAgent, and Darwin DNSServiceRegister advertises the _universal and _print subtypes.

Co-authored-by: George Lambert <marchon@gmail.com>
2026-10-05 01:27:23 +00:00

39 lines
1.3 KiB
Swift

import AppKit
// verae-airdrop opens the AirDrop share sheet for the files it is given.
// The menu-bar app launches this helper when it is installed next to
// verae-print. The same NSSharingService call lives in the menu-bar app
// for builds that do not include this helper.
//
// Usage: verae-airdrop certificate.pdf receipt.json
final class AirDropDelegate: NSObject, NSSharingServiceDelegate {
func sharingService(_ sharingService: NSSharingService, didShareItems items: [Any]) {
exit(0)
}
func sharingService(_ sharingService: NSSharingService, didFailToShareItems items: [Any], error: Error) {
fputs("AirDrop failed: \(error.localizedDescription)\n", stderr)
exit(1)
}
}
let paths = Array(CommandLine.arguments.dropFirst()).filter { !$0.isEmpty }
if paths.isEmpty {
fputs("usage: verae-airdrop certificate.pdf [receipt.json]\n", stderr)
exit(2)
}
let app = NSApplication.shared
app.setActivationPolicy(.accessory)
let delegate = AirDropDelegate()
guard let service = NSSharingService(named: .sendViaAirDrop) else {
fputs("AirDrop sharing service is unavailable\n", stderr)
exit(1)
}
service.delegate = delegate
let urls = paths.map { URL(fileURLWithPath: $0) }
app.activate(ignoringOtherApps: true)
service.perform(withItems: urls)
RunLoop.main.run(until: Date().addingTimeInterval(600))
exit(0)