mirror of
https://github.com/overte-org/overte.git
synced 2025-04-07 17:52:26 +02:00
Merge pull request #16269 from SimonWalton-HiFi/asset-scripting-wait-for-init
DEV-1898: Make Assets.initializeCache() script i/f blocking
This commit is contained in:
commit
37f18e2e5e
2 changed files with 22 additions and 1 deletions
|
@ -29,6 +29,8 @@
|
|||
#include <shared/QtHelpers.h>
|
||||
#include <Gzip.h>
|
||||
|
||||
#include <future>
|
||||
|
||||
using Promise = MiniPromise::Promise;
|
||||
|
||||
AssetScriptingInterface::AssetScriptingInterface(QObject* parent) : BaseAssetScriptingInterface(parent) {
|
||||
|
@ -38,6 +40,25 @@ AssetScriptingInterface::AssetScriptingInterface(QObject* parent) : BaseAssetScr
|
|||
|
||||
#define JS_VERIFY(cond, error) { if (!this->jsVerify(cond, error)) { return; } }
|
||||
|
||||
bool AssetScriptingInterface::initializeCache() {
|
||||
if (!Parent::initializeCache()) {
|
||||
if (assetClient()) {
|
||||
std::promise<bool> cacheStatusResult;
|
||||
Promise assetClientPromise(makePromise(__func__));
|
||||
assetClientPromise->moveToThread(qApp->thread()); // To ensure the finally() is processed.
|
||||
|
||||
assetClient()->cacheInfoRequestAsync(assetClientPromise);
|
||||
assetClientPromise->finally([&](QString, QVariantMap result)
|
||||
{ cacheStatusResult.set_value(!result.isEmpty()); });
|
||||
return cacheStatusResult.get_future().get();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void AssetScriptingInterface::uploadData(QString data, QScriptValue callback) {
|
||||
auto handler = jsBindCallback(thisObject(), callback);
|
||||
QByteArray dataByteArray = data.toUtf8();
|
||||
|
|
|
@ -356,7 +356,7 @@ public:
|
|||
* @function Assets.initializeCache
|
||||
* @returns {boolean} <code>true</code> if the cache is initialized, <code>false</code> if it isn't.
|
||||
*/
|
||||
Q_INVOKABLE bool initializeCache() { return Parent::initializeCache(); }
|
||||
Q_INVOKABLE bool initializeCache();
|
||||
|
||||
/**jsdoc
|
||||
* Checks whether the script can write to the cache.
|
||||
|
|
Loading…
Reference in a new issue