diff --git a/interface/resources/qml/Marketplaces.qml b/interface/resources/qml/Marketplaces.qml index 5bee3a84d9..167a456e06 100644 --- a/interface/resources/qml/Marketplaces.qml +++ b/interface/resources/qml/Marketplaces.qml @@ -56,7 +56,7 @@ Rectangle { property var simpleDownload: 'var element = $("a.download-file"); element.removeClass("download-file"); element.removeAttr("download");' - + function displayErrorStatus() { alertTimer.handler = function() { statusLabel.text = claraMessage; @@ -69,12 +69,23 @@ Rectangle { property var notFbxHandler: 'var element = $("a.btn.btn-primary.viewer-button.download-file") element.click();' - // this code is for removing other file types from Clara.io's download options - //property var checkFileType: "$('[data-extension]:not([data-extension=\"fbx\"])').parent().remove()" + // Replace Clara FBX download link action with Cara API action. + property string replaceFBXDownload: 'var element = $("a[data-extension=\'fbx\']:first"); + element.unbind("click"); + element.bind("click", function(event) { + console.log("Initiate Clara.io FBX file download"); + window.open("https://clara.io/api/scenes/{uuid}/export/fbx?fbxVersion=7.4&fbxEmbedTextures=true¢erScene=true&alignSceneGound=true"); + return false; + });' onLinkHovered: { desktop.currentUrl = hoveredUrl; - //runJavaScript(checkFileType, function(){console.log("Remove filetypes JS injection");}); + + if (desktop.isClaraFBXZipDownload(desktop.currentUrl)) { + var doReplaceFBXDownload = replaceFBXDownload.replace("{uuid}", desktop.currentUrl.slice(desktop.currentUrl.lastIndexOf("/") + 1, -1)); + runJavaScript(doReplaceFBXDownload); + } + if (File.isZippedFbx(desktop.currentUrl)) { runJavaScript(simpleDownload, function(){console.log("Download JS injection");}); return; @@ -110,7 +121,7 @@ Rectangle { newWindow.height = 0; request.openIn(newWindow.webView); - if (File.isZippedFbx(desktop.currentUrl)) { + if (desktop.isClaraFBXZipDownload(desktop.currentUrl)) { newWindow.setAutoAdd(true); runJavaScript(autoCancel); newWindow.loadingChanged.connect(function(status) { diff --git a/interface/resources/qml/hifi/Desktop.qml b/interface/resources/qml/hifi/Desktop.qml index c396df9d4d..04a7c404f4 100644 --- a/interface/resources/qml/hifi/Desktop.qml +++ b/interface/resources/qml/hifi/Desktop.qml @@ -90,6 +90,11 @@ OriginalDesktop.Desktop { property string tempDir: "" property bool autoAdd: false + function isClaraFBXZipDownload(url) { + // Clara.io FBX file: Original URL that is ovrridden in JavaScript to download using API. + return url.indexOf("clara.io/view/") !== -1 && url.slice(-1) === "#"; + } + function initWebviewProfileHandlers(profile) { console.log("The webview url in desktop is: " + currentUrl); if (webViewProfileSetup) return; @@ -101,6 +106,9 @@ OriginalDesktop.Desktop { tempDir = File.getTempDir(); console.log("Temp dir created: " + tempDir); download.path = tempDir + "/" + adaptedPath; + if (isClaraFBXZipDownload(currentUrl)) { + download.path += "fbx.zip"; + } console.log("Path where object should download: " + download.path); console.log("Auto add: " + autoAdd); download.accept();