From 3883de26bad26ef326a935a0d290a85d8fe59f20 Mon Sep 17 00:00:00 2001 From: Alezia Kurdis <60075796+AleziaKurdis@users.noreply.github.com> Date: Thu, 19 Dec 2024 21:56:30 -0500 Subject: [PATCH] Add Hide & Show App from settings This make the tablet app to be launched or not based on new setting that control its present in the tablet/toolbar. It also make it able to discard or restore itself on the tablet/toolbar if the option is checked in the Setting menu. (See PR 1274 for the new setting) --- scripts/system/graphicsSettings.js | 54 ++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/scripts/system/graphicsSettings.js b/scripts/system/graphicsSettings.js index df556a91b1..748eafca24 100644 --- a/scripts/system/graphicsSettings.js +++ b/scripts/system/graphicsSettings.js @@ -1,15 +1,20 @@ // // graphicsSettings.js // -// Created by Kalila L. on 8/5/2020 +// Created by Kalila L. on August 5th, 2020 // Copyright 2020 Vircadia contributors. +// Copyright 2024 Overte e.V. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // (function() { // BEGIN LOCAL_SCOPE - + var channelComm = "Overte-ShowGraphicsIconChanged"; + var appStatus = false; + var GRAPHICS_HIDE_AND_SHOW_SETTING_KEY = "showGraphicsIcon"; + var GRAPHICS_HIDE_AND_SHOW_DEFAULT_VALUE = true; + var AppUi = Script.require('appUi'); // cellphone-cog MDI @@ -49,22 +54,49 @@ } function startup() { - ui = new AppUi({ - buttonName: BUTTON_NAME, - sortOrder: 8, - normalButton: getIcon(), - activeButton: getIcon().replace('white', 'black'), - home: GRAPHICS_QML_SOURCE - }); + if (!appStatus) { + ui = new AppUi({ + buttonName: BUTTON_NAME, + sortOrder: 8, + normalButton: getIcon(), + activeButton: getIcon().replace('white', 'black'), + home: GRAPHICS_QML_SOURCE + }); + } + appStatus = true; } function shutdown() { + if (appStatus) { + ui.onScriptEnding(); + appStatus = false; + } + } + + function cleanup() { + Messages.messageReceived.disconnect(onMessageReceived); + Messages.unsubscribe(channelComm); + } + + function onMessageReceived(channel, message, sender, localOnly) { + if (channel === channelComm && localOnly) { + if (Settings.getValue(GRAPHICS_HIDE_AND_SHOW_SETTING_KEY, GRAPHICS_HIDE_AND_SHOW_DEFAULT_VALUE)) { + startup(); + } else { + shutdown(); + } + } } // // Run the functions. // - startup(); - Script.scriptEnding.connect(shutdown); + if (Settings.getValue(GRAPHICS_HIDE_AND_SHOW_SETTING_KEY, GRAPHICS_HIDE_AND_SHOW_DEFAULT_VALUE)) { + startup(); + } + Messages.subscribe(channelComm); + Messages.messageReceived.connect(onMessageReceived); + + Script.scriptEnding.connect(cleanup); }()); // END LOCAL_SCOPE