Skip to content

Commit

Permalink
feat: Added an ExpiringActivity to initFileProviderDomains
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-coye committed Feb 28, 2024
1 parent ef191a9 commit a2a04bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public extension DriveInfosManager {
private typealias FilteredDomain = (new: NSFileProviderDomain, existing: NSFileProviderDomain?)

internal func initFileProviderDomains(drives: [Drive], user: InfomaniakCore.UserProfile) {
let expiringActivity = ExpiringActivity(id: "\(#function)_\(UUID().uuidString)", delegate: nil)
expiringActivity.start()

// Clean file provider storage if needed
if UserDefaults.shared.fpStorageVersion < currentFpStorageVersion {
do {
Expand All @@ -42,6 +45,12 @@ public extension DriveInfosManager {
}
}

guard !expiringActivity.shouldTerminate else {
// Sentry
expiringActivity.endAll()
return
}

// TODO: Start Activity
Task {
let updatedDomains = drives.map {
Expand Down Expand Up @@ -94,7 +103,7 @@ public extension DriveInfosManager {
// TODO: add Sentry
}

// TODO: notify for consistency
expiringActivity.endAll()
}
}

Expand Down Expand Up @@ -123,17 +132,6 @@ public extension DriveInfosManager {
}
}

internal func getFileProviderDomain(for driveId: String, completion: @escaping (NSFileProviderDomain?) -> Void) {
NSFileProviderManager.getDomainsWithCompletionHandler { domains, error in
if let error {
DDLogError("Error while getting domains: \(error)")
completion(nil)
} else {
completion(domains.first { $0.identifier.rawValue == driveId })
}
}
}

func getFileProviderManager(for drive: Drive, completion: @escaping (NSFileProviderManager) -> Void) {
getFileProviderManager(for: drive.objectId, completion: completion)
}
Expand All @@ -153,6 +151,17 @@ public extension DriveInfosManager {
}
}

private func getFileProviderDomain(for driveId: String, completion: @escaping (NSFileProviderDomain?) -> Void) {
NSFileProviderManager.getDomainsWithCompletionHandler { domains, error in
if let error {
DDLogError("Error while getting domains: \(error)")
completion(nil)
} else {
completion(domains.first { $0.identifier.rawValue == driveId })
}
}
}

// MARK: Signal

/// Signal changes on this Drive to the File Provider Extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/

import CocoaLumberjackSwift
import FileProvider
import Foundation
import InfomaniakCore
import Realm
Expand Down

0 comments on commit a2a04bb

Please sign in to comment.