Skip to content

Commit

Permalink
Spotify requests are now always sent from the main thread
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilInTheGaps committed Dec 20, 2023
1 parent 67304dd commit a7340be
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/services/rest/restserviceconnectorlocal.cpp
Expand Up @@ -93,6 +93,17 @@ void RESTServiceConnectorLocal::disconnectService()

void RESTServiceConnectorLocal::sendRequest(RestRequest &&container, QPromise<RestReply> &&promise)
{
if (QThread::currentThread() != this->thread())
{
QMetaObject::invokeMethod(
this,
[this, container = std::move(container), promise = std::move(promise)]() mutable {
sendRequest(std::move(container), std::move(promise));
},
Qt::ConnectionType::QueuedConnection);
return;
}

auto *requestor = makeRequestor();
auto request = container.request();

Expand Down
11 changes: 11 additions & 0 deletions src/services/spotify/spotifyconnectorserver.cpp
Expand Up @@ -53,6 +53,17 @@ void SpotifyConnectorServer::disconnectService()

void SpotifyConnectorServer::sendRequest(RestRequest &&container, QPromise<RestReply> &&promise)
{
if (QThread::currentThread() != this->thread())
{
QMetaObject::invokeMethod(
this,
[this, container = std::move(container), promise = std::move(promise)]() mutable {
sendRequest(std::move(container), std::move(promise));
},
Qt::ConnectionType::QueuedConnection);
return;
}

auto request = container.options().testFlag(Services::Option::Authenticated) ? addAuthHeader(container.request())
: container.request();
QNetworkReply *reply = nullptr;
Expand Down

0 comments on commit a7340be

Please sign in to comment.