clara.io marketplace works on tablet

This commit is contained in:
Anthony J. Thibault 2017-01-17 15:38:44 -08:00
parent c212fc93c9
commit 56fc42a2bd
4 changed files with 63 additions and 107 deletions

View file

@ -10,8 +10,9 @@ Item {
loader.source = url; loader.source = url;
} }
function loadWebUrl(url) { function loadWebUrl(url, injectedJavaScriptUrl) {
loader.item.url = url; loader.item.url = url;
loader.item.scriptURL = injectedJavaScriptUrl;
} }
SoundEffect { SoundEffect {
@ -35,6 +36,13 @@ Item {
// propogate eventBridge to WebEngineView // propogate eventBridge to WebEngineView
if (loader.item.hasOwnProperty("eventBridge")) { if (loader.item.hasOwnProperty("eventBridge")) {
loader.item.eventBridge = eventBridge; loader.item.eventBridge = eventBridge;
// Hook up callback for clara.io download from the marketplace.
eventBridge.webEventReceived.connect(function (event) {
if (event.slice(0, 17) === "CLARA.IO DOWNLOAD") {
ApplicationInterface.addAssetToWorldFromURL(event.slice(18));
}
});
} }
} }
} }

View file

@ -117,6 +117,10 @@ void TabletProxy::gotoHomeScreen() {
} }
void TabletProxy::gotoWebScreen(const QString& url) { void TabletProxy::gotoWebScreen(const QString& url) {
gotoWebScreen(url, "");
}
void TabletProxy::gotoWebScreen(const QString& url, const QString& injectedJavaScriptUrl) {
if (_qmlTabletRoot) { if (_qmlTabletRoot) {
if (_state == State::Home) { if (_state == State::Home) {
removeButtonsFromHomeScreen(); removeButtonsFromHomeScreen();
@ -125,7 +129,8 @@ void TabletProxy::gotoWebScreen(const QString& url) {
QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(WEB_VIEW_SOURCE_URL))); QMetaObject::invokeMethod(_qmlTabletRoot, "loadSource", Q_ARG(const QVariant&, QVariant(WEB_VIEW_SOURCE_URL)));
_state = State::Web; _state = State::Web;
} }
QMetaObject::invokeMethod(_qmlTabletRoot, "loadWebUrl", Q_ARG(const QVariant&, QVariant(url))); QMetaObject::invokeMethod(_qmlTabletRoot, "loadWebUrl", Q_ARG(const QVariant&, QVariant(url)),
Q_ARG(const QVariant&, QVariant(injectedJavaScriptUrl)));
} }
} }

View file

@ -75,9 +75,11 @@ public:
/**jsdoc /**jsdoc
* show the specified web url on the tablet. * show the specified web url on the tablet.
* @function TabletProxy#gotoWebScreen * @function TabletProxy#gotoWebScreen
* @param url {string} * @param url {string} url of web page.
* @param [injectedJavaScriptUrl] {string} optional url to an additional JS script to inject into the web page.
*/ */
Q_INVOKABLE void gotoWebScreen(const QString& url); Q_INVOKABLE void gotoWebScreen(const QString& url);
Q_INVOKABLE void gotoWebScreen(const QString& url, const QString& injectedJavaScriptUrl);
/**jsdoc /**jsdoc
* Creates a new button, adds it to this and returns it. * Creates a new button, adds it to this and returns it.

View file

@ -8,13 +8,13 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
/* global WebTablet Tablet */
/* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */
(function() { // BEGIN LOCAL_SCOPE (function() { // BEGIN LOCAL_SCOPE
/* global WebTablet */
Script.include("../libraries/WebTablet.js"); Script.include("../libraries/WebTablet.js");
var toolIconUrl = Script.resolvePath("../assets/images/tools/");
var MARKETPLACE_URL = "https://metaverse.highfidelity.com/marketplace"; var MARKETPLACE_URL = "https://metaverse.highfidelity.com/marketplace";
var MARKETPLACE_URL_INITIAL = MARKETPLACE_URL + "?"; // Append "?" to signal injected script that it's the initial page. var MARKETPLACE_URL_INITIAL = MARKETPLACE_URL + "?"; // Append "?" to signal injected script that it's the initial page.
var MARKETPLACES_URL = Script.resolvePath("../html/marketplaces.html"); var MARKETPLACES_URL = Script.resolvePath("../html/marketplaces.html");
@ -39,112 +39,60 @@ var NO_BUTTON = 0; // QMessageBox::NoButton
var NO_PERMISSIONS_ERROR_MESSAGE = "Cannot download model because you can't write to \nthe domain's Asset Server."; 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",
width: 900,
height: 700,
visible: false
});
marketplaceWindow.setScriptURL(MARKETPLACES_INJECT_SCRIPT_URL);
function onWebEventReceived(message) {
if (message === GOTO_DIRECTORY) {
var url = MARKETPLACES_URL;
marketplaceWindow.setURL(url);
return;
}
if (message === QUERY_CAN_WRITE_ASSETS) {
var canWriteAssets = CAN_WRITE_ASSETS + " " + Entities.canWriteAssets();
marketplaceWindow.emitScriptEvent(canWriteAssets);
return;
}
if (message === WARN_USER_NO_PERMISSIONS) {
Window.alert(NO_PERMISSIONS_ERROR_MESSAGE);
return;
}
if (message.slice(0, CLARA_IO_STATUS.length) === CLARA_IO_STATUS) {
if (isDownloadBeingCancelled) {
return;
}
var text = message.slice(CLARA_IO_STATUS.length);
if (messageBox === null) {
messageBox = Window.openMessageBox(CLARA_DOWNLOAD_TITLE, text, CANCEL_BUTTON, NO_BUTTON);
} else {
Window.updateMessageBox(messageBox, CLARA_DOWNLOAD_TITLE, text, CANCEL_BUTTON, NO_BUTTON);
}
return;
}
if (message.slice(0, CLARA_IO_DOWNLOAD.length) === CLARA_IO_DOWNLOAD) {
if (messageBox !== null) {
Window.closeMessageBox(messageBox);
messageBox = null;
}
return;
}
if (message === CLARA_IO_CANCELLED_DOWNLOAD) {
isDownloadBeingCancelled = false;
}
}
marketplaceWindow.webEventReceived.connect(onWebEventReceived);
function onMessageBoxClosed(id, button) { function onMessageBoxClosed(id, button) {
if (id === messageBox && button === CANCEL_BUTTON) { if (id === messageBox && button === CANCEL_BUTTON) {
isDownloadBeingCancelled = true; isDownloadBeingCancelled = true;
messageBox = null; messageBox = null;
marketplaceWindow.emitScriptEvent(CLARA_IO_CANCEL_DOWNLOAD); tablet.emitScriptEvent(CLARA_IO_CANCEL_DOWNLOAD);
} }
} }
Window.messageBoxClosed.connect(onMessageBoxClosed); Window.messageBoxClosed.connect(onMessageBoxClosed);
var toolHeight = 50;
var toolWidth = 50;
var TOOLBAR_MARGIN_Y = 0;
var marketplaceVisible = false;
var marketplaceWebTablet;
// We persist clientOnly data in the .ini file, and reconstitute it on restart.
// To keep things consistent, we pickle the tablet data in Settings, and kill any existing such on restart and domain change.
var persistenceKey = "io.highfidelity.lastDomainTablet";
function showMarketplace() { function showMarketplace() {
tablet.gotoWebScreen(MARKETPLACE_URL_INITIAL); tablet.gotoWebScreen(MARKETPLACE_URL_INITIAL, MARKETPLACES_INJECT_SCRIPT_URL);
// if (shouldShowWebTablet()) {
// updateButtonState(true);
// marketplaceWebTablet = new WebTablet(MARKETPLACE_URL_INITIAL, null, null, true);
// Settings.setValue(persistenceKey, marketplaceWebTablet.pickle());
// marketplaceWebTablet.setScriptURL(MARKETPLACES_INJECT_SCRIPT_URL);
// marketplaceWebTablet.getOverlayObject().webEventReceived.connect(onWebEventReceived);
// } else {
// marketplaceWindow.setURL(MARKETPLACE_URL_INITIAL);
// marketplaceWindow.setVisible(true);
// }
marketplaceVisible = true;
UserActivityLogger.openedMarketplace(); UserActivityLogger.openedMarketplace();
// FIXME - the code to support the following is not yet implented tablet.webEventReceived.connect(function (message) {
/*tablet.setScriptURL(MARKETPLACES_INJECT_SCRIPT_URL); if (message === GOTO_DIRECTORY) {
tablet.webEventRecieved.connect(function (message) { tablet.gotoWebScreen(MARKETPLACES_URL);
if (message === GOTO_DIRECTORY) { }
tablet.gotoWebScreen(MARKETPLACE_URL_INITIAL);
}
if (message === QUERY_CAN_WRITE_ASSESTS) { if (message === QUERY_CAN_WRITE_ASSETS) {
tablet.emitScriptEvent(CAN_WRITE_ASSETS + " " + Entities.canWriteAssets()); tablet.emitScriptEvent(CAN_WRITE_ASSETS + " " + Entities.canWriteAssets());
} }
if (message === WARN_USER_NO_PERMISSIONS) { if (message === WARN_USER_NO_PERMISSIONS) {
Window.alert(NO_PERMISSIONS_ERROR_MESSAGE); Window.alert(NO_PERMISSIONS_ERROR_MESSAGE);
} }
});*/ if (message.slice(0, CLARA_IO_STATUS.length) === CLARA_IO_STATUS) {
if (isDownloadBeingCancelled) {
return;
}
var text = message.slice(CLARA_IO_STATUS.length);
if (messageBox === null) {
messageBox = Window.openMessageBox(CLARA_DOWNLOAD_TITLE, text, CANCEL_BUTTON, NO_BUTTON);
} else {
Window.updateMessageBox(messageBox, CLARA_DOWNLOAD_TITLE, text, CANCEL_BUTTON, NO_BUTTON);
}
return;
}
if (message.slice(0, CLARA_IO_DOWNLOAD.length) === CLARA_IO_DOWNLOAD) {
if (messageBox !== null) {
Window.closeMessageBox(messageBox);
messageBox = null;
}
return;
}
if (message === CLARA_IO_CANCELLED_DOWNLOAD) {
isDownloadBeingCancelled = false;
}
});
} }
function toggleMarketplace() { function toggleMarketplace() {
@ -153,32 +101,25 @@ function toggleMarketplace() {
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
var browseExamplesButton = tablet.addButton({ var marketplaceButton = tablet.addButton({
icon: "icons/tablet-icons/market-i.svg", icon: "icons/tablet-icons/market-i.svg",
text: "MARKET" text: "MARKET"
}); });
function onCanWriteAssetsChanged() { function onCanWriteAssetsChanged() {
var message = CAN_WRITE_ASSETS + " " + Entities.canWriteAssets(); var message = CAN_WRITE_ASSETS + " " + Entities.canWriteAssets();
if (marketplaceWindow.visible) { tablet.emitScriptEvent(message);
marketplaceWindow.emitScriptEvent(message);
}
if (marketplaceWebTablet) {
marketplaceWebTablet.getOverlayObject().emitScriptEvent(message);
}
} }
function onClick() { function onClick() {
toggleMarketplace(); toggleMarketplace();
} }
browseExamplesButton.clicked.connect(onClick); marketplaceButton.clicked.connect(onClick);
Entities.canWriteAssetsChanged.connect(onCanWriteAssetsChanged); Entities.canWriteAssetsChanged.connect(onCanWriteAssetsChanged);
Script.scriptEnding.connect(function () { Script.scriptEnding.connect(function () {
browseExamplesButton.clicked.disconnect(onClick); tablet.removeButton(marketplaceButton);
tablet.removeButton(browseExamplesButton);
marketplaceWindow.visibleChanged.disconnect(onMarketplaceWindowVisibilityChanged);
Entities.canWriteAssetsChanged.disconnect(onCanWriteAssetsChanged); Entities.canWriteAssetsChanged.disconnect(onCanWriteAssetsChanged);
}); });