Code Formatting Fixes

Co-Authored-By: Keb Helion <60008426+KebHelion@users.noreply.github.com>
This commit is contained in:
Kasen IO 2020-03-15 22:16:11 -04:00
parent 756d036dd5
commit d19ef23190
2 changed files with 125 additions and 123 deletions

View file

@ -13,12 +13,12 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
(function() {
var ROOT = Script.resolvePath('').split("app-more.js")[0];
var APP_NAME = "MORE...";
var APP_URL = ROOT + "more.html";
var APP_ICON_INACTIVE = ROOT + "appicon_i.png";
var APP_ICON_ACTIVE = ROOT + "appicon_a.png";
var Appstatus = false;
const ROOT = Script.resolvePath('').split("app-more.js")[0];
const APP_NAME = "MORE...";
const APP_URL = ROOT + "more.html";
const APP_ICON_INACTIVE = ROOT + "appicon_i.png";
const APP_ICON_ACTIVE = ROOT + "appicon_a.png";
var appStatus = false;
var lastProcessing = {
"action": "",
"script": ""
@ -30,24 +30,21 @@
text: APP_NAME,
icon: APP_ICON_INACTIVE,
activeIcon: APP_ICON_ACTIVE
});
});
function clicked() {
if (Appstatus) {
if (appStatus) {
tablet.webEventReceived.disconnect(onMoreAppWebEventReceived);
tablet.gotoHomeScreen();
Appstatus = false;
appStatus = false;
} else {
tablet.gotoWebScreen(APP_URL);
tablet.webEventReceived.connect(onMoreAppWebEventReceived);
Appstatus = true;
tablet.gotoWebScreen(APP_URL);
tablet.webEventReceived.connect(onMoreAppWebEventReceived);
appStatus = true;
}
button.editProperties({
isActive: Appstatus
isActive: appStatus
});
}
button.clicked.connect(clicked);
@ -59,87 +56,63 @@
for (var j = 0; j < currentlyRunningScripts.length; j++) {
runningScriptJson = currentlyRunningScripts[j].url;
if (runningScriptJson.indexOf("https://kasenvr.github.io/community-apps/applications") !== -1) {
newMessage = newMessage + "_" + runningScriptJson;
newMessage += "_" + runningScriptJson;
}
}
tablet.emitScriptEvent(newMessage);
}
function onMoreAppWebEventReceived(eventz) {
if (typeof eventz === "string") {
var eventzget = JSON.parse(eventz);
//print("EVENT ACTION: " + eventzget.action);
//print("EVENT SCRIPT: " + eventzget.script);
if (eventzget.action === "installScript") {
if (lastProcessing.action === eventzget.action && lastProcessing.script === eventzget.script) {
return;
} else {
ScriptDiscoveryService.loadOneScript(eventzget.script);
lastProcessing.action = eventzget.action;
lastProcessing.script = eventzget.script;
function onMoreAppWebEventReceived(message) {
if (typeof message === "string") {
var instruction = JSON.parse(message);
if (instruction.action === "installScript") {
if (lastProcessing.action !== instruction.action || lastProcessing.script !== instruction.script) {
ScriptDiscoveryService.loadOneScript(instruction.script);
lastProcessing.action = instruction.action;
lastProcessing.script = instruction.script;
Script.setTimeout(function() {
sendRunningScriptList();
}, 1500);
}
}
if (eventzget.action === "uninstallScript") {
if (lastProcessing.action === eventzget.action && lastProcessing.script === eventzget.script) {
return;
} else {
ScriptDiscoveryService.stopScript(eventzget.script, false);
lastProcessing.action = eventzget.action;
lastProcessing.script = eventzget.script;
if (instruction.action === "uninstallScript") {
if (lastProcessing.action !== instruction.action || lastProcessing.script !== instruction.script) {
ScriptDiscoveryService.stopScript(instruction.script, false);
lastProcessing.action = instruction.action;
lastProcessing.script = instruction.script;
Script.setTimeout(function() {
sendRunningScriptList();
}, 1500);
}
}
}
}
if (eventzget.action === "requestRunningScriptData") {
if (instruction.action === "requestRunningScriptData") {
sendRunningScriptList();
}
}
}
}
function onScreenChanged(type, url) {
if (type === "Web" && url.indexOf(APP_URL) !== -1) {
//Active
//print("MORE... ACTIVE");
Appstatus = true;
appStatus = true;
} else {
//Inactive
//print("MORE... INACTIVE");
Appstatus = false;
}
appStatus = false;
}
button.editProperties({
isActive: Appstatus
isActive: appStatus
});
}
function cleanup() {
if (Appstatus) {
if (appStatus) {
tablet.gotoHomeScreen();
tablet.webEventReceived.disconnect(onMoreAppWebEventReceived);
}
tablet.screenChanged.disconnect(onScreenChanged);
tablet.removeButton(button);
}
Script.scriptEnding.connect(cleanup);
}());
}());

View file

@ -1,3 +1,4 @@
<!DOCTYPE html>
<!--
// more.html
//
@ -11,26 +12,25 @@
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script id="metadataScriptTag" type="text/javascript" src="https://kasenvr.github.io/community-apps/applications/metadata.js"></script>
<script>
//Defaults
DEFAULT_PER_PAGE = 3;
DEFAULT_OFFSET = 0;
var DEFAULT_PER_PAGE = 3;
var DEFAULT_OFFSET = 0;
//Paths
var currentPath = window.location.protocol + "//" + window.location.host + window.location.pathname;
var rootPath;
var metadataScript = document.getElementById("metadataScriptTag");
if (currentPath.includes("kasenvr.github.io") || !currentPath.includes("file:/")) { // Loading app from repo or filesystem.
rootPath = currentPath.replace("more/more.html", "applications/");
if (metadataScript.src !== "../applications/metadata.js") {
metadataScript.src = "../applications/metadata.js";
console.info("Loading apps and metadata locally.");
console.info("Loading apps and metadata locally.");
}
} else {
rootPath = "https://kasenvr.github.io/community-apps/applications/";
@ -41,7 +41,7 @@
}
document.getElementsByTagName("head")[0].appendChild(metadataScript);
//Parameters
function findGetParameter(parameterName) {
var result = null,
@ -69,7 +69,7 @@
var search = findGetParameter("search");
if (search === null) {
search = "";
}
}
//Search
function doSearch(keyword) {
@ -102,18 +102,16 @@
//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){
//then change btn appearence
var btn = "<button class='processing' >Processing...</button>";
document.getElementById(btnId).innerHTML = btn;
//Action
var readyEvent = {
"action": "installScript",
"script": script
@ -124,11 +122,9 @@
}
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
@ -137,11 +133,11 @@
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="css/styles.css" rel="stylesheet">
</head>
<body><form name = "searchbar">
<h1 class="mainTitle">Add more functionalities...</h1>
@ -164,64 +160,106 @@
</td>
<td style = "vertical-align:middle; text-align:right;">
<div id = 'pager_top' style = "vertical-align: middle;"></div>
</td>
</td>
</tr>
</table>
</form><br>
</form>
<div id = "data"></div>
<div style="width:98%; text-align:right;">
<div style = "vertical-align: middle;" id = 'pager_footer'><!-- More info placeholder --></div>
</div>
<hr>
<p class="mainDesc">Want to contribute and add your own app?<br>
Read the <a href="https://kasenvr.github.io/community-apps/web/index.html">guide</a>!</p>
<script>
function monitorEnter(e) {
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 13) {
doSearch(document.searchbar.searchtextbox.value);
}
}
function submitForm(event){
event.preventDefault();
}
document.searchbar.searchtextbox.value = search;
var pageContent = "";
function DisplayApp(item) {
pageContent = pageContent + "<a name = '" + window.btoa(item.directory) + "'><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>";
var btn = "";
var absoluteJsFile = rootPath + item.jsfile;
var btn = "<button class='install' onclick = 'install(" + '"' + absoluteJsFile + " ," + window.btoa(item.directory) + '"' + ");'>Install</button>";
var btndata = {
"url": absoluteJsFile,
"id": window.btoa(item.directory)
};
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.directory) +"' align='right'>" + btn + "</div></td>";
pageContent = pageContent + "</tr></table><br><br>";
pageContent = pageContent + "</tr></table><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;
function listBuilder(searchKeyword, listOffset, listPerPage) {
buttonList = [];
var counterDir = -1;
var counterDisp = 0;
var index = 0;
var lowItem = "";
var needNext = false;
pageContent = "";
for (index = 0; index < metadata.applications.length; index++) {
lowItem = metadata.applications[index].name.toLowerCase();
if (lowItem.indexOf(searchKeyword.toLowerCase()) !== -1 && metadata.applications[index].isActive == true) {
counterDir = counterDir + 1;
if ((counterDir >= listOffset) && (counterDir < (listOffset + listPerPage))) {
DisplayApp(metadata.applications[index]);
counterDisp = counterDisp + 1;
}
if (counterDir >= (listOffset + listPerPage)) {
needNext = true;
break;
}
}
}
var pagerPrevious = "<a href='#' onclick='pagetoPrevious();'><img src='minus-16.png'></a>";
if (listOffset <= 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 = listOffset + 1;
var countB = listOffset + 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();
}
//pager
function pagetoPrevious(){
offset = offset - perpage;
if (offset < 0) {
offset = 0;
}
location.href = "more.html?offset=" + offset + "&perpage=" + perpage + "&search=" + encodeURI(search);
listBuilder(search, offset, perpage);
}
function pagetoNext(){
@ -233,17 +271,8 @@
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;
listBuilder(search, offset, perpage);
if (counterDisp > 0 ) {
document.getElementById("pager_top").innerHTML = pagerHtml;
@ -256,4 +285,4 @@
requestRunningScriptData();
</script>
</body>
</html>
</html>