From f27a52d83e7dbe99343adb9472cd663a16b3a3d8 Mon Sep 17 00:00:00 2001 From: armored-dragon Date: Thu, 29 Aug 2024 14:55:40 -0500 Subject: [PATCH] Optimized settings.js --- scripts/system/settings/settings.js | 34 ++++++++++++++--------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/scripts/system/settings/settings.js b/scripts/system/settings/settings.js index 2fa2147534..74dad37266 100644 --- a/scripts/system/settings/settings.js +++ b/scripts/system/settings/settings.js @@ -23,6 +23,7 @@ var tablet; var appButton; var active = false; + const url = Script.resolvePath("./settings.qml") tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); appButton = tablet.addButton({ @@ -41,30 +42,27 @@ // Overlay button toggle appButton.clicked.connect(toolbarButtonClicked); tablet.fromQml.connect(fromQML); + tablet.screenChanged.connect(onTabletScreenChanged); function toolbarButtonClicked() { - if (active) { - tablet.gotoHomeScreen(); - active = !active; - appButton.editProperties({ - isActive: active, - }); - } else { - tablet.loadQMLSource(Script.resolvePath("./settings.qml")); - active = !active; - appButton.editProperties({ - isActive: active, - }); - } + if (active) tablet.gotoHomeScreen(); + else tablet.loadQMLSource(url); + + active = !active; + appButton.editProperties({ + isActive: active, + }); } - // Functions - function getActivePolls(){ - // Send hello world - // Add responses to list + function onTabletScreenChanged(type, new_url){ + if (url == new_url) active = true; + else active = false; + + appButton.editProperties({ + isActive: active, + }); } - // Communication function fromQML(event) { console.log(`New QML event:\n${JSON.stringify(event)}`);