From 287a4e4c0b1bb731234bee6296610195dd6ac974 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Sat, 11 Mar 2023 15:55:46 +0100 Subject: [PATCH] Unauthenticate the file provider extension when account is logged out Signed-off-by: Claudio Cambra --- .../FileProviderExt/FileProviderExtension.swift | 4 ++++ .../FileProviderSocketLineProcessor.swift | 4 +++- src/gui/macOS/fileprovidersocketcontroller.cpp | 16 +++++++++++++++- src/gui/macOS/fileprovidersocketcontroller.h | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension.swift index c8e252d80..c6e12ec61 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderExtension.swift @@ -628,4 +628,8 @@ class FileProviderExtension: NSObject, NSFileProviderReplicatedExtension, NKComm signalEnumeratorAfterAccountSetup() } + + func removeAccountConfig() { + ncAccount = nil + } } diff --git a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderSocketLineProcessor.swift b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderSocketLineProcessor.swift index 1082baa52..8a46f9d22 100644 --- a/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderSocketLineProcessor.swift +++ b/shell_integration/MacOSX/NextcloudIntegration/FileProviderExt/FileProviderSocketLineProcessor.swift @@ -18,7 +18,7 @@ import NCDesktopClientSocketKit class FileProviderSocketLineProcessor: NSObject, LineProcessor { var delegate: FileProviderExtension - init(delegate: FileProviderExtension) { + required init(delegate: FileProviderExtension) { self.delegate = delegate } @@ -35,6 +35,8 @@ class FileProviderSocketLineProcessor: NSObject, LineProcessor { NSLog("Received command: %@", command) if (command == "SEND_FILE_PROVIDER_DOMAIN_IDENTIFIER") { delegate.sendFileProviderDomainIdentifier() + } else if (command == "ACCOUNT_NOT_AUTHENTICATED") { + delegate.removeAccountConfig() } else if (command == "ACCOUNT_DETAILS") { guard let accountDetailsSubsequence = splitLine.last else { return } let splitAccountDetails = accountDetailsSubsequence.split(separator: "~", maxSplits: 2) diff --git a/src/gui/macOS/fileprovidersocketcontroller.cpp b/src/gui/macOS/fileprovidersocketcontroller.cpp index 57671c371..88bf26adf 100644 --- a/src/gui/macOS/fileprovidersocketcontroller.cpp +++ b/src/gui/macOS/fileprovidersocketcontroller.cpp @@ -148,6 +148,7 @@ void FileProviderSocketController::slotAccountStateChanged(const AccountState::S case AccountState::SignedOut: case AccountState::AskingCredentials: // Notify File Provider that it should show the not authenticated message + sendNotAuthenticated(); break; case AccountState::Connected: // Provide credentials @@ -156,6 +157,19 @@ void FileProviderSocketController::slotAccountStateChanged(const AccountState::S } } +void FileProviderSocketController::sendNotAuthenticated() const +{ + Q_ASSERT(_accountState); + const auto account = _accountState->account(); + Q_ASSERT(account); + + qCDebug(lcFileProviderSocketController) << "About to send not authenticated message to file provider extension" + << account->displayName(); + + const auto message = QString(QStringLiteral("ACCOUNT_NOT_AUTHENTICATED")); + sendMessage(message); +} + void FileProviderSocketController::sendAccountDetails() const { Q_ASSERT(_accountState); @@ -165,7 +179,7 @@ void FileProviderSocketController::sendAccountDetails() const qCDebug(lcFileProviderSocketController) << "About to send account details to file provider extension" << account->displayName(); - connect(_accountState.data(), &AccountState::stateChanged, this, &FileProviderSocketController::slotAccountStateChanged); + connect(_accountState.data(), &AccountState::stateChanged, this, &FileProviderSocketController::slotAccountStateChanged, Qt::UniqueConnection); if (!_accountState->isConnected()) { qCDebug(lcFileProviderSocketController) << "Not sending account details yet as account is not connected" diff --git a/src/gui/macOS/fileprovidersocketcontroller.h b/src/gui/macOS/fileprovidersocketcontroller.h index 4826dc95e..52d195fc6 100644 --- a/src/gui/macOS/fileprovidersocketcontroller.h +++ b/src/gui/macOS/fileprovidersocketcontroller.h @@ -48,6 +48,7 @@ private slots: void parseReceivedLine(const QString &receivedLine); void requestFileProviderDomainInfo() const; void sendAccountDetails() const; + void sendNotAuthenticated() const; private: static AccountStatePtr accountStateFromFileProviderDomainIdentifier(const QString &domainIdentifier); -- 2.30.2