This commit is contained in:
howard-stearns 2018-07-16 16:28:44 -07:00
parent f1fed37763
commit 2c92b02b95
2 changed files with 71 additions and 70 deletions

View file

@ -1,3 +1,5 @@
"use strict";
/*global Tablet, Script*/
//
// libraries/appUi.js
//
@ -25,7 +27,6 @@ function AppUi(properties) {
and use isOpen, open(), and close() as needed.)
7. lint!
*/
var that = this;
function defaultButton(name, suffix) {
var base = that[name] || (that.buttonPrefix + suffix);
@ -38,7 +39,7 @@ function AppUi(properties) {
that.graphicsDirectory = "icons/tablet-icons/"; // Where to look for button svgs. See below.
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.open = function open() { // How to open the app.
if (that.isQML()) {
that.tablet.loadQMLSource(that.home);
@ -62,7 +63,7 @@ function AppUi(properties) {
};
that.isQML = function isQML() { // We set type property in onClick.
return that.type === 'QML';
}
};
that.eventSignal = function eventSignal() { // What signal to hook onMessage to.
return that.isQML() ? that.tablet.fromQml : that.tablet.webEventReceived;
};
@ -116,11 +117,11 @@ function AppUi(properties) {
// HTML event bridge uses strings, not objects. Here we abstract over that.
// (Although injected javascript still has to use JSON.stringify/JSON.parse.)
that.sendToHtml = function (messageObject) { that.tablet.emitScriptEvent(JSON.stringify(messageObject)); };
that.fromHtml = function (messageString) { that.onMessage(JSON.parse(messageString)); }
that.fromHtml = function (messageString) { that.onMessage(JSON.parse(messageString)); };
that.wireEventBridge = function wireEventBridge(on) {
// Uniquivocally sets that.sendMessage(messageObject) to do the right thing.
// Sets hasEventBridge and wires onMessage to eventSignal as appropriate, IFF onMessage defined.
var isQml = that.isQML();
var handler, isQml = that.isQML();
console.debug(that.buttonName, 'wireEventBridge', on, that.hasEventBridge);
// Outbound (always, regardless of whether there is an inbound handler).
if (on) {
@ -132,7 +133,7 @@ function AppUi(properties) {
if (!that.onMessage) { return; }
// Inbound
var handler = isQml ? that.onMessage : that.fromHtml;
handler = isQml ? that.onMessage : that.fromHtml;
if (on) {
if (!that.hasEventBridge) {
console.debug(that.buttonName, 'connecting', that.eventSignal());
@ -155,7 +156,7 @@ function AppUi(properties) {
if (that.isOpen) {
that.close();
} else {
that.type = /.qml$/.test(that.home) ? 'QML' : 'Web'
that.type = /.qml$/.test(that.home) ? 'QML' : 'Web';
that.open();
}
} : that.ignore;
@ -176,5 +177,5 @@ function AppUi(properties) {
that.tablet.screenChanged.connect(that.onScreenChanged);
that.button.clicked.connect(that.onClicked);
Script.scriptEnding.connect(that.onScriptEnding);
};
}
module.exports = AppUi;

View file

@ -41,6 +41,7 @@ var HOVER_TEXTURES = {
var UNSELECTED_COLOR = { red: 0x1F, green: 0xC6, blue: 0xA6};
var SELECTED_COLOR = {red: 0xF3, green: 0x91, blue: 0x29};
var HOVER_COLOR = {red: 0xD0, green: 0xD0, blue: 0xD0}; // almost white for now
var METAVERSE_BASE = Account.metaverseServerURL;
Script.include("/~/system/libraries/controllers.js");
@ -222,7 +223,7 @@ function convertDbToLinear(decibels) {
return Math.pow(2, decibels / 10.0);
}
function fromQml(message) { // messages are {method, params}, like json-rpc. See also sendToQml.
var data;
var data, connectionUserName, friendUserName;
switch (message.method) {
case 'selected':
selectedIds = message.params;
@ -282,7 +283,7 @@ function fromQml(message) { // messages are {method, params}, like json-rpc. See
}
getConnectionData(false);
});
break
break;
case 'removeFriend':
friendUserName = message.params;
@ -297,7 +298,7 @@ function fromQml(message) { // messages are {method, params}, like json-rpc. See
}
getConnectionData(friendUserName);
});
break
break;
case 'addFriend':
friendUserName = message.params;
print("Adding " + friendUserName + " to friends.");
@ -335,7 +336,6 @@ function updateUser(data) {
// User management services
//
// These are prototype versions that will be changed when the back end changes.
var METAVERSE_BASE = Account.metaverseServerURL;
function requestJSON(url, callback) { // callback(data) if successfull. Logs otherwise.
request({
@ -363,7 +363,7 @@ function getProfilePicture(username, callback) { // callback(url) if successfull
});
}
function getAvailableConnections(domain, callback) { // callback([{usename, location}...]) if successfull. (Logs otherwise)
url = METAVERSE_BASE + '/api/v1/users?per_page=400&'
var url = METAVERSE_BASE + '/api/v1/users?per_page=400&';
if (domain) {
url += 'status=' + domain.slice(1, -1); // without curly braces
} else {
@ -374,7 +374,7 @@ function getAvailableConnections(domain, callback) { // callback([{usename, loca
});
}
function getInfoAboutUser(specificUsername, callback) {
url = METAVERSE_BASE + '/api/v1/users?filter=connections'
var url = METAVERSE_BASE + '/api/v1/users?filter=connections';
requestJSON(url, function (connectionsData) {
for (user in connectionsData.users) {
if (connectionsData.users[user].username === specificUsername) {