mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:24:00 +02:00
Don't use eventLoop, since that will block the UI
This commit is contained in:
parent
249f0568a1
commit
5ee28297f3
1 changed files with 34 additions and 36 deletions
|
@ -233,49 +233,47 @@ bool QmlCommerce::installApp(const QString& itemHref) {
|
|||
|
||||
QUrl appHref(itemHref);
|
||||
|
||||
auto request =
|
||||
std::unique_ptr<ResourceRequest>(DependencyManager::get<ResourceManager>()->createResourceRequest(this, appHref));
|
||||
auto request = DependencyManager::get<ResourceManager>()->createResourceRequest(this, appHref);
|
||||
|
||||
if (!request) {
|
||||
qCDebug(commerce) << "Couldn't create resource request for app.";
|
||||
return false;
|
||||
}
|
||||
|
||||
QEventLoop loop;
|
||||
connect(request.get(), &ResourceRequest::finished, &loop, &QEventLoop::quit);
|
||||
connect(request, &ResourceRequest::finished, this, [=]() {
|
||||
if (request->getResult() != ResourceRequest::Success) {
|
||||
qCDebug(commerce) << "Failed to get .app.json file from remote.";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Copy the .app.json to the apps directory inside %AppData%/High Fidelity/Interface
|
||||
auto requestData = request->getData();
|
||||
QFile appFile(_appsPath + "/" + appHref.fileName());
|
||||
if (!appFile.open(QIODevice::WriteOnly)) {
|
||||
qCDebug(commerce) << "Couldn't open local .app.json file for creation.";
|
||||
return false;
|
||||
}
|
||||
if (appFile.write(requestData) == -1) {
|
||||
qCDebug(commerce) << "Couldn't write to local .app.json file.";
|
||||
return false;
|
||||
}
|
||||
// Close the file
|
||||
appFile.close();
|
||||
|
||||
// Read from the returned datastream to know what .js to add to Running Scripts
|
||||
QJsonDocument appFileJsonDocument = QJsonDocument::fromJson(requestData);
|
||||
QJsonObject appFileJsonObject = appFileJsonDocument.object();
|
||||
QString scriptUrl = appFileJsonObject["scriptURL"].toString();
|
||||
|
||||
if ((DependencyManager::get<ScriptEngines>()->loadScript(scriptUrl.trimmed())).isNull()) {
|
||||
qCDebug(commerce) << "Couldn't load script.";
|
||||
return false;
|
||||
}
|
||||
|
||||
emit appInstalled(itemHref);
|
||||
return true;
|
||||
});
|
||||
request->send();
|
||||
loop.exec();
|
||||
|
||||
if (request->getResult() != ResourceRequest::Success) {
|
||||
qCDebug(commerce) << "Failed to get .app.json file from remote.";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Copy the .app.json to the apps directory inside %AppData%/High Fidelity/Interface
|
||||
auto requestData = request->getData();
|
||||
QFile appFile(_appsPath + "/" + appHref.fileName());
|
||||
if (!appFile.open(QIODevice::WriteOnly)) {
|
||||
qCDebug(commerce) << "Couldn't open local .app.json file for creation.";
|
||||
return false;
|
||||
}
|
||||
if (appFile.write(requestData) == -1) {
|
||||
qCDebug(commerce) << "Couldn't write to local .app.json file.";
|
||||
return false;
|
||||
}
|
||||
// Close the file
|
||||
appFile.close();
|
||||
|
||||
// Read from the returned datastream to know what .js to add to Running Scripts
|
||||
QJsonDocument appFileJsonDocument = QJsonDocument::fromJson(requestData);
|
||||
QJsonObject appFileJsonObject = appFileJsonDocument.object();
|
||||
QString scriptUrl = appFileJsonObject["scriptURL"].toString();
|
||||
|
||||
if ((DependencyManager::get<ScriptEngines>()->loadScript(scriptUrl.trimmed())).isNull()) {
|
||||
qCDebug(commerce) << "Couldn't load script.";
|
||||
return false;
|
||||
}
|
||||
|
||||
emit appInstalled(itemHref);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue