From e319516b89320b5cfb4752c2b717c3e529acf09a Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 4 Jan 2023 21:09:48 +0100 Subject: [PATCH] Add URLSession to FileProviderExtension Signed-off-by: Claudio Cambra --- .../FileProviderExtension.swift | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension.swift index f31f02b97..15455e755 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension.swift @@ -15,12 +15,29 @@ import FileProvider import OSLog import NCDesktopClientSocketKit +import NextcloudKit class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension { let domain: NSFileProviderDomain + + let appGroupIdentifier: String? = Bundle.main.object(forInfoDictionaryKey: "SocketApiPrefix") as? String var socketClient: LocalSocketClient = LocalSocketClient() var ncAccount: FileProviderDomainNextcloudAccountData = FileProviderDomainNextcloudAccountData() + let urlSessionIdentifier: String = "com.nextcloud.session.upload.fileproviderext" + let urlSessionMaximumConnectionsPerHost = 5 + lazy var urlSession: URLSession = { + let configuration = URLSessionConfiguration.background(withIdentifier: urlSessionIdentifier) + configuration.allowsCellularAccess = true + configuration.sessionSendsLaunchEvents = true + configuration.isDiscretionary = false + configuration.httpMaximumConnectionsPerHost = urlSessionMaximumConnectionsPerHost + configuration.requestCachePolicy = NSURLRequest.CachePolicy.reloadIgnoringLocalCacheData + configuration.sharedContainerIdentifier = appGroupIdentifier + let session = URLSession(configuration: configuration, delegate: NKBackground.shared, delegateQueue: OperationQueue.main) + return session + }() + required init(domain: NSFileProviderDomain) { self.domain = domain // The containing application must create a domain using `NSFileProviderManager.add(_:, completionHandler:)`. The system will then launch the application extension process, call `FileProviderExtension.init(domain:)` to instantiate the extension for that domain, and call methods on the instance. @@ -79,10 +96,8 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension { // MARK: Nextcloud desktop client communication func startLocalSocketClient() { - let bundle = Bundle(for: type(of: self)) - guard let fileProviderSocketApiPrefix = bundle.object(forInfoDictionaryKey: "SocketApiPrefix") as? String else { + guard let fileProviderSocketApiPrefix = appGroupIdentifier else { NSLog("Could not start file provider socket client properly as SocketApiPrefix is missing") - return; } -- 2.30.2