Browse Source

Add FileProviderDomain.swift

marinofaggiana 5 years ago
parent
commit
d42946faa1

+ 78 - 0
File Provider Extension/FileProviderDomain.swift

@@ -0,0 +1,78 @@
+//
+//  FileProviderDomain.swift
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 04/06/2019.
+//  Copyright © 2018 Marino Faggiana. All rights reserved.
+//
+//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+import Foundation
+
+class FileProviderDomain: NSObject {
+    @objc static let sharedInstance: FileProviderDomain = {
+        let instance = FileProviderDomain()
+        return instance
+    }()
+
+    @available(iOS 11.0, *)
+    
+    @objc func registerDomain() {
+        
+        NSFileProviderManager.getDomainsWithCompletionHandler { (fileProviderDomain, error) in
+            
+            var domains = [String]()
+            let pathRelativeToDocumentStorage = NSFileProviderManager.default.documentStorageURL.absoluteString
+            let tableAccounts = NCManageDatabase.sharedInstance.getAllAccount()
+            
+            for domain in fileProviderDomain {
+                domains.append(domain.identifier.rawValue)
+            }
+            
+            // Check account->domain & (add)
+            for tableAccount in tableAccounts {
+                guard let url = NSURL(string: tableAccount.url) else {
+                    continue
+                }
+                guard let host = url.host else {
+                    continue
+                }
+                let accountDomain =  tableAccount.userID + " (" + host + ")"
+                if domains.contains(accountDomain) {
+                    domains = domains.filter() {$0 != accountDomain}
+                } else {
+                    let domainRawValue = NSFileProviderDomain(identifier: NSFileProviderDomainIdentifier(rawValue: accountDomain), displayName: accountDomain, pathRelativeToDocumentStorage: pathRelativeToDocumentStorage)
+                    NSFileProviderManager.add(domainRawValue, completionHandler: { (error) in
+                        if error != nil {
+                            print("Error  domain: \(domainRawValue) error: \(String(describing: error))")
+                        }
+                    })
+                }
+            }
+            
+            // Check if remove domain
+            for domain in domains {
+                let domainRawValue = NSFileProviderDomain(identifier: NSFileProviderDomainIdentifier(rawValue: domain), displayName: domain, pathRelativeToDocumentStorage: pathRelativeToDocumentStorage)
+                NSFileProviderManager.remove(domainRawValue, completionHandler: { (error) in
+                    if error != nil {
+                        print("Error  domain: \(domainRawValue) error: \(String(describing: error))")
+                    }
+                })
+            }
+        }
+    }
+}

+ 6 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -319,6 +319,8 @@
 		F762CB9B1EACB84400B38484 /* TWMessageBarManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F762CB941EACB84400B38484 /* TWMessageBarManager.m */; };
 		F7632FBF21832F8700721B71 /* NCTrashSectionHeaderMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = F7632FBE21832F8700721B71 /* NCTrashSectionHeaderMenu.xib */; };
 		F7632FC1218353AA00721B71 /* NCTrashSectionFooter.xib in Resources */ = {isa = PBXBuildFile; fileRef = F7632FC0218353AA00721B71 /* NCTrashSectionFooter.xib */; };
+		F76673ED22C901F6007ED366 /* FileProviderDomain.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76673EC22C901F5007ED366 /* FileProviderDomain.swift */; };
+		F76673EE22C901F6007ED366 /* FileProviderDomain.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76673EC22C901F5007ED366 /* FileProviderDomain.swift */; };
 		F76B3CCE1EAE01BD00921AC9 /* NCBrand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76B3CCD1EAE01BD00921AC9 /* NCBrand.swift */; };
 		F76B3CCF1EAE01BD00921AC9 /* NCBrand.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76B3CCD1EAE01BD00921AC9 /* NCBrand.swift */; };
 		F76C6F8E21943C8C0063591B /* NCActionSheetHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = F76C6F8D21943C8C0063591B /* NCActionSheetHeader.swift */; };
@@ -1096,6 +1098,7 @@
 		F7632FC0218353AA00721B71 /* NCTrashSectionFooter.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = NCTrashSectionFooter.xib; sourceTree = "<group>"; };
 		F76344751BF259A800188725 /* synchronized.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = synchronized.gif; sourceTree = "<group>"; };
 		F76344761BF259A800188725 /* synchronizedcrypto.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = synchronizedcrypto.gif; sourceTree = "<group>"; };
+		F76673EC22C901F5007ED366 /* FileProviderDomain.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileProviderDomain.swift; sourceTree = "<group>"; };
 		F768EAFB1BFB7CD800B6E341 /* CCShareOC.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCShareOC.h; sourceTree = "<group>"; };
 		F768EAFC1BFB7CD800B6E341 /* CCShareOC.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCShareOC.m; sourceTree = "<group>"; };
 		F768EB021BFB7EA900B6E341 /* CCShare.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = CCShare.storyboard; sourceTree = "<group>"; };
@@ -2268,6 +2271,7 @@
 		F771E3D120E2392D00AFB62D /* File Provider Extension */ = {
 			isa = PBXGroup;
 			children = (
+				F76673EC22C901F5007ED366 /* FileProviderDomain.swift */,
 				F771E3F220E239A600AFB62D /* FileProviderData.swift */,
 				F771E3D620E2392D00AFB62D /* FileProviderEnumerator.swift */,
 				F771E3D220E2392D00AFB62D /* FileProviderExtension.swift */,
@@ -3531,6 +3535,7 @@
 				F7434B4F20E2408E00417916 /* OCXMLListParser.m in Sources */,
 				F7434B6120E2445C00417916 /* CCCertificate.m in Sources */,
 				F7434B5A20E241BB00417916 /* NCNetworkingEndToEnd.m in Sources */,
+				F76673EE22C901F6007ED366 /* FileProviderDomain.swift in Sources */,
 				F7434B3820E2400600417916 /* NCBrand.swift in Sources */,
 				F7434B6320E249FB00417916 /* NSString+TruncateToWidth.m in Sources */,
 				F7434B5620E2412900417916 /* CCError.m in Sources */,
@@ -3669,6 +3674,7 @@
 				F73B4F0B1F470D9100BBEE4B /* nsGB2312Prober.cpp in Sources */,
 				F762CAFE1EACB66200B38484 /* XLFormLeftRightSelectorCell.m in Sources */,
 				F77B0E301D118A16002130FE /* CCHud.m in Sources */,
+				F76673ED22C901F6007ED366 /* FileProviderDomain.swift in Sources */,
 				F7D423891F0596C6009C9782 /* ReaderViewController.m in Sources */,
 				F70022E91EC4C9100080073F /* OCXMLShareByLinkParser.m in Sources */,
 				F70022E31EC4C9100080073F /* OCXMLParser.m in Sources */,

+ 1 - 1
iOSClient/Main/CCMain.m

@@ -385,7 +385,7 @@
     // Registeration domain File Provider
 #if TARGET_OS_SIMULATOR
     if (@available(iOS 13, *) ) {
-        //[FileProviderDomain.sharedInstance registerDomain];
+        [FileProviderDomain.sharedInstance registerDomain];
     }
 #endif