var APP_URL = Script.resolvePath('Tablet/planetUI.html'); var buttonActivated = false; var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var planetConfig = Script.require(Script.resolvePath('Tablet/planetDefault.json?v=' + Date.now())); var MESSAGES_CHANNEL = "com.highfidelity.planets.dataMessages"; var button = tablet.addButton({ // icon: ICONS.icon, // activeIcon: ICONS.activeIcon, text: 'planet', sortOrder: 1 }); function onClicked() { if (buttonActivated) { button.editProperties({isActive: false}); buttonActivated = false; tablet.gotoHomeScreen(); tablet.webEventReceived.disconnect(onWebEventReceived); } else { tablet.gotoWebScreen(APP_URL); tablet.webEventReceived.connect(onWebEventReceived); button.editProperties({isActive: true}); buttonActivated = true; } } button.clicked.connect(onClicked); function onWebEventReceived(event) { var htmlEvent = JSON.parse(event); switch (htmlEvent.type){ case 'slider': planetConfig[htmlEvent.id].val = htmlEvent.value; Messages.sendMessage(MESSAGES_CHANNEL, JSON.stringify({ id: htmlEvent.id, value: htmlEvent.value })); break; default: } } function scriptEnding() { button.clicked.disconnect(onClicked); tablet.removeButton(button); } Script.scriptEnding.connect(scriptEnding);