mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-07 14:22:23 +02:00
cleanup references to button, tablet
This commit is contained in:
parent
46061a2a15
commit
ffa5259319
2 changed files with 32 additions and 64 deletions
|
@ -13,13 +13,16 @@ function AppUi(properties) {
|
|||
1. var AppUi = Script.require('appUi');
|
||||
2. Put appname-i.svg, appname-a.svg in graphicsDirectory (where non-default graphicsDirectory can be added in #3).
|
||||
3. ui = new AppUi({buttonName: "APPNAME", home: "qml-or-html-path"});
|
||||
(and if converting an existing app,
|
||||
(And if converting an existing app,
|
||||
define var tablet = ui.tablet, button = ui.button; as needed.
|
||||
remove button.clicked.[dis]connect and tablet.remove(button).)
|
||||
4. Define onOpened and onClosed behavior in #3, if any.
|
||||
(and if converting an existing app, remove screenChanged.[dis]connect.)
|
||||
5. Define onMessage in #3, if any.
|
||||
(and if converting an existing app, remove code that [un]wires that message handling.)
|
||||
(And if converting an existing app, remove screenChanged.[dis]connect.)
|
||||
5. Define onMessage and sendMessage in #3, if any.
|
||||
(And if converting an existing app, remove code that [un]wires that message handling such as
|
||||
fromQml/sendToQml or webEventReceived/emitScriptEvent.)
|
||||
6. (If converting an existing app, cleanup stuff that is no longer necessary, like references to button, tablet,
|
||||
and use isOpen, open(), and close() as needed.)
|
||||
x. lint!
|
||||
*/
|
||||
|
||||
|
@ -36,14 +39,14 @@ function AppUi(properties) {
|
|||
that.checkIsOpen = function checkIsOpen(type, tabletUrl) { // Are we active? Value used to set isOpen.
|
||||
return (type === that.type) && (tabletUrl.indexOf(that.home) >= 0); // Actual url may have prefix or suffix.
|
||||
}
|
||||
that.toOpen = function toOpen() { // How to open the app.
|
||||
that.open = function open() { // How to open the app.
|
||||
if (that.isQML()) {
|
||||
that.tablet.loadQMLSource(that.home);
|
||||
} else {
|
||||
that.tablet.gotoWebScreen(that.home, that.inject);
|
||||
}
|
||||
};
|
||||
that.toClose = function toClose() { // How to close the app.
|
||||
that.close = function close() { // How to close the app.
|
||||
// for toolbar-mode: go back to home screen, this will close the window.
|
||||
that.tablet.gotoHomeScreen();
|
||||
};
|
||||
|
@ -87,7 +90,7 @@ function AppUi(properties) {
|
|||
that.onScreenChanged = function onScreenChanged(type, url) {
|
||||
// Set isOpen, wireEventBridge, set buttonActive as appropriate,
|
||||
// and finally call onOpened() or onClosed() IFF defined.
|
||||
print('hrs fixme onScreenChanged', type, url, that.isOpen);
|
||||
console.debug(that.buttonName, 'onScreenChanged', type, url, that.isOpen);
|
||||
if (that.checkIsOpen(type, url)) {
|
||||
if (!that.isOpen) {
|
||||
that.isOpen = true;
|
||||
|
@ -112,17 +115,17 @@ function AppUi(properties) {
|
|||
that.hasEventBridge = false;
|
||||
that.wireEventBridge = function wireEventBridge(on) {
|
||||
// Sets hasEventBridge and wires onMessage to eventSignal as appropriate, IFF onMessage defined.
|
||||
print('hrs fixme wireEventBridge', on, that.hasEventBridge);
|
||||
console.debug(that.buttonName, 'wireEventBridge', on, that.hasEventBridge);
|
||||
if (!that.onMessage) { return; }
|
||||
if (on) {
|
||||
if (!that.hasEventBridge) {
|
||||
print('hrs fixme connecting', that.eventSignal());
|
||||
console.debug(that.buttonName, 'connecting', that.eventSignal());
|
||||
that.eventSignal().connect(that.onMessage);
|
||||
that.hasEventBridge = true;
|
||||
}
|
||||
} else {
|
||||
if (that.hasEventBridge) {
|
||||
print('hrs fixme connecting', that.eventSignal());
|
||||
console.debug(that.buttonName, 'connecting', that.eventSignal());
|
||||
that.eventSignal().disconnect(that.onMessage);
|
||||
that.hasEventBridge = false;
|
||||
}
|
||||
|
@ -132,18 +135,18 @@ function AppUi(properties) {
|
|||
// To facilitate incremental development, only wire onClicked to do something when "home" is defined in properties.
|
||||
that.onClicked = that.home
|
||||
? function onClicked() {
|
||||
// Call toOpen() or toClose(), and reset type based on current home property.
|
||||
// Call open() or close(), and reset type based on current home property.
|
||||
if (that.isOpen) {
|
||||
that.toClose();
|
||||
that.close();
|
||||
} else {
|
||||
that.type = /.qml$/.test(that.home) ? 'QML' : 'Web'
|
||||
that.toOpen();
|
||||
that.open();
|
||||
}
|
||||
} : that.ignore;
|
||||
that.onScriptEnding = function onScriptEnding() {
|
||||
// Close if necessary, clean up any remaining handlers, and remove the button.
|
||||
if (that.isOpen) {
|
||||
that.toClose();
|
||||
that.close();
|
||||
}
|
||||
that.tablet.screenChanged.disconnect(that.onScreenChanged);
|
||||
if (that.button) {
|
||||
|
|
|
@ -325,7 +325,7 @@ function fromQml(message) { // messages are {method, params}, like json-rpc. See
|
|||
}
|
||||
|
||||
function sendToQml(message) {
|
||||
tablet.sendToQml(message);
|
||||
ui.tablet.sendToQml(message);
|
||||
}
|
||||
function updateUser(data) {
|
||||
print('PAL update:', JSON.stringify(data));
|
||||
|
@ -670,44 +670,24 @@ triggerMapping.from(Controller.Standard.LTClick).peek().to(makeClickHandler(Cont
|
|||
triggerPressMapping.from(Controller.Standard.RT).peek().to(makePressHandler(Controller.Standard.RightHand));
|
||||
triggerPressMapping.from(Controller.Standard.LT).peek().to(makePressHandler(Controller.Standard.LeftHand));
|
||||
|
||||
var ui;
|
||||
// Most apps can have people toggle the tablet closed and open again, and the app should remain "open" even while
|
||||
// the tablet is not shown. However, for the pal, we explicitly close the app and return the tablet to it's
|
||||
// home screen (so that the avatar highlighting goes away).
|
||||
function tabletVisibilityChanged() {
|
||||
if (!tablet.tabletShown && onPalScreen) {
|
||||
ContextOverlay.enabled = true;
|
||||
tablet.gotoHomeScreen();
|
||||
if (!ui.tablet.tabletShown && ui.isOpen) {
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
|
||||
var wasOnPalScreen = false;
|
||||
var onPalScreen = false;
|
||||
/*var hasEventBridge = false;
|
||||
function wireEventBridge(on) {
|
||||
if (on) {
|
||||
if (!hasEventBridge) {
|
||||
tablet.fromQml.connect(fromQml);
|
||||
hasEventBridge = true;
|
||||
}
|
||||
} else {
|
||||
if (hasEventBridge) {
|
||||
tablet.fromQml.disconnect(fromQml);
|
||||
hasEventBridge = false;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
function captureState() {
|
||||
wasOnPalScreen = onPalScreen;
|
||||
onPalScreen = ui.isOpen;
|
||||
//wireEventBridge(onPalScreen);
|
||||
}
|
||||
function on() {
|
||||
captureState();
|
||||
isWired = true;
|
||||
|
||||
ContextOverlay.enabled = false;
|
||||
Users.requestsDomainListData = true;
|
||||
|
||||
audioTimer = createAudioInterval(AUDIO_LEVEL_UPDATE_INTERVAL_MS);
|
||||
|
||||
tablet.tabletShownChanged.connect(tabletVisibilityChanged);
|
||||
ui.tablet.tabletShownChanged.connect(tabletVisibilityChanged);
|
||||
Script.update.connect(updateOverlays);
|
||||
Controller.mousePressEvent.connect(handleMouseEvent);
|
||||
Controller.mouseMoveEvent.connect(handleMouseMoveEvent);
|
||||
|
@ -716,7 +696,6 @@ function on() {
|
|||
triggerPressMapping.enable();
|
||||
populateNearbyUserList();
|
||||
}
|
||||
var button, ui, tablet;
|
||||
|
||||
//
|
||||
// Message from other scripts, such as edit.js
|
||||
|
@ -729,8 +708,8 @@ function receiveMessage(channel, messageString, senderID) {
|
|||
var message = JSON.parse(messageString);
|
||||
switch (message.method) {
|
||||
case 'select':
|
||||
if (!onPalScreen) {
|
||||
tablet.loadQMLSource(ui.home);
|
||||
if (!ui.isOpen) {
|
||||
ui.open();
|
||||
Script.setTimeout(function () { sendToQml(message); }, 1000);
|
||||
} else {
|
||||
sendToQml(message); // Accepts objects, not just strings.
|
||||
|
@ -810,9 +789,8 @@ function avatarDisconnected(nodeID) {
|
|||
|
||||
function clearLocalQMLDataAndClosePAL() {
|
||||
sendToQml({ method: 'clearLocalQMLData' });
|
||||
if (onPalScreen) {
|
||||
ContextOverlay.enabled = true;
|
||||
tablet.gotoHomeScreen();
|
||||
if (ui.isOpen) {
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -838,7 +816,6 @@ function startup() {
|
|||
onMessage: fromQml
|
||||
});
|
||||
tablet = ui.tablet;
|
||||
button = ui.button;
|
||||
Window.domainChanged.connect(clearLocalQMLDataAndClosePAL);
|
||||
Window.domainConnectionRefused.connect(clearLocalQMLDataAndClosePAL);
|
||||
Messages.subscribe(CHANNEL);
|
||||
|
@ -850,40 +827,28 @@ function startup() {
|
|||
}
|
||||
startup();
|
||||
|
||||
|
||||
var isWired = false;
|
||||
var audioTimer;
|
||||
var AUDIO_LEVEL_UPDATE_INTERVAL_MS = 100; // 10hz for now (change this and change the AVERAGING_RATIO too)
|
||||
function off() {
|
||||
captureState();
|
||||
if (isWired) {
|
||||
if (ui.isOpen) { // i.e., only when connected
|
||||
Script.update.disconnect(updateOverlays);
|
||||
Controller.mousePressEvent.disconnect(handleMouseEvent);
|
||||
Controller.mouseMoveEvent.disconnect(handleMouseMoveEvent);
|
||||
tablet.tabletShownChanged.disconnect(tabletVisibilityChanged);
|
||||
ui.tablet.tabletShownChanged.disconnect(tabletVisibilityChanged);
|
||||
Users.usernameFromIDReply.disconnect(usernameFromIDReply);
|
||||
ContextOverlay.enabled = true
|
||||
triggerMapping.disable();
|
||||
triggerPressMapping.disable();
|
||||
Users.requestsDomainListData = false;
|
||||
|
||||
isWired = false;
|
||||
|
||||
if (audioTimer) {
|
||||
Script.clearInterval(audioTimer);
|
||||
}
|
||||
}
|
||||
|
||||
removeOverlays();
|
||||
if (wasOnPalScreen) {
|
||||
ContextOverlay.enabled = true;
|
||||
}
|
||||
ContextOverlay.enabled = true;
|
||||
}
|
||||
|
||||
function shutdown() {
|
||||
if (onPalScreen) {
|
||||
tablet.gotoHomeScreen();
|
||||
}
|
||||
Window.domainChanged.disconnect(clearLocalQMLDataAndClosePAL);
|
||||
Window.domainConnectionRefused.disconnect(clearLocalQMLDataAndClosePAL);
|
||||
Messages.subscribe(CHANNEL);
|
||||
|
|
Loading…
Reference in a new issue