Lint + fix default apps per page + fix script list loading bug.

This commit is contained in:
Kasen IO 2020-03-11 14:59:35 -04:00
parent 8092220ea4
commit 4eea4980fd
2 changed files with 57 additions and 54 deletions

View file

@ -6,16 +6,12 @@
// Created by Keb Helion, February 2020. // Created by Keb Helion, February 2020.
// Copyright 2020 Project Athena and contributors. // Copyright 2020 Project Athena and contributors.
// //
// App maintained in: https://github.com/kasenvr/community-apps
// App copied to: https://github.com/kasenvr/project-athena
//
// This script adds a "More Apps" selector to "Project Athena" to allow the user to add optional functionalities to the tablet. // This script adds a "More Apps" selector to "Project Athena" to allow the user to add optional functionalities to the tablet.
// This application has been designed to work directly from the Github repository. // This application has been designed to work directly from the Github repository.
// //
// 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...";
@ -38,7 +34,7 @@
function clicked() { function clicked() {
if (Appstatus) { if (Appstatus == true) {
tablet.webEventReceived.disconnect(onMoreAppWebEventReceived); tablet.webEventReceived.disconnect(onMoreAppWebEventReceived);
tablet.gotoHomeScreen(); tablet.gotoHomeScreen();
Appstatus = false; Appstatus = false;
@ -64,14 +60,14 @@
function onMoreAppWebEventReceived(eventz) { function onMoreAppWebEventReceived(eventz) {
if (typeof eventz === "string") { if (typeof eventz === "string") {
eventzget = JSON.parse(eventz); var 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);
@ -87,7 +83,7 @@
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);
@ -111,7 +107,7 @@
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;

View file

@ -7,6 +7,7 @@
// App maintained in: https://github.com/kasenvr/community-apps // App maintained in: https://github.com/kasenvr/community-apps
// App copied to: https://github.com/kasenvr/project-athena // App copied to: https://github.com/kasenvr/project-athena
// //
//
// 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
--> -->
@ -14,20 +15,29 @@
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<script id="metadataScriptTag" type="text/javascript" src="https://kasenvr.github.io/community-apps/applications/metadata.js"></script>
<script> <script>
//Defaults
DEFAULT_PER_PAGE = 3;
DEFAULT_OFFSET = 0;
//Paths //Paths
var currentPath = window.location.protocol + "//" + window.location.host + window.location.pathname; var currentPath = window.location.protocol + "//" + window.location.host + window.location.pathname;
var rootPath; var rootPath;
var metadataScript = document.createElement("script"); var metadataScript = document.getElementById("metadataScriptTag");
if (currentPath.includes("kasenvr.github.io") || !currentPath.includes("file:/")) { // Loading app from repo or filesystem. if (currentPath.includes("kasenvr.github.io") || !currentPath.includes("file:/")) { // Loading app from repo or filesystem.
rootPath = currentPath.replace("more/more.html", "applications/"); rootPath = currentPath.replace("more/more.html", "applications/");
metadataScript.src = "../applications/metadata.js"; if (metadataScript.src != "../applications/metadata.js") {
console.info("Loading apps and metadata locally."); metadataScript.src = "../applications/metadata.js";
console.info("Loading apps and metadata locally.");
}
} else { } else {
rootPath = "https://kasenvr.github.io/community-apps/applications/"; rootPath = "https://kasenvr.github.io/community-apps/applications/";
metadataScript.src = "https://kasenvr.github.io/community-apps/applications/metadata.js"; if (metadataScript.src != "https://kasenvr.github.io/community-apps/applications/metadata.js") {
console.info("Loading apps and metadata remotely."); metadataScript.src = "https://kasenvr.github.io/community-apps/applications/metadata.js";
console.info("Loading apps and metadata remotely.");
}
} }
document.getElementsByTagName("head")[0].appendChild(metadataScript); document.getElementsByTagName("head")[0].appendChild(metadataScript);
@ -39,22 +49,20 @@
var items = location.search.substr(1).split("&"); var items = location.search.substr(1).split("&");
for (var index = 0; index < items.length; index++) { for (var index = 0; index < items.length; index++) {
tmp = items[index].split("="); tmp = items[index].split("=");
if (tmp[0] === parameterName) { if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]);
result = decodeURIComponent(tmp[1])
};
} }
return result; return result;
} }
var offset = findGetParameter("offset"); var offset = findGetParameter("offset");
if (offset === null) { if (offset === null) {
offset = 0; offset = DEFAULT_OFFSET;
} }
offset = parseInt(offset); offset = parseInt(offset);
var perpage = findGetParameter("perpage"); var perpage = findGetParameter("perpage");
if (perpage === null) { if (perpage === null) {
perpage = 25; perpage = DEFAULT_PER_PAGE;
} }
perpage = parseInt(perpage); perpage = parseInt(perpage);
@ -64,11 +72,11 @@
} }
//Search //Search
function doSearch(keyword){ function doSearch(keyword) {
location.href = "more.html?offset=0&search=" + encodeURI(keyword); location.href = "more.html?offset=0&search=" + encodeURI(keyword);
} }
function clearSearch(){ function clearSearch() {
location.href = "more.html?offset=0"; location.href = "more.html?offset=0";
} }
@ -86,7 +94,7 @@
//update the buttons //update the buttons
buttonList.forEach(function(item){ buttonList.forEach(function(item){
var btn = ""; var btn = "";
if (message.indexOf(item.url) !== -1) { if (message.indexOf(item.url) != -1) {
//Means already running //Means already running
btn = "<button class='uninstall' onclick='uninstall(" + '"' + item.url + '"' + ", " + '"' + item.id + '"' + ");'>Uninstall</button>"; btn = "<button class='uninstall' onclick='uninstall(" + '"' + item.url + '"' + ", " + '"' + item.id + '"' + ");'>Uninstall</button>";
} else { } else {
@ -133,31 +141,30 @@
<link href="css/styles.css" rel="stylesheet"> <link href="css/styles.css" rel="stylesheet">
</head> </head>
<body> <body><form name = "searchbar">
<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="https://kasenvr.github.io/community-apps/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>
@ -189,9 +196,9 @@
var needNext = false; var needNext = false;
var pageContent = ""; var pageContent = "";
for (index = 0; index < metadata.applications.length; index++){ for (index = 0; index < metadata.applications.length; index++) {
lowItem = metadata.applications[index].name.toLowerCase(); lowItem = metadata.applications[index].name.toLowerCase();
if (lowItem.indexOf(search.toLowerCase()) !== -1 && metadata.applications[index].isActive) { if (lowItem.indexOf(search.toLowerCase()) != -1 && metadata.applications[index].isActive == true) {
counterDir = counterDir + 1; counterDir = counterDir + 1;
if ((counterDir >= offset) && (counterDir < (offset + perpage))) { if ((counterDir >= offset) && (counterDir < (offset + perpage))) {
DisplayApp(metadata.applications[index]); DisplayApp(metadata.applications[index]);
@ -206,15 +213,15 @@
//pager //pager
function pagetoPrevious() { function pagetoPrevious(){
offset = offset - perpage; offset = offset - perpage;
if (offset < 0){ if (offset < 0) {
offset = 0; offset = 0;
} }
location.href = "more.html?offset=" + offset + "&perpage=" + perpage + "&search=" + encodeURI(search); location.href = "more.html?offset=" + offset + "&perpage=" + perpage + "&search=" + encodeURI(search);
} }
function pagetoNext() { function pagetoNext(){
offset = offset + perpage; offset = offset + perpage;
location.href = "more.html?offset=" + offset + "&perpage=" + perpage + "&search=" + encodeURI(search); location.href = "more.html?offset=" + offset + "&perpage=" + perpage + "&search=" + encodeURI(search);
} }
@ -225,7 +232,7 @@
} }
var pagerNext = "<a href='#' onclick='pagetoNext();'><img src='plus-16.png'></a>"; var pagerNext = "<a href='#' onclick='pagetoNext();'><img src='plus-16.png'></a>";
if (!needNext) { if (needNext == false) {
pagerNext = "<img src='blank_plus-16.png'>"; pagerNext = "<img src='blank_plus-16.png'>";
} }