mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
Inform user if can't do Clara.io download because can't write to ATP
This commit is contained in:
parent
0dd7366198
commit
c4ff129f86
3 changed files with 81 additions and 17 deletions
|
@ -5582,17 +5582,24 @@ void Application::showAssetServerWidget(QString filePath) {
|
|||
void Application::addAssetToWorldFromURL(QString url) {
|
||||
qInfo(interfaceapp) << "Download asset and add to world from" << url;
|
||||
|
||||
if (!_addAssetToWorldMessageBox) {
|
||||
_addAssetToWorldMessageBox = DependencyManager::get<OffscreenUi>()->createMessageBox(OffscreenUi::ICON_INFORMATION,
|
||||
"Downloading Asset", "Downloading asset file " + url.section("filename=", 1, 1),
|
||||
QMessageBox::Cancel, QMessageBox::NoButton);
|
||||
connect(_addAssetToWorldMessageBox, SIGNAL(destroyed()), this, SLOT(onAssetToWorldMessageBoxClosed()));
|
||||
}
|
||||
|
||||
if (!DependencyManager::get<NodeList>()->getThisNodeCanWriteAssets()) {
|
||||
QString errorInfo = "You do not have permissions to write to the Asset Server.";
|
||||
qWarning(interfaceapp) << "Error downloading asset: " + errorInfo;
|
||||
addAssetToWorldError(errorInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
QUrl urlURL = QUrl(url);
|
||||
auto request = ResourceManager::createResourceRequest(nullptr, urlURL);
|
||||
connect(request, &ResourceRequest::finished, this, &Application::addAssetToWorldFromURLRequestFinished);
|
||||
request->send();
|
||||
|
||||
if (!_addAssetToWorldMessageBox) {
|
||||
_addAssetToWorldMessageBox = DependencyManager::get<OffscreenUi>()->createMessageBox(OffscreenUi::ICON_INFORMATION,
|
||||
"Downloading Asset", "Downloading asset file " + url.section("filename=", 1, 1),
|
||||
QMessageBox::Cancel, QMessageBox::NoButton);
|
||||
}
|
||||
connect(_addAssetToWorldMessageBox, SIGNAL(destroyed()), this, SLOT(onAssetToWorldMessageBoxClosed()));
|
||||
}
|
||||
|
||||
void Application::addAssetToWorldFromURLRequestFinished() {
|
||||
|
@ -5650,8 +5657,9 @@ void Application::addAssetToWorld(QString filePath) {
|
|||
return;
|
||||
}
|
||||
|
||||
// Test repeated because possibly different code paths.
|
||||
if (!DependencyManager::get<NodeList>()->getThisNodeCanWriteAssets()) {
|
||||
QString errorInfo = "Do not have permissions to write to asset server.";
|
||||
QString errorInfo = "You do not have permissions to write to the Asset Server.";
|
||||
qWarning(interfaceapp) << "Error downloading asset: " + errorInfo;
|
||||
addAssetToWorldError(errorInfo);
|
||||
return;
|
||||
|
@ -5660,7 +5668,7 @@ void Application::addAssetToWorld(QString filePath) {
|
|||
QString path = QUrl(filePath).toLocalFile();
|
||||
QString mapping = path.right(path.length() - path.lastIndexOf("/"));
|
||||
|
||||
_addAssetToWorldMessageBox->setProperty("text", "Adding " + mapping.mid(1) + " to Asset Server.");
|
||||
_addAssetToWorldMessageBox->setProperty("text", "Adding " + mapping.mid(1) + " to the Asset Server.");
|
||||
|
||||
addAssetToWorldWithNewMapping(path, mapping, 0);
|
||||
}
|
||||
|
@ -5708,7 +5716,7 @@ void Application::addAssetToWorldUpload(QString path, QString mapping) {
|
|||
auto upload = DependencyManager::get<AssetClient>()->createUpload(path);
|
||||
QObject::connect(upload, &AssetUpload::finished, this, [=](AssetUpload* upload, const QString& hash) mutable {
|
||||
if (upload->getError() != AssetUpload::NoError) {
|
||||
QString errorInfo = "Could not upload asset to asset server.";
|
||||
QString errorInfo = "Could not upload asset to the Asset Server.";
|
||||
qWarning(interfaceapp) << "Error downloading asset: " + errorInfo;
|
||||
addAssetToWorldError(errorInfo);
|
||||
} else {
|
||||
|
|
|
@ -12,6 +12,15 @@
|
|||
|
||||
(function () {
|
||||
|
||||
// Event bridge messages.
|
||||
var CLARA_IO_DOWNLOAD = "CLARA.IO DOWNLOAD";
|
||||
var GOTO_DIRECTORY = "GOTO_DIRECTORY";
|
||||
var QUERY_CAN_WRITE_ASSETS = "QUERY_CAN_WRITE_ASSETS";
|
||||
var CAN_WRITE_ASSETS = "CAN_WRITE_ASSETS";
|
||||
var WARN_USER_NO_PERMISSIONS = "WARN_USER_NO_PERMISSIONS";
|
||||
|
||||
var canWriteAssets = false;
|
||||
|
||||
function injectCommonCode(isDirectoryPage) {
|
||||
|
||||
// Supporting styles from marketplaces.css.
|
||||
|
@ -54,7 +63,7 @@
|
|||
window.history.back();
|
||||
});
|
||||
$("#all-markets").on("click", function () {
|
||||
EventBridge.emitWebEvent("GOTO_DIRECTORY");
|
||||
EventBridge.emitWebEvent(GOTO_DIRECTORY);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -118,7 +127,13 @@
|
|||
|
||||
// Automatic download to High Fidelity.
|
||||
var downloadTimer;
|
||||
function startAutoDownload() {
|
||||
function startAutoDownload(event) {
|
||||
if (!canWriteAssets) {
|
||||
console.log("Clara.io FBX file download cancelled because no permissions to write to Asset Server");
|
||||
EventBridge.emitWebEvent(WARN_USER_NO_PERMISSIONS);
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
window.scrollTo(0, 0); // Scroll to top ready for history.back().
|
||||
if (!downloadTimer) {
|
||||
downloadTimer = setInterval(autoDownload, 1000);
|
||||
|
@ -131,7 +146,7 @@
|
|||
clearInterval(downloadTimer);
|
||||
downloadTimer = null;
|
||||
var href = downloadButton[0].href;
|
||||
EventBridge.emitWebEvent("CLARA.IO DOWNLOAD " + href);
|
||||
EventBridge.emitWebEvent(CLARA_IO_DOWNLOAD + " " + href);
|
||||
console.log("Clara.io FBX file download initiated for " + href);
|
||||
$("a.btn.cancel").click();
|
||||
history.back(); // Remove history item created by clicking "download".
|
||||
|
@ -170,9 +185,18 @@
|
|||
checkLocationInterval = undefined;
|
||||
currentLocation = "";
|
||||
});
|
||||
|
||||
EventBridge.emitWebEvent(QUERY_CAN_WRITE_ASSETS);
|
||||
}
|
||||
|
||||
function onLoad() {
|
||||
|
||||
EventBridge.scriptEventReceived.connect(function (message) {
|
||||
if (message.slice(0, CAN_WRITE_ASSETS.length) === CAN_WRITE_ASSETS) {
|
||||
canWriteAssets = message.slice(-4) === "true";
|
||||
}
|
||||
});
|
||||
|
||||
var DIRECTORY = 0;
|
||||
var HIFI = 1;
|
||||
var CLARA = 2;
|
||||
|
|
|
@ -20,6 +20,14 @@ var MARKETPLACE_URL_INITIAL = MARKETPLACE_URL + "?"; // Append "?" to signal in
|
|||
var MARKETPLACES_URL = Script.resolvePath("../html/marketplaces.html");
|
||||
var MARKETPLACES_INJECT_SCRIPT_URL = Script.resolvePath("../html/js/marketplacesInject.js");
|
||||
|
||||
// Event bridge messages.
|
||||
var CLARA_IO_DOWNLOAD = "CLARA.IO DOWNLOAD";
|
||||
var GOTO_DIRECTORY = "GOTO_DIRECTORY";
|
||||
var QUERY_CAN_WRITE_ASSETS = "QUERY_CAN_WRITE_ASSETS";
|
||||
var CAN_WRITE_ASSETS = "CAN_WRITE_ASSETS";
|
||||
var WARN_USER_NO_PERMISSIONS = "WARN_USER_NO_PERMISSIONS";
|
||||
var NO_PERMISSIONS_ERROR_MESSAGE = "Cannot download model because you can't write to \nthe domain's Asset Server.";
|
||||
|
||||
var marketplaceWindow = new OverlayWebWindow({
|
||||
title: "Marketplace",
|
||||
source: "about:blank",
|
||||
|
@ -28,10 +36,16 @@ var marketplaceWindow = new OverlayWebWindow({
|
|||
visible: false
|
||||
});
|
||||
marketplaceWindow.setScriptURL(MARKETPLACES_INJECT_SCRIPT_URL);
|
||||
marketplaceWindow.webEventReceived.connect(function (data) {
|
||||
if (data === "GOTO_DIRECTORY") {
|
||||
marketplaceWindow.webEventReceived.connect(function (message) {
|
||||
if (message === GOTO_DIRECTORY) {
|
||||
marketplaceWindow.setURL(MARKETPLACES_URL);
|
||||
}
|
||||
if (message === QUERY_CAN_WRITE_ASSETS) {
|
||||
marketplaceWindow.emitScriptEvent(CAN_WRITE_ASSETS + " " + Entities.canWriteAssets());
|
||||
}
|
||||
if (message === WARN_USER_NO_PERMISSIONS) {
|
||||
Window.alert(NO_PERMISSIONS_ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
|
||||
var toolHeight = 50;
|
||||
|
@ -57,10 +71,16 @@ function showMarketplace() {
|
|||
marketplaceWebTablet = new WebTablet(MARKETPLACE_URL_INITIAL, null, null, true);
|
||||
Settings.setValue(persistenceKey, marketplaceWebTablet.pickle());
|
||||
marketplaceWebTablet.setScriptURL(MARKETPLACES_INJECT_SCRIPT_URL);
|
||||
marketplaceWebTablet.getOverlayObject().webEventReceived.connect(function (data) {
|
||||
if (data === "GOTO_DIRECTORY") {
|
||||
marketplaceWebTablet.getOverlayObject().webEventReceived.connect(function (message) {
|
||||
if (message === GOTO_DIRECTORY) {
|
||||
marketplaceWebTablet.setURL(MARKETPLACES_URL);
|
||||
}
|
||||
if (message === QUERY_CAN_WRITE_ASSETS) {
|
||||
marketplaceWebTablet.getOverlayObject().emitScriptEvent(CAN_WRITE_ASSETS + " " + Entities.canWriteAssets());
|
||||
}
|
||||
if (message === WARN_USER_NO_PERMISSIONS) {
|
||||
Window.alert(NO_PERMISSIONS_ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
marketplaceWindow.setURL(MARKETPLACE_URL_INITIAL);
|
||||
|
@ -123,12 +143,23 @@ function onMarketplaceWindowVisibilityChanged() {
|
|||
marketplaceVisible = marketplaceWindow.visible;
|
||||
}
|
||||
|
||||
function onCanWriteAssetsChanged() {
|
||||
var message = CAN_WRITE_ASSETS + " " + Entities.canWriteAssets();
|
||||
if (marketplaceWindow.visible) {
|
||||
marketplaceWindow.emitScriptEvent(message);
|
||||
}
|
||||
if (marketplaceWebTablet) {
|
||||
marketplaceWebTablet.getOverlayObject().emitScriptEvent(message);
|
||||
}
|
||||
}
|
||||
|
||||
function onClick() {
|
||||
toggleMarketplace();
|
||||
}
|
||||
|
||||
browseExamplesButton.clicked.connect(onClick);
|
||||
marketplaceWindow.visibleChanged.connect(onMarketplaceWindowVisibilityChanged);
|
||||
Entities.canWriteAssetsChanged.connect(onCanWriteAssetsChanged);
|
||||
|
||||
clearOldTablet(); // Run once at startup, in case there's anything laying around from a crash.
|
||||
// We could also optionally do something like Window.domainChanged.connect(function () {Script.setTimeout(clearOldTablet, 2000)}),
|
||||
|
@ -138,6 +169,7 @@ Script.scriptEnding.connect(function () {
|
|||
toolBar.removeButton("marketplace");
|
||||
browseExamplesButton.clicked.disconnect(onClick);
|
||||
marketplaceWindow.visibleChanged.disconnect(onMarketplaceWindowVisibilityChanged);
|
||||
Entities.canWriteAssetsChanged.disconnect(onCanWriteAssetsChanged);
|
||||
});
|
||||
|
||||
}()); // END LOCAL_SCOPE
|
||||
|
|
Loading…
Reference in a new issue