mirror of
https://github.com/overte-org/overte.git
synced 2025-07-08 22:40:08 +02:00
103 lines
No EOL
2.5 KiB
JavaScript
103 lines
No EOL
2.5 KiB
JavaScript
//
|
|
// settings.js
|
|
//
|
|
// App to configure Overte
|
|
//
|
|
// Created by Armored Dragon, 2024.
|
|
// 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
|
|
|
|
/* global Script Tablet */
|
|
|
|
// TODO: Fullscreen display?
|
|
|
|
(() => {
|
|
"use strict";
|
|
var tablet;
|
|
var appButton;
|
|
var active = false;
|
|
const url = Script.resolvePath("./settings.qml")
|
|
|
|
tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
|
|
appButton = tablet.addButton({
|
|
icon: Script.resolvePath("./img/icon_white.png"),
|
|
activeIcon: Script.resolvePath("./img/icon_black.png"),
|
|
text: "SETTINGS",
|
|
isActive: active,
|
|
});
|
|
|
|
// When script ends, remove itself from tablet
|
|
Script.scriptEnding.connect(function () {
|
|
console.log("Shutting down Settings.js application");
|
|
tablet.removeButton(appButton);
|
|
Menu.removeMenuItem("Settings", "Graphics...");
|
|
});
|
|
|
|
// Event listeners
|
|
appButton.clicked.connect(toolbarButtonClicked);
|
|
tablet.fromQml.connect(fromQML);
|
|
tablet.screenChanged.connect(onTabletScreenChanged);
|
|
Menu.menuItemEvent.connect(onMenuItemEvent);
|
|
|
|
// Menu button
|
|
Menu.addMenuItem({
|
|
menuName: "Settings",
|
|
menuItemName: "Graphics...",
|
|
afterItem: "Audio...",
|
|
});
|
|
|
|
function onMenuItemEvent(menuItem) {
|
|
if (menuItem === 'Graphics...') {
|
|
toolbarButtonClicked();
|
|
toQML({ type: 'loadPage', page: 'Graphics' })
|
|
}
|
|
}
|
|
|
|
function toolbarButtonClicked() {
|
|
if (active) tablet.gotoHomeScreen();
|
|
else tablet.loadQMLSource(url);
|
|
|
|
active = !active;
|
|
appButton.editProperties({
|
|
isActive: active,
|
|
});
|
|
}
|
|
|
|
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)}`);
|
|
|
|
switch (event.type) {
|
|
case "initialized":
|
|
getActivePolls();
|
|
break;
|
|
case "switch_app":
|
|
if (event.app_url == "hifi/dialogs/GeneralPreferencesDialog.qml") {
|
|
// This page needs to be opened like this because
|
|
Desktop.show("hifi/dialogs/GeneralPreferencesDialog.qml", "GeneralPreferencesDialog");
|
|
return;
|
|
}
|
|
tablet.loadQMLSource(event.app_url);
|
|
break;
|
|
}
|
|
}
|
|
/**
|
|
* Emit a packet to the HTML front end. Easy communication!
|
|
* @param {Object} packet - The Object packet to emit to the HTML
|
|
* @param {("loadPage"|)} packet.type - The type of packet it is
|
|
*/
|
|
function toQML(packet = { type: "" }) {
|
|
tablet.sendToQml(packet);
|
|
}
|
|
})(); |