2024-02-21 15:29:03 +03:00
|
|
|
//
|
|
|
|
// FPUIExtensionCommunicationService.swift
|
|
|
|
// FileProviderExt
|
|
|
|
//
|
|
|
|
// Created by Claudio Cambra on 21/2/24.
|
|
|
|
//
|
|
|
|
|
|
|
|
import FileProvider
|
|
|
|
import Foundation
|
2024-02-27 15:29:46 +03:00
|
|
|
import NextcloudKit
|
2024-02-21 15:29:03 +03:00
|
|
|
import OSLog
|
|
|
|
|
|
|
|
class FPUIExtensionServiceSource: NSObject, NSFileProviderServiceSource, NSXPCListenerDelegate, FPUIExtensionService {
|
|
|
|
let listener = NSXPCListener.anonymous()
|
|
|
|
let serviceName = fpUiExtensionServiceName
|
|
|
|
let fpExtension: FileProviderExtension
|
|
|
|
|
|
|
|
init(fpExtension: FileProviderExtension) {
|
|
|
|
Logger.fpUiExtensionService.debug("Instantiating FPUIExtensionService service")
|
|
|
|
self.fpExtension = fpExtension
|
|
|
|
super.init()
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeListenerEndpoint() throws -> NSXPCListenerEndpoint {
|
|
|
|
listener.delegate = self
|
|
|
|
listener.resume()
|
|
|
|
return listener.endpoint
|
|
|
|
}
|
|
|
|
|
|
|
|
func listener(
|
|
|
|
_ listener: NSXPCListener,
|
|
|
|
shouldAcceptNewConnection newConnection: NSXPCConnection
|
|
|
|
) -> Bool {
|
2024-02-27 16:24:49 +03:00
|
|
|
newConnection.exportedInterface = NSXPCInterface(with: FPUIExtensionService.self)
|
2024-02-21 15:29:03 +03:00
|
|
|
newConnection.exportedObject = self
|
|
|
|
newConnection.resume()
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
//MARK: - FPUIExtensionService protocol methods
|
|
|
|
|
2024-02-27 15:29:46 +03:00
|
|
|
func shares(
|
|
|
|
forItemIdentifier itemIdentifier: NSFileProviderItemIdentifier
|
|
|
|
) async -> [NKShare]? {
|
|
|
|
let controller = ItemSharesController(
|
|
|
|
itemIdentifier: itemIdentifier, parentExtension: fpExtension
|
|
|
|
)
|
|
|
|
return await controller.fetch()
|
|
|
|
}
|
2024-02-21 15:29:03 +03:00
|
|
|
}
|