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

Work/socket api #11427

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions shell_integration/windows/OCUtil/RemotePathChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions shell_integration/windows/OCUtil/RemotePathChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@
#include <atomic>
#include <condition_variable>

#pragma once
#pragma once

class __declspec(dllexport) RemotePathChecker {
class RemotePathChecker
{
public:
enum FileState {
// Order synced with OCOverlay
Expand All @@ -39,10 +40,11 @@ class __declspec(dllexport) RemotePathChecker {
RemotePathChecker();
~RemotePathChecker();
std::shared_ptr<const std::vector<std::wstring>> 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<bool> _stop;

Expand All @@ -67,4 +69,4 @@ class __declspec(dllexport) RemotePathChecker {
void workerThreadLoop();
};

#endif
#endif
5 changes: 5 additions & 0 deletions src/common/utility_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ Utility::NtfsPermissionLookupRAII::~NtfsPermissionLookupRAII()
qt_ntfs_permission_lookup--;
}

void Utility::printWindowsDebugMessage(const QString &s)
{
OutputDebugStringW(reinterpret_cast<const wchar_t *>(s.utf16()));
}


Utility::Handle::Handle(HANDLE h, std::function<void(HANDLE)> &&close)
: _handle(h)
Expand Down
2 changes: 2 additions & 0 deletions src/common/utility_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,7 @@ namespace Utility {
private:
Q_DISABLE_COPY(NtfsPermissionLookupRAII);
};

OCSYNC_EXPORT void printWindowsDebugMessage(const QString &s);
}
}
1 change: 1 addition & 0 deletions src/gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
42 changes: 27 additions & 15 deletions src/gui/socketapi/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -790,21 +790,11 @@ Q_INVOKABLE void OCC::SocketApi::command_OPEN_APP_LINK(const QString &localFile,
}
}

void SocketApi::command_V2_LIST_ACCOUNTS(const QSharedPointer<SocketApiJobV2> &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<SocketApiJobV2> &job) const
{
OC_ASSERT(job);
if (!OC_ENSURE_NOT(job.isNull())) {
return;
}
const auto &arguments = job->arguments();

const auto size = arguments.value(QStringLiteral("size"));
Expand Down Expand Up @@ -843,7 +833,28 @@ void SocketApi::command_V2_GET_CLIENT_ICON(const QSharedPointer<SocketApiJobV2>

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<SocketApiJobV2> &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)
Expand Down Expand Up @@ -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();
}

Expand Down
6 changes: 4 additions & 2 deletions src/gui/socketapi/socketapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<SocketApiJobV2> &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"
Expand All @@ -137,6 +136,9 @@ private slots:
// e.g. { "id" : "1", "arguments" : { "size" : 16 } }
Q_INVOKABLE void command_V2_GET_CLIENT_ICON(const QSharedPointer<SocketApiJobV2> &job) const;


Q_INVOKABLE void command_V2_RETRIEVE_FILE_STATUS(const QSharedPointer<SocketApiJobV2> &job);

// Fetch the private link and call targetFun
void fetchPrivateLinkUrlHelper(const QString &localFile, const std::function<void(const QUrl &url)> &targetFun);

Expand Down
1 change: 1 addition & 0 deletions src/gui/socketapi/socketapi_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class SocketApiJobV2 : public QObject
QString _jobId;
QJsonObject _arguments;
QString _warning;
Utility::ChronoElapsedTimer _timer;
};
}

Expand Down
Loading