Browse Source

Improvements : setupActiveAccount

Marino Faggiana 6 years ago
parent
commit
daffbc4c4d

+ 11 - 23
PickerFileProvider/FileProviderData.swift

@@ -74,18 +74,6 @@ class FileProviderData: NSObject {
     
     func setupActiveAccount() -> Bool {
         
-        queueTradeSafe.sync(flags: .barrier) {
-            groupURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.sharedInstance.capabilitiesGroups)
-            fileProviderStorageURL = groupURL!.appendingPathComponent(k_assetLocalIdentifierFileProviderStorage)
-        }
-        
-        // Create dir File Provider Storage
-        do {
-            try FileManager.default.createDirectory(atPath: fileProviderStorageURL!.path, withIntermediateDirectories: true, attributes: nil)
-        } catch let error as NSError {
-            NSLog("Unable to create directory \(error.debugDescription)")
-        }
-        
         if CCUtility.getDisableFilesApp() {
             return false
         }
@@ -94,20 +82,20 @@ class FileProviderData: NSObject {
             return false
         }
         
-        if account != "" && account != activeAccount.account {
+        if account == "" {
+            queueTradeSafe.sync(flags: .barrier) {
+                account = activeAccount.account
+                accountUser = activeAccount.user
+                accountUserID = activeAccount.userID
+                accountPassword = activeAccount.password
+                accountUrl = activeAccount.url
+                homeServerUrl = CCUtility.getHomeServerUrlActiveUrl(activeAccount.url)
+                directoryUser = CCUtility.getDirectoryActiveUser(activeAccount.user, activeUrl: activeAccount.url)
+            }
+        } else if account != activeAccount.account {
             assert(false, "change user")
         }
         
-        queueTradeSafe.sync(flags: .barrier) {
-            account = activeAccount.account
-            accountUser = activeAccount.user
-            accountUserID = activeAccount.userID
-            accountPassword = activeAccount.password
-            accountUrl = activeAccount.url
-            homeServerUrl = CCUtility.getHomeServerUrlActiveUrl(activeAccount.url)
-            directoryUser = CCUtility.getDirectoryActiveUser(activeAccount.user, activeUrl: activeAccount.url)
-        }
-        
         return true
     }
     

+ 12 - 0
PickerFileProvider/FileProviderExtension.swift

@@ -69,6 +69,18 @@ class FileProviderExtension: NSFileProviderExtension, CCNetworkingDelegate {
         
         super.init()
         
+        // Get group directiry
+        providerData.groupURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: NCBrandOptions.sharedInstance.capabilitiesGroups)
+        providerData.fileProviderStorageURL = providerData.groupURL!.appendingPathComponent(k_assetLocalIdentifierFileProviderStorage)
+        
+        // Create directory File Provider Storage
+        do {
+            try FileManager.default.createDirectory(atPath: providerData.fileProviderStorageURL!.path, withIntermediateDirectories: true, attributes: nil)
+        } catch let error as NSError {
+            NSLog("Unable to create directory \(error.debugDescription)")
+        }
+        
+        // Setup account
         _ = providerData.setupActiveAccount()
         
         if #available(iOSApplicationExtension 11.0, *) {