shell_integration/macOS/FileProviderExt: Adapt to API changes in NextcloudFileProviderKit changes in 2.0

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
Claudio Cambra 2024-12-04 16:34:57 +08:00 committed by Matthieu Gallien
parent 778a6cf470
commit a08a425083
3 changed files with 46 additions and 26 deletions

View File

@ -107,14 +107,25 @@ extension FileProviderExtension: NSFileProviderServicing, ChangeNotificationInte
@objc func setupDomainAccount(
user: String, userId: String, serverUrl: String, password: String
) {
let account = Account(user: user, id: userId, serverUrl: serverUrl, password: password)
guard account != ncAccount else { return }
Task {
let authTestNcKit = NextcloudKit()
authTestNcKit.setup(user: user, userId: userId, password: password, urlBase: serverUrl)
ncKit.appendSession(
account: account.ncKitAccount,
urlBase: serverUrl,
user: user,
userId: userId,
password: password,
userAgent: "Nextcloud-macOS/FileProviderExt",
nextcloudVersion: 25,
groupIdentifier: ""
)
var authAttemptState = AuthenticationAttemptResultState.connectionError // default
// Retry a few times if we have a connection issue
for authTimeout in AuthenticationTimeouts {
authAttemptState = await authTestNcKit.tryAuthenticationAttempt()
authAttemptState = await ncKit.tryAuthenticationAttempt(account: account)
guard authAttemptState == .connectionError else { break }
Logger.fileProviderExtension.info(
@ -146,22 +157,12 @@ extension FileProviderExtension: NSFileProviderServicing, ChangeNotificationInte
}
Task { @MainActor in
let newNcAccount =
Account(user: user, id: userId, serverUrl: serverUrl, password: password)
guard newNcAccount != ncAccount else { return }
ncAccount = newNcAccount
ncKit.setup(
account: newNcAccount.ncKitAccount,
user: newNcAccount.username,
userId: newNcAccount.id,
password: newNcAccount.password,
urlBase: newNcAccount.serverUrl,
userAgent: "Nextcloud-macOS/FileProviderExt",
nextcloudVersion: 25,
delegate: nil) // TODO: add delegate methods for self
ncAccount = account
changeObserver = RemoteChangeObserver(
remoteInterface: ncKit, changeNotificationInterface: self, domain: domain
account: account,
remoteInterface: ncKit,
changeNotificationInterface: self,
domain: domain
)
ncKit.setup(delegate: changeObserver)
signalEnumeratorAfterAccountSetup()

View File

@ -29,9 +29,15 @@ extension FileProviderExtension: NSFileProviderThumbnailing {
) -> Void,
completionHandler: @escaping (Error?) -> Void
) -> Progress {
guard let ncAccount else {
completionHandler(NSFileProviderError(.notAuthenticated))
return Progress()
}
return NextcloudFileProviderKit.fetchThumbnails(
for: itemIdentifiers,
requestedSize: size,
account: ncAccount,
usingRemoteInterface: self.ncKit,
perThumbnailCompletionHandler: perThumbnailCompletionHandler,
completionHandler: completionHandler

View File

@ -20,7 +20,7 @@ import OSLog
@objc class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension {
let domain: NSFileProviderDomain
let ncKit = NextcloudKit()
let ncKit = NextcloudKit.shared
let appGroupIdentifier = Bundle.main.object(forInfoDictionaryKey: "SocketApiPrefix") as? String
var ncAccount: Account?
var changeObserver: RemoteChangeObserver?
@ -104,7 +104,7 @@ import OSLog
request _: NSFileProviderRequest,
completionHandler: @escaping (NSFileProviderItem?, Error?) -> Void
) -> Progress {
if ncAccount == nil {
guard let ncAccount else {
Logger.fileProviderExtension.error(
"""
Not fetching item for identifier: \(identifier.rawValue, privacy: .public)
@ -112,7 +112,12 @@ import OSLog
"""
)
completionHandler(nil, NSFileProviderError(.notAuthenticated))
} else if let item = Item.storedItem(identifier: identifier, remoteInterface: ncKit) {
return Progress()
}
if let item = Item.storedItem(
identifier: identifier, account: ncAccount, remoteInterface: ncKit
) {
completionHandler(item, nil)
} else {
completionHandler(nil, NSFileProviderError(.noSuchItem))
@ -147,7 +152,7 @@ import OSLog
return Progress()
}
guard ncAccount != nil else {
guard let ncAccount else {
Logger.fileProviderExtension.error(
"""
Not fetching contents for item: \(itemIdentifier.rawValue, privacy: .public)
@ -159,7 +164,9 @@ import OSLog
return Progress()
}
guard let item = Item.storedItem(identifier: itemIdentifier, remoteInterface: ncKit) else {
guard let item = Item.storedItem(
identifier: itemIdentifier, account: ncAccount, remoteInterface: ncKit
) else {
Logger.fileProviderExtension.error(
"""
Not fetching contents for item: \(itemIdentifier.rawValue, privacy: .public)
@ -228,6 +235,7 @@ import OSLog
contents: url,
request: request,
domain: self.domain,
account: ncAccount,
remoteInterface: ncKit,
progress: progress
)
@ -283,7 +291,9 @@ import OSLog
return Progress()
}
guard let existingItem = Item.storedItem(identifier: identifier, remoteInterface: ncKit) else {
guard let existingItem = Item.storedItem(
identifier: identifier, account: ncAccount, remoteInterface: ncKit
) else {
Logger.fileProviderExtension.error(
"Not modifying item: \(ocId, privacy: .public) as item not found."
)
@ -331,7 +341,7 @@ import OSLog
"Received delete request for item: \(identifier.rawValue, privacy: .public)"
)
guard ncAccount != nil else {
guard let ncAccount else {
Logger.fileProviderExtension.error(
"Not deleting item \(identifier.rawValue, privacy: .public), account not set up yet"
)
@ -340,7 +350,9 @@ import OSLog
return Progress()
}
guard let item = Item.storedItem(identifier: identifier, remoteInterface: ncKit) else {
guard let item = Item.storedItem(
identifier: identifier, account: ncAccount, remoteInterface: ncKit
) else {
Logger.fileProviderExtension.error(
"Not deleting item \(identifier.rawValue, privacy: .public), item not found"
)
@ -376,6 +388,7 @@ import OSLog
return Enumerator(
enumeratedItemIdentifier: containerItemIdentifier,
account: ncAccount,
remoteInterface: ncKit,
domain: domain,
fastEnumeration: config.fastEnumerationEnabled,