|
17 | 17 | #include <QLoggingCategory>
|
18 | 18 |
|
19 | 19 | #include "gui/accountmanager.h"
|
| 20 | +#include "gui/macOS/fileprovider.h" |
20 | 21 | #include "gui/macOS/fileproviderdomainmanager.h"
|
21 | 22 | #include "gui/macOS/fileproviderxpc_mac_utils.h"
|
22 | 23 |
|
|
144 | 145 | }
|
145 | 146 | }
|
146 | 147 |
|
147 |
| -bool FileProviderXPC::fileProviderExtReachable(const QString &extensionAccountId) |
148 |
| -{ |
| 148 | +bool FileProviderXPC::fileProviderExtReachable(const QString &extensionAccountId, const bool retry, const bool reconfigureOnFail) |
149 | 149 | const auto lastUnreachableTime = _unreachableAccountExtensions.value(extensionAccountId);
|
150 |
| - if (lastUnreachableTime.isValid() && lastUnreachableTime.secsTo(QDateTime::currentDateTime()) < ::reachableRetryTimeout) { |
| 150 | + if (!retry |
| 151 | + && !reconfigureOnFail |
| 152 | + && lastUnreachableTime.isValid() |
| 153 | + && lastUnreachableTime.secsTo(QDateTime::currentDateTime()) < ::reachableRetryTimeout) { |
151 | 154 | qCInfo(lcFileProviderXPC) << "File provider extension was unreachable less than a minute ago. "
|
152 | 155 | << "Not checking again";
|
153 | 156 | return false;
|
154 | 157 | }
|
155 | 158 |
|
156 | 159 | const auto service = (NSObject<ClientCommunicationProtocol> *)_clientCommServices.value(extensionAccountId);
|
157 | 160 | if (service == nil) {
|
| 161 | + qCWarning(lcFileProviderXPC) << "Could not get service for extension" << extensionAccountId; |
158 | 162 | return false;
|
159 | 163 | }
|
160 | 164 |
|
|
170 | 174 | _unreachableAccountExtensions.remove(extensionAccountId);
|
171 | 175 | } else {
|
172 | 176 | qCWarning(lcFileProviderXPC) << "Could not reach file provider extension.";
|
173 |
| - _unreachableAccountExtensions.insert(extensionAccountId, QDateTime::currentDateTime()); |
| 177 | + |
| 178 | + if (reconfigureOnFail) { |
| 179 | + qCWarning(lcFileProviderXPC) << "Could not reach extension" |
| 180 | + << extensionAccountId |
| 181 | + << "going to attempt reconfiguring interface"; |
| 182 | + const auto ncDomainManager = FileProvider::instance()->domainManager(); |
| 183 | + const auto accountState = ncDomainManager->accountStateFromFileProviderDomainIdentifier(extensionAccountId); |
| 184 | + const auto domain = (NSFileProviderDomain *)(ncDomainManager->domainForAccount(accountState.get())); |
| 185 | + const auto manager = [NSFileProviderManager managerForDomain:domain]; |
| 186 | + const auto fpServices = FileProviderXPCUtils::getFileProviderServices(@[manager]); |
| 187 | + const auto connections = FileProviderXPCUtils::connectToFileProviderServices(fpServices); |
| 188 | + const auto services = FileProviderXPCUtils::processClientCommunicationConnections(connections); |
| 189 | + _clientCommServices.insert(services); |
| 190 | + } |
| 191 | + |
| 192 | + if (retry) { |
| 193 | + qCWarning(lcFileProviderXPC) << "Could not reach extension" << extensionAccountId << "retrying"; |
| 194 | + return fileProviderExtReachable(extensionAccountId, false, false); |
| 195 | + } else { |
| 196 | + _unreachableAccountExtensions.insert(extensionAccountId, QDateTime::currentDateTime()); |
| 197 | + } |
174 | 198 | }
|
175 | 199 | return response;
|
176 | 200 | }
|
|
0 commit comments