mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-28 19:58:56 +03:00
Add URLSession to FileProviderExtension
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
parent
4efb234f68
commit
e319516b89
1 changed files with 18 additions and 3 deletions
|
@ -15,12 +15,29 @@
|
||||||
import FileProvider
|
import FileProvider
|
||||||
import OSLog
|
import OSLog
|
||||||
import NCDesktopClientSocketKit
|
import NCDesktopClientSocketKit
|
||||||
|
import NextcloudKit
|
||||||
|
|
||||||
class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension {
|
class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension {
|
||||||
let domain: NSFileProviderDomain
|
let domain: NSFileProviderDomain
|
||||||
|
|
||||||
|
let appGroupIdentifier: String? = Bundle.main.object(forInfoDictionaryKey: "SocketApiPrefix") as? String
|
||||||
var socketClient: LocalSocketClient = LocalSocketClient()
|
var socketClient: LocalSocketClient = LocalSocketClient()
|
||||||
var ncAccount: FileProviderDomainNextcloudAccountData = FileProviderDomainNextcloudAccountData()
|
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) {
|
required init(domain: NSFileProviderDomain) {
|
||||||
self.domain = domain
|
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.
|
// 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
|
// MARK: Nextcloud desktop client communication
|
||||||
|
|
||||||
func startLocalSocketClient() {
|
func startLocalSocketClient() {
|
||||||
let bundle = Bundle(for: type(of: self))
|
guard let fileProviderSocketApiPrefix = appGroupIdentifier else {
|
||||||
guard let fileProviderSocketApiPrefix = bundle.object(forInfoDictionaryKey: "SocketApiPrefix") as? String else {
|
|
||||||
NSLog("Could not start file provider socket client properly as SocketApiPrefix is missing")
|
NSLog("Could not start file provider socket client properly as SocketApiPrefix is missing")
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue