if desktop client sent a first reply: wait for the menu data

may need the user to wait a bit longer but should prevent missing the
context menu

should still be robust since we only wait indefinitely if desktop client
sent a first reply

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
This commit is contained in:
Matthieu Gallien 2024-03-19 09:39:36 +01:00
parent 9a8392c1a3
commit 4bf1b8604c
No known key found for this signature in database
GPG Key ID: 7D0F74F05C22F553
2 changed files with 8 additions and 2 deletions

View File

@ -48,7 +48,10 @@ NCClientInterface::ContextMenuInfo NCClientInterface::FetchInfo(const std::wstri
ContextMenuInfo info;
std::wstring response;
int sleptCount = 0;
while (sleptCount < 20) {
constexpr auto noReplyTimeout = 20;
constexpr auto replyTimeout = 200;
bool receivedReplyFromDesktopClient = false;
while ((!receivedReplyFromDesktopClient && sleptCount < noReplyTimeout) || (receivedReplyFromDesktopClient && sleptCount < replyTimeout)) {
if (socket.ReadLine(&response)) {
if (StringUtil::begins_with(response, wstring(L"REGISTER_PATH:"))) {
wstring responsePath = response.substr(14); // length of REGISTER_PATH
@ -65,6 +68,9 @@ NCClientInterface::ContextMenuInfo NCClientInterface::FetchInfo(const std::wstri
if (!StringUtil::extractChunks(response, commandName, flags, title))
continue;
info.menuItems.push_back({ commandName, flags, title });
} else if (StringUtil::begins_with(response, wstring(L"GET_MENU_ITEMS:BEGIN"))) {
receivedReplyFromDesktopClient = true;
continue;
} else if (StringUtil::begins_with(response, wstring(L"GET_MENU_ITEMS:END"))) {
break; // Stop once we completely received the last sent request
}

View File

@ -1346,7 +1346,7 @@ SocketApi::FileData SocketApi::FileData::parentFolder() const
void SocketApi::command_GET_MENU_ITEMS(const QString &argument, OCC::SocketListener *listener)
{
listener->sendMessage(QString("GET_MENU_ITEMS:BEGIN"));
listener->sendMessage(QString("GET_MENU_ITEMS:BEGIN"), true);
const QStringList files = split(argument);
// Find the common sync folder.