Fixes apps and metadata loading locally or remotely.

This commit is contained in:
Kasen IO 2020-03-01 16:13:02 -05:00
parent 0f5a83b970
commit 22169d9458
3 changed files with 323 additions and 311 deletions

View file

@ -34,7 +34,7 @@ var DEFAULT_SCRIPTS_COMBINED = [
"system/emote.js", "system/emote.js",
"system/miniTablet.js", "system/miniTablet.js",
"system/audioMuteOverlay.js", "system/audioMuteOverlay.js",
"system/keyboardShortcuts/keyboardShortcuts.js", "system/keyboardShortcuts/keyboardShortcuts.js"
]; ];
var DEFAULT_SCRIPTS_SEPARATE = [ var DEFAULT_SCRIPTS_SEPARATE = [
"system/controllers/controllerScripts.js", "system/controllers/controllerScripts.js",

View file

@ -11,126 +11,126 @@
// //
// Distributed under the Apache License, Version 2.0. // Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
(function() { (function() {
var ROOT = Script.resolvePath('').split("app-more.js")[0]; var ROOT = Script.resolvePath('').split("app-more.js")[0];
var APP_NAME = "MORE..."; var APP_NAME = "MORE...";
var APP_URL = ROOT + "more.html"; var APP_URL = ROOT + "more.html";
var APP_ICON_INACTIVE = ROOT + "appicon_i.png"; var APP_ICON_INACTIVE = ROOT + "appicon_i.png";
var APP_ICON_ACTIVE = ROOT + "appicon_a.png"; var APP_ICON_ACTIVE = ROOT + "appicon_a.png";
var Appstatus = false; var Appstatus = false;
var lastProcessing = { var lastProcessing = {
"action": "", "action": "",
"script": "" "script": ""
}; };
var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system"); var tablet = Tablet.getTablet("com.highfidelity.interface.tablet.system");
tablet.screenChanged.connect(onScreenChanged); tablet.screenChanged.connect(onScreenChanged);
var button = tablet.addButton({ var button = tablet.addButton({
text: APP_NAME, text: APP_NAME,
icon: APP_ICON_INACTIVE, icon: APP_ICON_INACTIVE,
activeIcon: APP_ICON_ACTIVE activeIcon: APP_ICON_ACTIVE
}); });
function clicked() { function clicked() {
if (Appstatus == true) { if (Appstatus == true) {
tablet.webEventReceived.disconnect(onMoreAppWebEventReceived); tablet.webEventReceived.disconnect(onMoreAppWebEventReceived);
tablet.gotoHomeScreen(); tablet.gotoHomeScreen();
Appstatus = false; Appstatus = false;
} else { } else {
tablet.gotoWebScreen(APP_URL); tablet.gotoWebScreen(APP_URL);
tablet.webEventReceived.connect(onMoreAppWebEventReceived); tablet.webEventReceived.connect(onMoreAppWebEventReceived);
Appstatus = true; Appstatus = true;
} }
button.editProperties({ button.editProperties({
isActive: Appstatus isActive: Appstatus
}); });
} }
button.clicked.connect(clicked); button.clicked.connect(clicked);
function sendRunningScriptList() { function sendRunningScriptList() {
var currentlyRunningScripts = ScriptDiscoveryService.getRunning(); var currentlyRunningScripts = ScriptDiscoveryService.getRunning();
tablet.emitScriptEvent(JSON.stringify(currentlyRunningScripts)); tablet.emitScriptEvent(JSON.stringify(currentlyRunningScripts));
} }
function onMoreAppWebEventReceived(eventz) { function onMoreAppWebEventReceived(eventz) {
if (typeof eventz === "string") { if (typeof eventz === "string") {
eventzget = JSON.parse(eventz); eventzget = JSON.parse(eventz);
//print("EVENT ACTION: " + eventzget.action); //print("EVENT ACTION: " + eventzget.action);
//print("EVENT SCRIPT: " + eventzget.script); //print("EVENT SCRIPT: " + eventzget.script);
if (eventzget.action === "installScript") { if (eventzget.action === "installScript") {
if (lastProcessing.action == eventzget.action && lastProcessing.script == eventzget.script) { if (lastProcessing.action == eventzget.action && lastProcessing.script == eventzget.script) {
return; return;
} else { } else {
ScriptDiscoveryService.loadOneScript(eventzget.script); ScriptDiscoveryService.loadOneScript(eventzget.script);
lastProcessing.action = eventzget.action; lastProcessing.action = eventzget.action;
lastProcessing.script = eventzget.script; lastProcessing.script = eventzget.script;
Script.setTimeout(function() { Script.setTimeout(function() {
sendRunningScriptList(); sendRunningScriptList();
}, 2000); }, 2000);
} }
} }
if (eventzget.action === "uninstallScript") { if (eventzget.action === "uninstallScript") {
if (lastProcessing.action == eventzget.action && lastProcessing.script == eventzget.script) { if (lastProcessing.action == eventzget.action && lastProcessing.script == eventzget.script) {
return; return;
} else { } else {
ScriptDiscoveryService.stopScript(eventzget.script, false); ScriptDiscoveryService.stopScript(eventzget.script, false);
lastProcessing.action = eventzget.action; lastProcessing.action = eventzget.action;
lastProcessing.script = eventzget.script; lastProcessing.script = eventzget.script;
Script.setTimeout(function() { Script.setTimeout(function() {
sendRunningScriptList(); sendRunningScriptList();
}, 2000); }, 2000);
} }
} }
if (eventzget.action === "requestRunningScriptData") { if (eventzget.action === "requestRunningScriptData") {
sendRunningScriptList(); sendRunningScriptList();
} }
} }
} }
function onScreenChanged(type, url) { function onScreenChanged(type, url) {
if (type == "Web" && url.indexOf(APP_URL) != -1) { if (type == "Web" && url.indexOf(APP_URL) != -1) {
//Active //Active
//print("MORE... ACTIVE"); //print("MORE... ACTIVE");
Appstatus = true; Appstatus = true;
} else { } else {
//Inactive //Inactive
//print("MORE... INACTIVE"); //print("MORE... INACTIVE");
Appstatus = false; Appstatus = false;
} }
button.editProperties({ button.editProperties({
isActive: Appstatus isActive: Appstatus
}); });
} }
function cleanup() { function cleanup() {
if (Appstatus) { if (Appstatus) {
tablet.gotoHomeScreen(); tablet.gotoHomeScreen();
tablet.webEventReceived.disconnect(onMoreAppWebEventReceived); tablet.webEventReceived.disconnect(onMoreAppWebEventReceived);
} }
tablet.screenChanged.disconnect(onScreenChanged); tablet.screenChanged.disconnect(onScreenChanged);
tablet.removeButton(button); tablet.removeButton(button);
} }
Script.scriptEnding.connect(cleanup); Script.scriptEnding.connect(cleanup);
}()); }());

View file

@ -9,217 +9,229 @@
--> -->
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<script type="text/javascript" src="https://kasenvr.github.io/community-apps/applications/metadata.js"></script> <script>
<script> //Paths
//Parameters var currentPath = window.location.protocol + "//" + window.location.host + window.location.pathname;
function findGetParameter(parameterName) { var rootPath;
var result = null, var metadataScript = document.createElement("script");
tmp = [];
var items = location.search.substr(1).split("&"); if (currentPath.includes("kasenvr.github.io") || !currentPath.includes("file:/")) { // Loading app from repo or filesystem.
for (var index = 0; index < items.length; index++) { rootPath = currentPath.replace("more/more.html", "applications/");
tmp = items[index].split("="); metadataScript.src = "../applications/metadata.js";
if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]); console.info("Loading apps and metadata locally.");
} } else {
return result; rootPath = "https://kasenvr.github.io/community-apps/applications/";
} metadataScript.src = "https://kasenvr.github.io/community-apps/applications/metadata.js";
console.info("Loading apps and metadata remotely.");
var offset = findGetParameter("offset"); }
if(offset === null){offset = 0;}
offset = parseInt(offset);
var perpage = findGetParameter("perpage");
if(perpage === null){perpage = 25;}
perpage = parseInt(perpage);
var search = findGetParameter("search");
if(search === null){search = "";}
//Search
function doSearch(keyword){
location.href = "more.html?offset=0&search=" + encodeURI(keyword);
}
function clearSearch(){ document.getElementsByTagName("head")[0].appendChild(metadataScript);
location.href = "more.html?offset=0";
} //Parameters
function findGetParameter(parameterName) {
//Paths var result = null,
var currentPath = window.location.protocol + "//" + window.location.host + window.location.pathname; tmp = [];
var rootPath = "https://kasenvr.github.io/community-apps/applications/"; var items = location.search.substr(1).split("&");
for (var index = 0; index < items.length; index++) {
//Running scripts tmp = items[index].split("=");
var buttonList = []; if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
}
function requestRunningScriptData() { return result;
var readyEvent = { }
"action": "requestRunningScriptData"
}; var offset = findGetParameter("offset");
EventBridge.emitWebEvent(JSON.stringify(readyEvent)); if(offset === null){offset = 0;}
} offset = parseInt(offset);
var perpage = findGetParameter("perpage");
if(perpage === null){perpage = 25;}
perpage = parseInt(perpage);
var search = findGetParameter("search");
if(search === null){search = "";}
//Search
function doSearch(keyword){
location.href = "more.html?offset=0&search=" + encodeURI(keyword);
}
EventBridge.scriptEventReceived.connect(function(message){ function clearSearch(){
//update the buttons location.href = "more.html?offset=0";
buttonList.forEach(function(item){ }
var btn = "";
if (message.indexOf(item.url) != -1) { //Running scripts
//Means already running var buttonList = [];
btn = "<button class='uninstall' onclick='uninstall(" + '"' + item.url + '"' + ", " + '"' + item.id + '"' + ");'>Uninstall</button>";
} else { function requestRunningScriptData() {
//Means not already installed var readyEvent = {
btn = "<button class='install' onclick='install(" + '"' + item.url + '"' + ", " + '"' + item.id + '"' + ");'>Install</button>"; "action": "requestRunningScriptData"
} };
EventBridge.emitWebEvent(JSON.stringify(readyEvent));
document.getElementById(item.id).innerHTML = btn; }
});
EventBridge.scriptEventReceived.connect(function(message){
//update the buttons
buttonList.forEach(function(item){
var btn = "";
if (message.indexOf(item.url) != -1) {
//Means already running
btn = "<button class='uninstall' onclick='uninstall(" + '"' + item.url + '"' + ", " + '"' + item.id + '"' + ");'>Uninstall</button>";
} else {
//Means not already installed
btn = "<button class='install' onclick='install(" + '"' + item.url + '"' + ", " + '"' + item.id + '"' + ");'>Install</button>";
}
document.getElementById(item.id).innerHTML = btn;
});
}); });
function install(script, btnId){ function install(script, btnId){
//then change btn appearence //then change btn appearence
var btn = "<button class='processing' >Processing...</button>"; var btn = "<button class='processing' >Processing...</button>";
document.getElementById(btnId).innerHTML = btn; document.getElementById(btnId).innerHTML = btn;
//Action //Action
var readyEvent = { var readyEvent = {
"action": "installScript", "action": "installScript",
"script": script "script": script
}; };
EventBridge.emitWebEvent(JSON.stringify(readyEvent));
}
function uninstall(script, btnId){
//then change btn appearence
var btn = "<button class='processing' >Processing...</button>";
document.getElementById(btnId).innerHTML = btn;
//Action
var readyEvent = {
"action": "uninstallScript",
"script": script
};
EventBridge.emitWebEvent(JSON.stringify(readyEvent)); EventBridge.emitWebEvent(JSON.stringify(readyEvent));
}
}
function uninstall(script, btnId){
//then change btn appearence
var btn = "<button class='processing' >Processing...</button>";
document.getElementById(btnId).innerHTML = btn;
//Action
var readyEvent = {
"action": "uninstallScript",
"script": script
};
EventBridge.emitWebEvent(JSON.stringify(readyEvent));
}
</script> </script>
<link href="https://fonts.googleapis.com/css?family=Merriweather|Quicksand:400,700&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Merriweather|Quicksand:400,700&display=swap" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet"> <link href="css/styles.css" rel="stylesheet">
</head> </head>
<body><form name = "searchbar"> <body><form name = "searchbar">
<h1 class="mainTitle">Add more functionalities...</h1> <h1 class="mainTitle">Add more functionalities...</h1>
<p class="mainDesc">Want to add your own app? Read the <a href="../web/index.html">guide</a>!</p> <p class="mainDesc">Want to add your own app? Read the <a href="../web/index.html">guide</a>!</p>
<table style = "width:100%;"> <table style = "width:100%;">
<tr > <tr >
<td style = "vertical-align:middle; text-align:left;"> <td style = "vertical-align:middle; text-align:left;">
<table> <table>
<tr> <tr>
<td style = "vertical-align:middle; text-align:left;"> <td style = "vertical-align:middle; text-align:left;">
<div class = "searchbox"> <div class = "searchbox">
<input class = "searchtextbox" name = "searchtextbox" size = "26" maxlength="32"> <a href="#" onclick='clearSearch();'><img src="del-x-16.png"></a> <input class = "searchtextbox" name = "searchtextbox" size = "26" maxlength="32"> <a href="#" onclick='clearSearch();'><img src="del-x-16.png"></a>
</div> </div>
</td> </td>
<td style = "vertical-align:middle; text-align:left;"> <td style = "vertical-align:middle; text-align:left;">
<a href = "#" onclick = 'doSearch(document.searchbar.searchtextbox.value);'><img src="search-32.png"></a> <a href = "#" onclick = 'doSearch(document.searchbar.searchtextbox.value);'><img src="search-32.png"></a>
</td> </td>
</tr> </tr>
</table> </table>
</td> </td>
<td style = "vertical-align:middle; text-align:right;"> <td style = "vertical-align:middle; text-align:right;">
<div id = 'pager_top' style = "vertical-align: middle;"></div> <div id = 'pager_top' style = "vertical-align: middle;"></div>
</td> </td>
</tr> </tr>
</table> </table>
</form><br> </form><br>
<div id = "data"></div> <div id = "data"></div>
<div style="width:98%; text-align:right;"><div style = "vertical-align: middle;" id = 'pager_footer'></div> <div style="width:98%; text-align:right;"><div style = "vertical-align: middle;" id = 'pager_footer'></div>
<script> <script>
document.searchbar.searchtextbox.value = search; document.searchbar.searchtextbox.value = search;
function DisplayApp(item) { function DisplayApp(item) {
pageContent = pageContent + "<a name = '" + window.btoa(item.name) + "'><table class='item'><tr>"; pageContent = pageContent + "<a name = '" + window.btoa(item.name) + "'><table class='item'><tr>";
pageContent = pageContent + "<td><div class='iconContainer'><img src='" + rootPath + item.icon + "' style='width:50px;'><br><font class = 'caption'>" + item.caption + "</font></div></td>"; pageContent = pageContent + "<td><div class='iconContainer'><img src='" + rootPath + item.icon + "' style='width:50px;'><br><font class = 'caption'>" + item.caption + "</font></div></td>";
var btn = ""; var btn = "";
var absoluteJsFile = rootPath + item.jsfile; var absoluteJsFile = rootPath + item.jsfile;
var btn = "<button class='install' onclick = 'install(" + '"' + absoluteJsFile + " ," + window.btoa(item.name) + '"' + ");'>Install</button>";
var btndata = {
"url": absoluteJsFile,
"id": window.btoa(item.name)
};
buttonList.push(btndata);
pageContent = pageContent + "<td><font class='appname'>" + item.name + "<br></font><font class = 'appdesc'>" + item.description + "<br></font><div id = '"+ window.btoa(item.name) +"' align='right'>" + btn + "</div></td>";
pageContent = pageContent + "</tr></table><br><br>";
}
var counterDir = -1;
var counterDisp = 0;
var index = 0;
var lowItem = "";
var needNext = false;
var pageContent = "";
for (index = 0; index < metadata.applications.length; index++){
lowItem = metadata.applications[index].name.toLowerCase();
if (lowItem.indexOf(search.toLowerCase()) != -1 && metadata.applications[index].isActive == true){
counterDir = counterDir + 1;
if ((counterDir >= offset) && (counterDir < (offset + perpage))){
DisplayApp(metadata.applications[index]);
counterDisp = counterDisp + 1;
}
if (counterDir >= (offset + perpage)){
needNext = true;
break;
}
}
}
//pager
function pagetoPrevious(){ var btn = "<button class='install' onclick = 'install(" + '"' + absoluteJsFile + " ," + window.btoa(item.name) + '"' + ");'>Install</button>";
offset = offset - perpage; var btndata = {
if (offset < 0){ "url": absoluteJsFile,
offset = 0; "id": window.btoa(item.name)
} };
location.href = "more.html?offset=" + offset + "&perpage=" + perpage + "&search=" + encodeURI(search); buttonList.push(btndata);
}
pageContent = pageContent + "<td><font class='appname'>" + item.name + "<br></font><font class = 'appdesc'>" + item.description + "<br></font><div id = '"+ window.btoa(item.name) +"' align='right'>" + btn + "</div></td>";
function pagetoNext(){ pageContent = pageContent + "</tr></table><br><br>";
offset = offset + perpage; }
location.href = "more.html?offset=" + offset + "&perpage=" + perpage + "&search=" + encodeURI(search);
}
var pagerPrevious = "<a href='#' onclick='pagetoPrevious();'><img src='minus-16.png'></a>";
if (offset <= 0){
pagerPrevious = "<img src='blank_minus-16.png'>";
}
var pagerNext = "<a href='#' onclick='pagetoNext();'><img src='plus-16.png'></a>";
if (needNext == false){
pagerNext = "<img src='blank_plus-16.png'>";
}
var countA = offset + 1;
var countB = offset + counterDisp;
var pagerHtml = pagerPrevious + "<font class='pager'>&nbsp;&nbsp;" + countA + " - " + countB + "&nbsp;&nbsp;</font>" + pagerNext;
if (counterDisp > 0 ){ var counterDir = -1;
document.getElementById("pager_top").innerHTML = pagerHtml; var counterDisp = 0;
document.getElementById("data").innerHTML = pageContent; var index = 0;
document.getElementById("pager_footer").innerHTML = pagerHtml; var lowItem = "";
}else{ var needNext = false;
document.getElementById("data").innerHTML = "<hr><div align='center'><font class='noresult'><br><br><br><br>Sorry, no result found.<br><br><br><br><br><br></font></div><hr>"; var pageContent = "";
}
for (index = 0; index < metadata.applications.length; index++){
requestRunningScriptData(); lowItem = metadata.applications[index].name.toLowerCase();
</script> if (lowItem.indexOf(search.toLowerCase()) != -1 && metadata.applications[index].isActive == true){
</body> counterDir = counterDir + 1;
if ((counterDir >= offset) && (counterDir < (offset + perpage))){
DisplayApp(metadata.applications[index]);
counterDisp = counterDisp + 1;
}
if (counterDir >= (offset + perpage)){
needNext = true;
break;
}
}
}
//pager
function pagetoPrevious(){
offset = offset - perpage;
if (offset < 0){
offset = 0;
}
location.href = "more.html?offset=" + offset + "&perpage=" + perpage + "&search=" + encodeURI(search);
}
function pagetoNext(){
offset = offset + perpage;
location.href = "more.html?offset=" + offset + "&perpage=" + perpage + "&search=" + encodeURI(search);
}
var pagerPrevious = "<a href='#' onclick='pagetoPrevious();'><img src='minus-16.png'></a>";
if (offset <= 0){
pagerPrevious = "<img src='blank_minus-16.png'>";
}
var pagerNext = "<a href='#' onclick='pagetoNext();'><img src='plus-16.png'></a>";
if (needNext == false){
pagerNext = "<img src='blank_plus-16.png'>";
}
var countA = offset + 1;
var countB = offset + counterDisp;
var pagerHtml = pagerPrevious + "<font class='pager'>&nbsp;&nbsp;" + countA + " - " + countB + "&nbsp;&nbsp;</font>" + pagerNext;
if (counterDisp > 0 ){
document.getElementById("pager_top").innerHTML = pagerHtml;
document.getElementById("data").innerHTML = pageContent;
document.getElementById("pager_footer").innerHTML = pagerHtml;
}else{
document.getElementById("data").innerHTML = "<hr><div align='center'><font class='noresult'><br><br><br><br>Sorry, no result found.<br><br><br><br><br><br></font></div><hr>";
}
requestRunningScriptData();
</script>
</body>
</html> </html>