Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If File Provider Extension is unreachable, try to reconfigure client communication interface #7462

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/gui/macOS/fileproviderxpc.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* for more details.
*/

#include <QObject>

Check failure on line 15 in src/gui/macOS/fileproviderxpc.h

View workflow job for this annotation

GitHub Actions / build

src/gui/macOS/fileproviderxpc.h:15:10 [clang-diagnostic-error]

'QObject' file not found
#include <QHash>
#include <QDateTime>

Expand All @@ -35,7 +35,7 @@
public:
explicit FileProviderXPC(QObject *parent = nullptr);

[[nodiscard]] bool fileProviderExtReachable(const QString &extensionAccountId);
[[nodiscard]] bool fileProviderExtReachable(const QString &extensionAccountId, bool retry = true, bool reconfigureOnFail = true);

// Returns enabled and set state of fast enumeration for the given extension
[[nodiscard]] std::optional<std::pair<bool, bool>> fastEnumerationStateForExtension(const QString &extensionAccountId) const;
Expand Down
32 changes: 28 additions & 4 deletions src/gui/macOS/fileproviderxpc_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <QLoggingCategory>

#include "gui/accountmanager.h"
#include "gui/macOS/fileprovider.h"
#include "gui/macOS/fileproviderdomainmanager.h"
#include "gui/macOS/fileproviderxpc_mac_utils.h"

Expand Down Expand Up @@ -144,17 +145,20 @@
}
}

bool FileProviderXPC::fileProviderExtReachable(const QString &extensionAccountId)
{
bool FileProviderXPC::fileProviderExtReachable(const QString &extensionAccountId, const bool retry, const bool reconfigureOnFail)
const auto lastUnreachableTime = _unreachableAccountExtensions.value(extensionAccountId);
if (lastUnreachableTime.isValid() && lastUnreachableTime.secsTo(QDateTime::currentDateTime()) < ::reachableRetryTimeout) {
if (!retry
&& !reconfigureOnFail
&& lastUnreachableTime.isValid()
&& lastUnreachableTime.secsTo(QDateTime::currentDateTime()) < ::reachableRetryTimeout) {
qCInfo(lcFileProviderXPC) << "File provider extension was unreachable less than a minute ago. "
<< "Not checking again";
return false;
}

const auto service = (NSObject<ClientCommunicationProtocol> *)_clientCommServices.value(extensionAccountId);
if (service == nil) {
qCWarning(lcFileProviderXPC) << "Could not get service for extension" << extensionAccountId;
return false;
}

Expand All @@ -170,7 +174,27 @@
_unreachableAccountExtensions.remove(extensionAccountId);
} else {
qCWarning(lcFileProviderXPC) << "Could not reach file provider extension.";
_unreachableAccountExtensions.insert(extensionAccountId, QDateTime::currentDateTime());

if (reconfigureOnFail) {
qCWarning(lcFileProviderXPC) << "Could not reach extension"
<< extensionAccountId
<< "going to attempt reconfiguring interface";
const auto ncDomainManager = FileProvider::instance()->domainManager();
const auto accountState = ncDomainManager->accountStateFromFileProviderDomainIdentifier(extensionAccountId);
const auto domain = (NSFileProviderDomain *)(ncDomainManager->domainForAccount(accountState.get()));
const auto manager = [NSFileProviderManager managerForDomain:domain];
const auto fpServices = FileProviderXPCUtils::getFileProviderServices(@[manager]);
const auto connections = FileProviderXPCUtils::connectToFileProviderServices(fpServices);
const auto services = FileProviderXPCUtils::processClientCommunicationConnections(connections);
_clientCommServices.insert(services);
}

if (retry) {
qCWarning(lcFileProviderXPC) << "Could not reach extension" << extensionAccountId << "retrying";
return fileProviderExtReachable(extensionAccountId, false, false);
} else {
_unreachableAccountExtensions.insert(extensionAccountId, QDateTime::currentDateTime());
}
}
return response;
}
Expand Down
Loading