diff --git a/shell_integration/windows/OCUtil/RemotePathChecker.cpp b/shell_integration/windows/OCUtil/RemotePathChecker.cpp index 79d4a5d90c7..36864b30a40 100644 --- a/shell_integration/windows/OCUtil/RemotePathChecker.cpp +++ b/shell_integration/windows/OCUtil/RemotePathChecker.cpp @@ -123,7 +123,7 @@ void RemotePathChecker::workerThreadLoop() if (!StringUtil::extractChunks(response, responseStatus, responsePath)) continue; - auto state = _StrToFileState(responseStatus); + auto state = fileStateFromString(responseStatus); bool wasAsked = asked.erase(responsePath) > 0; bool updateView = false; @@ -222,7 +222,7 @@ bool RemotePathChecker::IsMonitoredPath(const wchar_t* filePath, int* state) return false; } -RemotePathChecker::FileState RemotePathChecker::_StrToFileState(const std::wstring &str) +RemotePathChecker::FileState RemotePathChecker::fileStateFromString(const std::wstring &str) { if (str == L"NOP" || str == L"NONE") { return StateNone; diff --git a/shell_integration/windows/OCUtil/RemotePathChecker.h b/shell_integration/windows/OCUtil/RemotePathChecker.h index 36bcf1ae9be..94bf9f8bc08 100644 --- a/shell_integration/windows/OCUtil/RemotePathChecker.h +++ b/shell_integration/windows/OCUtil/RemotePathChecker.h @@ -24,9 +24,10 @@ #include #include -#pragma once +#pragma once -class __declspec(dllexport) RemotePathChecker { +class RemotePathChecker +{ public: enum FileState { // Order synced with OCOverlay @@ -39,10 +40,11 @@ class __declspec(dllexport) RemotePathChecker { RemotePathChecker(); ~RemotePathChecker(); std::shared_ptr> WatchedDirectories() const; - bool IsMonitoredPath(const wchar_t* filePath, int* state); + bool IsMonitoredPath(const wchar_t *filePath, int *state); + + static FileState fileStateFromString(const std::wstring &str); private: - FileState _StrToFileState(const std::wstring &str); std::mutex _mutex; std::atomic _stop; @@ -67,4 +69,4 @@ class __declspec(dllexport) RemotePathChecker { void workerThreadLoop(); }; -#endif \ No newline at end of file +#endif diff --git a/src/common/utility_win.cpp b/src/common/utility_win.cpp index d2edb9281f2..fef7f861626 100644 --- a/src/common/utility_win.cpp +++ b/src/common/utility_win.cpp @@ -124,6 +124,11 @@ Utility::NtfsPermissionLookupRAII::~NtfsPermissionLookupRAII() qt_ntfs_permission_lookup--; } +void Utility::printWindowsDebugMessage(const QString &s) +{ + OutputDebugStringW(reinterpret_cast(s.utf16())); +} + Utility::Handle::Handle(HANDLE h, std::function &&close) : _handle(h) diff --git a/src/common/utility_win.h b/src/common/utility_win.h index c87ef6b01a9..38408974d80 100644 --- a/src/common/utility_win.h +++ b/src/common/utility_win.h @@ -87,5 +87,7 @@ namespace Utility { private: Q_DISABLE_COPY(NtfsPermissionLookupRAII); }; + + OCSYNC_EXPORT void printWindowsDebugMessage(const QString &s); } } diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 19f36c1f3ae..dec57cf857d 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -420,6 +420,7 @@ int main(int argc, char **argv) // parse the arguments before we handle singleApplication // errors and help/version need to be handled in this instance const auto options = parseOptions(app.arguments()); + qDebug() << app.arguments(); KDSingleApplication singleApplication; diff --git a/src/gui/socketapi/socketapi.cpp b/src/gui/socketapi/socketapi.cpp index eb5c103a29e..4b9fb2c12f7 100644 --- a/src/gui/socketapi/socketapi.cpp +++ b/src/gui/socketapi/socketapi.cpp @@ -146,7 +146,7 @@ SocketApi::SocketApi(QObject *parent) SocketApiServer::removeServer(_socketPath); // Create the socket path: - if (!Utility::isMac()) { + if (!Utility::isMac() && !Utility::isWindows()) { // Not on macOS: there the directory is there, and created for us by the sandboxing // environment, because we belong to an App Group. QFileInfo info(_socketPath); @@ -790,21 +790,11 @@ Q_INVOKABLE void OCC::SocketApi::command_OPEN_APP_LINK(const QString &localFile, } } -void SocketApi::command_V2_LIST_ACCOUNTS(const QSharedPointer &job) const -{ - QJsonArray out; - for (auto acc : AccountManager::instance()->accounts()) { - OC_DISABLE_DEPRECATED_WARNING; // allow use of id - out << QJsonObject({{QStringLiteral("name"), acc->account()->displayName()}, {QStringLiteral("id"), acc->account()->id()}, - {QStringLiteral("uuid"), acc->account()->uuid().toString(QUuid::WithoutBraces)}}); - OC_ENABLE_DEPRECATED_WARNING - } - job->success({ { QStringLiteral("accounts"), out } }); -} - void SocketApi::command_V2_GET_CLIENT_ICON(const QSharedPointer &job) const { - OC_ASSERT(job); + if (!OC_ENSURE_NOT(job.isNull())) { + return; + } const auto &arguments = job->arguments(); const auto size = arguments.value(QStringLiteral("size")); @@ -843,7 +833,28 @@ void SocketApi::command_V2_GET_CLIENT_ICON(const QSharedPointer data = pngBuffer.data().toBase64(); } - job->success({ { QStringLiteral("png"), QString::fromUtf8(data) } }); + job->success({{QStringLiteral("png"), QString::fromUtf8(data)}}); +} + +void SocketApi::command_V2_RETRIEVE_FILE_STATUS(const QSharedPointer &job) +{ + if (!OC_ENSURE_NOT(job.isNull())) { + return; + } + const auto &arguments = job->arguments(); + + SyncFileStatus status = SyncFileStatus::StatusNone; + auto fileData = FileData::get(arguments.value(QStringLiteral("path")).toString()); + if (fileData.folder) { + // The user probably visited this directory in the file shell. + // Let the listener know that it should now send status pushes for sibblings of this file. + // TODO: + // QString directory = fileData.localPath.left(fileData.localPath.lastIndexOf(QLatin1Char('/'))); + // listener->registerMonitoredDirectory(qHash(directory)); + status = fileData.syncFileStatus(); + } + + job->success({{QStringLiteral("status"), SyncFileStatus(status).toSocketAPIString()}}); } void SocketApi::emailPrivateLink(const QUrl &link) @@ -1196,6 +1207,7 @@ void SocketApiJobV2::doFinish(const QJsonObject &obj) const data[QStringLiteral("warning")] = _warning; } _socketListener->sendMessage(_command + QStringLiteral("_RESULT:") + QString::fromUtf8(QJsonDocument(data).toJson(QJsonDocument::Compact))); + qCDebug(lcSocketApi) << "SocketApiJobV2" << _jobId << "finished" << _timer.duration() << _socketListener; Q_EMIT finished(); } diff --git a/src/gui/socketapi/socketapi.h b/src/gui/socketapi/socketapi.h index b136366f00c..3f8ea0c5579 100644 --- a/src/gui/socketapi/socketapi.h +++ b/src/gui/socketapi/socketapi.h @@ -127,8 +127,7 @@ private slots: Q_INVOKABLE void command_MOVE_ITEM(const QString &localFile, SocketListener *listener); Q_INVOKABLE void command_OPEN_APP_LINK(const QString &localFile, SocketListener *listener); - // External sync - Q_INVOKABLE void command_V2_LIST_ACCOUNTS(const QSharedPointer &job) const; + // Sends the id and the client icon as PNG image (base64 encoded) in Json key "png" // e.g. { "id" : "1", "arguments" : { "png" : "hswehs343dj8..." } } or an error message in key "error" @@ -137,6 +136,9 @@ private slots: // e.g. { "id" : "1", "arguments" : { "size" : 16 } } Q_INVOKABLE void command_V2_GET_CLIENT_ICON(const QSharedPointer &job) const; + + Q_INVOKABLE void command_V2_RETRIEVE_FILE_STATUS(const QSharedPointer &job); + // Fetch the private link and call targetFun void fetchPrivateLinkUrlHelper(const QString &localFile, const std::function &targetFun); diff --git a/src/gui/socketapi/socketapi_p.h b/src/gui/socketapi/socketapi_p.h index 51e79194964..46e4dab4129 100644 --- a/src/gui/socketapi/socketapi_p.h +++ b/src/gui/socketapi/socketapi_p.h @@ -157,6 +157,7 @@ class SocketApiJobV2 : public QObject QString _jobId; QJsonObject _arguments; QString _warning; + Utility::ChronoElapsedTimer _timer; }; }