Clean up properties and init/invalidate in FileProviderExtension

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2024-02-05 16:56:12 +08:00
parent 179a368f9f
commit cac263f174

View file

@ -25,16 +25,17 @@ import OSLog
lazy var ncKitBackground = NKBackground(nkCommonInstance: ncKit.nkCommonInstance) lazy var ncKitBackground = NKBackground(nkCommonInstance: ncKit.nkCommonInstance)
lazy var socketClient: LocalSocketClient? = { lazy var socketClient: LocalSocketClient? = {
guard let containerUrl = pathForAppGroupContainer() else { guard let containerUrl = pathForAppGroupContainer() else {
Logger.fileProviderExtension.critical("Won't start client, no container url") Logger.fileProviderExtension.critical("Won't start socket client, no container url")
return nil return nil;
} }
let socketPath = containerUrl.appendingPathComponent( let socketPath = containerUrl.appendingPathComponent(
".fileprovidersocket", conformingTo: .archive) ".fileprovidersocket", conformingTo: .archive)
let lineProcessor = FileProviderSocketLineProcessor(delegate: self) let lineProcessor = FileProviderSocketLineProcessor(delegate: self)
return LocalSocketClient(socketPath: socketPath.path, lineProcessor: lineProcessor) return LocalSocketClient(socketPath: socketPath.path, lineProcessor: lineProcessor)
}() }()
let urlSessionIdentifier: String = "com.nextcloud.session.upload.fileproviderext" let urlSessionIdentifier = "com.nextcloud.session.upload.fileproviderext"
let urlSessionMaximumConnectionsPerHost = 5 let urlSessionMaximumConnectionsPerHost = 5
lazy var urlSession: URLSession = { lazy var urlSession: URLSession = {
let configuration = URLSessionConfiguration.background(withIdentifier: urlSessionIdentifier) let configuration = URLSessionConfiguration.background(withIdentifier: urlSessionIdentifier)
@ -46,8 +47,10 @@ import OSLog
configuration.sharedContainerIdentifier = appGroupIdentifier configuration.sharedContainerIdentifier = appGroupIdentifier
let session = URLSession( let session = URLSession(
configuration: configuration, delegate: ncKitBackground, configuration: configuration,
delegateQueue: OperationQueue.main) delegate: ncKitBackground,
delegateQueue: OperationQueue.main
)
return session return session
}() }()
@ -77,7 +80,8 @@ import OSLog
func invalidate() { func invalidate() {
// TODO: cleanup any resources // TODO: cleanup any resources
Logger.fileProviderExtension.debug( Logger.fileProviderExtension.debug(
"Extension for domain \(self.domain.displayName, privacy: .public) is being torn down") "Extension for domain \(self.domain.displayName, privacy: .public) is being torn down"
)
} }
// MARK: NSFileProviderReplicatedExtension protocol methods // MARK: NSFileProviderReplicatedExtension protocol methods