--- /dev/null
+//
+// FileProviderCommunication.swift
+// FileProviderUIExt
+//
+// Created by Claudio Cambra on 30/7/24.
+//
+
+import FileProvider
+
+enum FileProviderCommunicationError: Error {
+ case serviceNotFound
+ case remoteProxyObjectInvalid
+}
+
+func serviceConnection(
+ url: URL, interruptionHandler: @escaping () -> Void
+) async throws -> FPUIExtensionService {
+ let services = try await FileManager().fileProviderServicesForItem(at: url)
+ guard let service = services[fpUiExtensionServiceName] else {
+ throw FileProviderCommunicationError.serviceNotFound
+ }
+ let connection: NSXPCConnection
+ connection = try await service.fileProviderConnection()
+ connection.remoteObjectInterface = NSXPCInterface(with: FPUIExtensionService.self)
+ connection.interruptionHandler = interruptionHandler
+ connection.resume()
+ guard let proxy = connection.remoteObjectProxy as? FPUIExtensionService else {
+ throw FileProviderCommunicationError.remoteProxyObjectInvalid
+ }
+ return proxy
+}
}
do {
- let connection = try await serviceConnection(url: itemURL)
+ let connection = try await serviceConnection(url: itemURL, interruptionHandler: {
+ Logger.sharesDataSource.error("Service connection interrupted")
+ })
guard let serverPath = await connection.itemServerPath(identifier: itemIdentifier),
let credentials = await connection.credentials() as? Dictionary<String, String>,
let convertedAccount = Account(dictionary: credentials),
}
}
- private func serviceConnection(url: URL) async throws -> FPUIExtensionService {
- let services = try await FileManager().fileProviderServicesForItem(at: url)
- guard let service = services[fpUiExtensionServiceName] else {
- Logger.sharesDataSource.error("Couldn't get service, required service not present")
- throw NSFileProviderError(.providerNotFound)
- }
- let connection: NSXPCConnection
- connection = try await service.fileProviderConnection()
- connection.remoteObjectInterface = NSXPCInterface(with: FPUIExtensionService.self)
- connection.interruptionHandler = {
- Logger.sharesDataSource.error("Service connection interrupted")
- }
- connection.resume()
- guard let proxy = connection.remoteObjectProxy as? FPUIExtensionService else {
- throw NSFileProviderError(.serverUnreachable)
- }
- return proxy
- }
-
private func fetch(
itemIdentifier: NSFileProviderItemIdentifier, itemRelativePath: String
) async -> [NKShare] {
537630982B8612F00026BFAB /* FPUIExtensionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 537630962B860D920026BFAB /* FPUIExtensionService.swift */; };
537BD67A2C58D67800446ED0 /* LockViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 537BD6792C58D67800446ED0 /* LockViewController.swift */; };
537BD67C2C58D7B700446ED0 /* LockViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 537BD67B2C58D7B700446ED0 /* LockViewController.xib */; };
+ 537BD6802C58F01B00446ED0 /* FileProviderCommunication.swift in Sources */ = {isa = PBXBuildFile; fileRef = 537BD67F2C58F01B00446ED0 /* FileProviderCommunication.swift */; };
538E396A27F4765000FA63D5 /* UniformTypeIdentifiers.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 538E396927F4765000FA63D5 /* UniformTypeIdentifiers.framework */; };
538E396D27F4765000FA63D5 /* FileProviderExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 538E396C27F4765000FA63D5 /* FileProviderExtension.swift */; };
538E397627F4765000FA63D5 /* FileProviderExt.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 538E396727F4765000FA63D5 /* FileProviderExt.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
537630962B860D920026BFAB /* FPUIExtensionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FPUIExtensionService.swift; sourceTree = "<group>"; };
537BD6792C58D67800446ED0 /* LockViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LockViewController.swift; sourceTree = "<group>"; };
537BD67B2C58D7B700446ED0 /* LockViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LockViewController.xib; sourceTree = "<group>"; };
+ 537BD67F2C58F01B00446ED0 /* FileProviderCommunication.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileProviderCommunication.swift; sourceTree = "<group>"; };
538E396727F4765000FA63D5 /* FileProviderExt.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = FileProviderExt.appex; sourceTree = BUILT_PRODUCTS_DIR; };
538E396927F4765000FA63D5 /* UniformTypeIdentifiers.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UniformTypeIdentifiers.framework; path = System/Library/Frameworks/UniformTypeIdentifiers.framework; sourceTree = SDKROOT; };
538E396C27F4765000FA63D5 /* FileProviderExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileProviderExtension.swift; sourceTree = "<group>"; };
537BD6782C58D0FC00446ED0 /* Locking */,
537BD6772C58D0C400446ED0 /* Sharing */,
53B979802B84C81F002DA742 /* DocumentActionViewController.swift */,
+ 537BD67F2C58F01B00446ED0 /* FileProviderCommunication.swift */,
53FE14572B8E3A7C006C4193 /* FileProviderUIExt.entitlements */,
53B979852B84C81F002DA742 /* Info.plist */,
);
53FE14592B8E3F6C006C4193 /* ShareTableItemView.swift in Sources */,
5376307D2B85E2ED0026BFAB /* Logger+Extensions.swift in Sources */,
53FE14502B8E0658006C4193 /* ShareTableViewDataSource.swift in Sources */,
+ 537BD6802C58F01B00446ED0 /* FileProviderCommunication.swift in Sources */,
537630982B8612F00026BFAB /* FPUIExtensionService.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;