Repository Public License
1// ORIX Convert — App/Sources/Features/Integration/ServicesProvider.swift2// Description: The macOS Services entry "Convert with ORIX Convert" (Finder › Services, and the Services menu of any3// app whose selection is files): the selected files and folders are staged in the Convert workspace,4// exactly as if they had been dropped on the window. Declared in Info.plist (NSServices).5// Author: Simon-Pierre Boucher — contact@spboucher.ai6import AppKit78final class ServicesProvider: NSObject {9 private let model: AppModel10 /// File URLs received by the last invocation (read by the self-test).11 private(set) var lastReceived: [URL] = []1213 init(model: AppModel) { self.model = model }1415 /// File URLs on a pasteboard: modern file-URL items first, then the legacy file-name list some senders use.16 static func fileURLs(on pasteboard: NSPasteboard) -> [URL] {17 var urls = (pasteboard.readObjects(forClasses: [NSURL.self], options: [.urlReadingFileURLsOnly: true]) as? [URL]) ?? []18 if urls.isEmpty, let names = pasteboard.propertyList(forType: NSPasteboard.PasteboardType("NSFilenamesPboardType")) as? [String] {19 urls = names.map { URL(fileURLWithPath: $0) }20 }21 var seen = Set<String>()22 return urls.filter { $0.isFileURL && FileManager.default.fileExists(atPath: $0.path) && seen.insert($0.standardizedFileURL.path).inserted }23 }2425 /// `NSMessage` of the service (Info.plist): `convertFiles`.26 @objc func convertFiles(_ pasteboard: NSPasteboard, userData: String?, error: AutoreleasingUnsafeMutablePointer<NSString>) {27 let urls = Self.fileURLs(on: pasteboard)28 lastReceived = urls29 guard !urls.isEmpty else {30 error.pointee = L("ORIX Convert received no file. Select files or folders in the Finder first.") as NSString31 return32 }33 model.ingest(urls: urls)34 if !model.launch.isAutomated { model.showMainWindow() }35 }36}37