From e7e958ed8257a75671e90a1653ba72814ec21498 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 30 Sep 2024 13:46:47 +0800 Subject: [PATCH] Try to authenticate new account details before setting them Signed-off-by: Claudio Cambra --- ...ileProviderExtension+ClientInterface.swift | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension+ClientInterface.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension+ClientInterface.swift index 61f0a0605..7d439245d 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension+ClientInterface.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension+ClientInterface.swift @@ -119,11 +119,28 @@ extension FileProviderExtension: NSFileProviderServicing, ChangeNotificationInte ) ncKit.setup(delegate: changeObserver) - Logger.fileProviderExtension.info( - "Nextcloud account set up in File Provider extension for user: \(user, privacy: .public) at server: \(serverUrl, privacy: .public)" - ) - - signalEnumeratorAfterAccountSetup() + Task { + switch (await ncKit.tryAuthenticationAttempt()) { + case .authenticationError: + Logger.fileProviderExtension.info( + "\(user, privacy: .public) authentication failed due to bad creds, stopping" + ) + ncAccount = nil + ncKit.setup(user: "", userId: "", password: "", urlBase: "") // In case ongoing ops + case .connectionError: + Logger.fileProviderExtension.info( + "\(user, privacy: .public) authentication try failed due to internet connectivity issues." + ) + case .success: + Logger.fileProviderExtension.info( + """ + Authenticated! Nextcloud account set up in File Provider extension. + User: \(user, privacy: .public) at server: \(serverUrl, privacy: .public) + """ + ) + Task { @MainActor in signalEnumeratorAfterAccountSetup() } + } + } } @objc func removeAccountConfig() {