From 33fa8c4f8650addff9d1b95fa03f712e13c62cc5 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Wed, 9 Aug 2017 11:43:44 -0700 Subject: [PATCH] Fix bugs and also change to single setting --- .../resources/controllers/keyboardMouse.json | 2 +- scripts/system/html/js/marketplacesInject.js | 37 ++++--- scripts/system/marketplaces/marketplaces.js | 100 ++++++++++-------- 3 files changed, 80 insertions(+), 59 deletions(-) diff --git a/interface/resources/controllers/keyboardMouse.json b/interface/resources/controllers/keyboardMouse.json index f377e02e5f..54d2467f78 100644 --- a/interface/resources/controllers/keyboardMouse.json +++ b/interface/resources/controllers/keyboardMouse.json @@ -131,6 +131,6 @@ { "from": "Keyboard.Space", "to": "Actions.SHIFT" }, { "from": "Keyboard.R", "to": "Actions.ACTION1" }, { "from": "Keyboard.T", "to": "Actions.ACTION2" }, - { "from": "Keyboard.RightMouseClicked", "to": "Actions.ContextMenu" } + { "from": "Keyboard.Tab", "to": "Actions.ContextMenu" } ] } diff --git a/scripts/system/html/js/marketplacesInject.js b/scripts/system/html/js/marketplacesInject.js index f4136de933..369e77fd70 100644 --- a/scripts/system/html/js/marketplacesInject.js +++ b/scripts/system/html/js/marketplacesInject.js @@ -361,18 +361,7 @@ } } - function onLoad() { - - EventBridge.scriptEventReceived.connect(function (message) { - if (message.slice(0, CAN_WRITE_ASSETS.length) === CAN_WRITE_ASSETS) { - canWriteAssets = message.slice(-4) === "true"; - } - - if (message.slice(0, CLARA_IO_CANCEL_DOWNLOAD.length) === CLARA_IO_CANCEL_DOWNLOAD) { - cancelClaraDownload(); - } - }); - + function injectCode() { var DIRECTORY = 0; var HIFI = 1; var CLARA = 2; @@ -400,7 +389,29 @@ } } + function onLoad() { + EventBridge.scriptEventReceived.connect(function (message) { + var parsedJsonMessage = JSON.parse(message); + + if (message.slice(0, CAN_WRITE_ASSETS.length) === CAN_WRITE_ASSETS) { + canWriteAssets = message.slice(-4) === "true"; + } else if (message.slice(0, CLARA_IO_CANCEL_DOWNLOAD.length) === CLARA_IO_CANCEL_DOWNLOAD) { + cancelClaraDownload(); + } else if (parsedJsonMessage.type === "marketplaces") { + if (parsedJsonMessage.action === "inspectionModeSetting") { + confirmAllPurchases = !!parsedJsonMessage.data; + injectCode(); + } + } + }); + + // Request inspection mode setting + // Code is injected into the webpage after the setting comes back. + EventBridge.emitWebEvent(JSON.stringify({ + type: "REQUEST_SETTING" + })); + } + // Load / unload. window.addEventListener("load", onLoad); // More robust to Web site issues than using $(document).ready(). - }()); diff --git a/scripts/system/marketplaces/marketplaces.js b/scripts/system/marketplaces/marketplaces.js index 74812bb013..2acc853178 100644 --- a/scripts/system/marketplaces/marketplaces.js +++ b/scripts/system/marketplaces/marketplaces.js @@ -58,51 +58,6 @@ function showMarketplace() { UserActivityLogger.openedMarketplace(); tablet.gotoWebScreen(MARKETPLACE_URL_INITIAL, MARKETPLACES_INJECT_SCRIPT_URL); - tablet.webEventReceived.connect(function (message) { - var parsedJsonMessage = JSON.parse(message); - if (parsedJsonMessage.type === "CHECKOUT") { - tablet.sendToQml({ method: 'updateCheckoutQML', params: parsedJsonMessage }); - tablet.pushOntoStack(MARKETPLACE_CHECKOUT_QML_PATH); - } - - if (message === GOTO_DIRECTORY) { - tablet.gotoWebScreen(MARKETPLACES_URL, MARKETPLACES_INJECT_SCRIPT_URL); - } - - if (message === QUERY_CAN_WRITE_ASSETS) { - tablet.emitScriptEvent(CAN_WRITE_ASSETS + " " + Entities.canWriteAssets()); - } - - if (message === WARN_USER_NO_PERMISSIONS) { - 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; - } - }); } var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); @@ -145,12 +100,67 @@ tablet.screenChanged.connect(onScreenChanged); Entities.canWriteAssetsChanged.connect(onCanWriteAssetsChanged); + function onMessage(message) { + var parsedJsonMessage = JSON.parse(message); + if (parsedJsonMessage.type === "CHECKOUT") { + tablet.sendToQml({ method: 'updateCheckoutQML', params: parsedJsonMessage }); + tablet.pushOntoStack(MARKETPLACE_CHECKOUT_QML_PATH); + } else if (parsedJsonMessage.type === "REQUEST_SETTING") { + tablet.emitScriptEvent(JSON.stringify({ + type: "marketplaces", + action: "inspectionModeSetting", + data: Settings.getValue("inspectionMode", false) + })); + } + + if (message === GOTO_DIRECTORY) { + tablet.gotoWebScreen(MARKETPLACES_URL, MARKETPLACES_INJECT_SCRIPT_URL); + } + + if (message === QUERY_CAN_WRITE_ASSETS) { + tablet.emitScriptEvent(CAN_WRITE_ASSETS + " " + Entities.canWriteAssets()); + } + + if (message === WARN_USER_NO_PERMISSIONS) { + 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; + } + } + + tablet.webEventReceived.connect(onMessage); + Script.scriptEnding.connect(function () { if (onMarketplaceScreen) { tablet.gotoHomeScreen(); } tablet.removeButton(marketplaceButton); tablet.screenChanged.disconnect(onScreenChanged); + tablet.webEventReceived.disconnect(onMessage); Entities.canWriteAssetsChanged.disconnect(onCanWriteAssetsChanged); });