From b377127fc12edcccd5d06039a2bc079d3e526d6a Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Wed, 12 Oct 2016 14:46:04 -0700 Subject: [PATCH 1/3] make marketplace tablet be clientOnly --- scripts/system/libraries/WebTablet.js | 6 +++--- scripts/system/marketplaces/marketplace.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index a255b7a494..5273dbfd01 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -39,7 +39,7 @@ function calcSpawnInfo() { } // ctor -WebTablet = function (url, width, dpi) { +WebTablet = function (url, width, dpi, clientOnly) { var ASPECT = 4.0 / 3.0; var WIDTH = width || DEFAULT_WIDTH; @@ -63,7 +63,7 @@ WebTablet = function (url, width, dpi) { dimensions: {x: WIDTH, y: HEIGHT, z: DEPTH}, parentID: MyAvatar.sessionUUID, parentJointIndex: -2 - }); + }, clientOnly); var WEB_ENTITY_REDUCTION_FACTOR = {x: 0.78, y: 0.85}; var WEB_ENTITY_Z_OFFSET = -0.01; @@ -84,7 +84,7 @@ WebTablet = function (url, width, dpi) { dpi: DPI, parentID: this.tabletEntityID, parentJointIndex: -1 - }); + }, clientOnly); this.state = "idle"; }; diff --git a/scripts/system/marketplaces/marketplace.js b/scripts/system/marketplaces/marketplace.js index 563a5289fc..29a21c5c2d 100644 --- a/scripts/system/marketplaces/marketplace.js +++ b/scripts/system/marketplaces/marketplace.js @@ -40,7 +40,7 @@ function shouldShowWebTablet() { function showMarketplace(marketplaceID) { if (shouldShowWebTablet()) { updateButtonState(true); - marketplaceWebTablet = new WebTablet("https://metaverse.highfidelity.com/marketplace"); + marketplaceWebTablet = new WebTablet("https://metaverse.highfidelity.com/marketplace", null, null, false); } else { var url = MARKETPLACE_URL; if (marketplaceID) { From 78f96a80bd217827a439afa0862611eec5ac97ed Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Wed, 12 Oct 2016 16:31:12 -0700 Subject: [PATCH 2/3] oops --- scripts/system/marketplaces/marketplace.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/system/marketplaces/marketplace.js b/scripts/system/marketplaces/marketplace.js index 29a21c5c2d..2cd9abed27 100644 --- a/scripts/system/marketplaces/marketplace.js +++ b/scripts/system/marketplaces/marketplace.js @@ -40,7 +40,7 @@ function shouldShowWebTablet() { function showMarketplace(marketplaceID) { if (shouldShowWebTablet()) { updateButtonState(true); - marketplaceWebTablet = new WebTablet("https://metaverse.highfidelity.com/marketplace", null, null, false); + marketplaceWebTablet = new WebTablet("https://metaverse.highfidelity.com/marketplace", null, null, true); } else { var url = MARKETPLACE_URL; if (marketplaceID) { From d232d115d5ae5e4870ccbfd9ccfeee5d78927102 Mon Sep 17 00:00:00 2001 From: howard-stearns Date: Thu, 13 Oct 2016 16:53:44 -0700 Subject: [PATCH 3/3] persist tablet data, and clean it up on startup --- scripts/system/libraries/WebTablet.js | 12 +++++++++- scripts/system/marketplaces/marketplace.js | 26 +++++++++++++++++++--- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 5273dbfd01..0c21ea22ae 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -93,4 +93,14 @@ WebTablet.prototype.destroy = function () { Entities.deleteEntity(this.webEntityID); Entities.deleteEntity(this.tabletEntityID); }; - +WebTablet.prototype.pickle = function () { + return JSON.stringify({webEntityID: this.webEntityID, tabletEntityID: this.tabletEntityID}); +}; +WebTablet.unpickle = function (string) { + if (!string) { + return; + } + var tablet = JSON.parse(string); + tablet.__proto__ = WebTablet.prototype; + return tablet; +}; diff --git a/scripts/system/marketplaces/marketplace.js b/scripts/system/marketplaces/marketplace.js index 2cd9abed27..894dae7eac 100644 --- a/scripts/system/marketplaces/marketplace.js +++ b/scripts/system/marketplaces/marketplace.js @@ -30,6 +30,10 @@ var TOOLBAR_MARGIN_Y = 0; var marketplaceVisible = false; var marketplaceWebTablet; +// We persist clientOnly data in the .ini file, and reconsistitute 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 shouldShowWebTablet() { var rightPose = Controller.getPoseValue(Controller.Standard.RightHand); var leftPose = Controller.getPoseValue(Controller.Standard.LeftHand); @@ -41,6 +45,7 @@ function showMarketplace(marketplaceID) { if (shouldShowWebTablet()) { updateButtonState(true); marketplaceWebTablet = new WebTablet("https://metaverse.highfidelity.com/marketplace", null, null, true); + Settings.setValue(persistenceKey, marketplaceWebTablet.pickle()); } else { var url = MARKETPLACE_URL; if (marketplaceID) { @@ -54,14 +59,25 @@ function showMarketplace(marketplaceID) { UserActivityLogger.openedMarketplace(); } +function hideTablet(tablet) { + if (!tablet) { + return; + } + updateButtonState(false); + tablet.destroy(); + marketplaceWebTablet = null; + Settings.setValue(persistenceKey, ""); +} +function clearOldTablet() { // If there was a tablet from previous domain or session, kill it and let it be recreated + var tablet = WebTablet.unpickle(Settings.getValue(persistenceKey, "")); + hideTablet(tablet); +} function hideMarketplace() { if (marketplaceWindow.visible) { marketplaceWindow.setVisible(false); marketplaceWindow.setURL("about:blank"); } else if (marketplaceWebTablet) { - updateButtonState(false); - marketplaceWebTablet.destroy(); - marketplaceWebTablet = null; + hideTablet(marketplaceWebTablet); } marketplaceVisible = false; } @@ -102,6 +118,10 @@ function onClick() { browseExamplesButton.clicked.connect(onClick); marketplaceWindow.visibleChanged.connect(onMarketplaceWindowVisibilityChanged); +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)}), +// but the HUD version stays around, so lets do the same. + Script.scriptEnding.connect(function () { toolBar.removeButton("marketplace"); browseExamplesButton.clicked.disconnect(onClick);