Skip to content

Commit

Permalink
Add Hide & Show App from settings
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
AleziaKurdis authored Dec 20, 2024
1 parent 8f1c08a commit 3883de2
Showing 1 changed file with 43 additions and 11 deletions.
54 changes: 43 additions & 11 deletions scripts/system/graphicsSettings.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

0 comments on commit 3883de2

Please sign in to comment.