Close #10, improve loading experience on slow connections

This commit is contained in:
Skylar Ittner 2017-12-09 19:49:12 -07:00
parent 968498894d
commit fb4895b6aa
7 changed files with 297 additions and 225 deletions

View File

@ -10,7 +10,7 @@ html, body {
.app-dock { .app-dock {
margin: 0 auto 10px auto; margin: 0 auto 10px auto;
display: flex; display: flex;
justify-content: space-around; justify-content: space-evenly;
flex-wrap: wrap; flex-wrap: wrap;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
@ -79,3 +79,7 @@ span.navbar-brand {
#navbar { #navbar {
min-height: 56px; min-height: 56px;
} }
.loading-text {
font-size: 18px;
}

View File

@ -38,6 +38,8 @@
<circle class="path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle> <circle class="path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle>
</svg> </svg>
</div> </div>
<div style="width: 100%;"></div>
<p class="loading-text">Loading...</p>
</div> </div>
</div> </div>
</div> </div>

View File

@ -30,6 +30,7 @@ document.addEventListener("deviceready", function () {
* succeeds. * succeeds.
*/ */
function getuserinfo(callback) { function getuserinfo(callback) {
$(".loading-text").text("Loading account...");
$.post(localStorage.getItem("syncurl"), { $.post(localStorage.getItem("syncurl"), {
username: localStorage.getItem("username"), username: localStorage.getItem("username"),
key: localStorage.getItem("key"), key: localStorage.getItem("key"),
@ -37,6 +38,7 @@ function getuserinfo(callback) {
action: "user_info" action: "user_info"
}, function (data) { }, function (data) {
if (data.status === 'OK') { if (data.status === 'OK') {
$(".loading-text").text("Loading...");
userinfo = data.info; userinfo = data.info;
if (typeof callback == 'function') { if (typeof callback == 'function') {
callback(); callback();
@ -196,7 +198,12 @@ function restartApplication() {
// Handle back button to close things // Handle back button to close things
document.addEventListener("backbutton", function (event) { document.addEventListener("backbutton", function (event) {
if (localStorage.getItem("setupcomplete")) { if (localStorage.getItem("setupcomplete")) {
if (_returnscreen != null) { if ($("#appframe").length && historyctr > 0) {
console.log("going back");
var iframe = document.getElementById("appframe");
iframe.contentWindow.postMessage("goback", "*");
historyctr--;
} else if (_returnscreen != null) {
openscreen(_returnscreen, "FADE"); openscreen(_returnscreen, "FADE");
_returnscreen = null; _returnscreen = null;
} else { } else {

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,9 @@
<iframe id="appframe" src="views/appspinner.html" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0px;"></iframe> <iframe id="appframe" src="" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0px;"></iframe>
<iframe id="loadframe" src="views/appspinner.html" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0px; z-index: 999999;"></iframe>
<script src="js/material-palette.js"></script> <script src="js/material-palette.js"></script>
<script> <script>
var historyctr = -1;
/** /**
* Open an app with native Android UI elements * Open an app with native Android UI elements
* @param String id Application ID * @param String id Application ID
@ -27,10 +29,17 @@
action: "start_session" action: "start_session"
}, function (data) { }, function (data) {
if (data.status === 'OK') { if (data.status === 'OK') {
document.getElementById("loadframe").contentWindow.postMessage("loginok", "*");
if (typeof injectcode === 'undefined' || injectcode === true) { if (typeof injectcode === 'undefined' || injectcode === true) {
$('#appframe').on("load", function () { $('#appframe').on("load", function () {
$("#loadframe").fadeOut(300);
historyctr++;
$.get("css/sidemenu.css", function (style) { $.get("css/sidemenu.css", function (style) {
$('#appframe').contents().find('head').append("<style>" + style + "</style>"); $('#appframe').contents().find('head').append("<style>" + style + "</style>");
$.get("js/jquery-ui.min.js", function (script) {
$('#appframe').contents().find('body').append("<script>" + script + "<\/script>");
$.get("js/hammer.min.js", function (script) {
$('#appframe').contents().find('body').append("<script>" + script + "<\/script>");
$.get("js/sidemenu.js", function (script) { $.get("js/sidemenu.js", function (script) {
script = script.replace("%%JQUERYFXOFF%%", !(localStorage.getItem("animations") === null || localStorage.getItem("animations") === "true")); script = script.replace("%%JQUERYFXOFF%%", !(localStorage.getItem("animations") === null || localStorage.getItem("animations") === "true"));
script = script.replace("%%USERNAME%%", userinfo.realname); script = script.replace("%%USERNAME%%", userinfo.realname);
@ -39,6 +48,8 @@
}); });
}); });
}); });
});
});
} else { } else {
// Only inject minimal CSS // Only inject minimal CSS
$('#appframe').on("load", function () { $('#appframe').on("load", function () {
@ -59,10 +70,20 @@
} }
var scanningactive = false; var scanningactive = false;
var dedup = false;
window.addEventListener('message', function (event) { window.addEventListener('message', function (event) {
console.log("app event: " + event.data); console.log("app event: " + event.data);
setTimeout(function () {
dedup = false;
}, 500);
if (dedup) {
return;
}
dedup = true;
if (event.data == "quit") { if (event.data == "quit") {
openscreen("home"); openscreen("home");
} else if (event.data == "goneback") {
historyctr -= 1;
} else if (event.data.startsWith("setcolor ")) { } else if (event.data.startsWith("setcolor ")) {
var color = event.data.split(" ", 2)[1]; var color = event.data.split(" ", 2)[1];
if (cordova.platformId == 'android') { if (cordova.platformId == 'android') {

View File

@ -1,12 +1,12 @@
<!DOCTYPE html> <!DOCTYPE html>
<html>
<head>
<title>Loading</title> <title>Loading</title>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<style> <style>
html, body { html, body {
height: 100%; height: 100%;
background-color: white;
font-family: "Roboto","Helvetica Neue",Helvetica,Arial,sans-serif;
} }
body { body {
@ -84,13 +84,58 @@
} }
} }
#statustext {
text-align: center;
}
#giveup {
display: none;
margin-top: 5px;
border: none;
border-radius: 3px;
box-shadow: 1px 1px 4px rgba(0,0,0,0.4);
padding: 6px 16px;
font-size: 13px;
line-height: 1.846;
color: #fff;
background-color: #2196f3;
text-align: center;
vertical-align: middle;
touch-action: manipulation;
white-space: nowrap;
text-decoration: none;
box-sizing: border-box;
text-transform: uppercase;
position: relative;
}
</style> </style>
</head>
<body>
<svg class="spinner" width="65px" height="65px" viewBox="0 0 66 66" xmlns="http://www.w3.org/2000/svg"> <svg class="spinner" width="65px" height="65px" viewBox="0 0 66 66" xmlns="http://www.w3.org/2000/svg">
<circle class="path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle> <circle class="path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle>
</svg> </svg>
<p>Logging in...</p> <p id="statustext">Logging in...</p>
</body> <br />
</html> <div id="giveup" onclick="parent.postMessage('quit', '*');">Give up</div>
<script>
window.addEventListener('message', function (event) {
if (event.data == "loginok") {
document.getElementById("statustext").innerHTML = "Loading...";
setTimeout(function () {
document.getElementById("statustext").innerHTML = "Still loading...";
}, 5000);
setTimeout(function () {
document.getElementById("statustext").innerHTML = "Just a moment...";
document.getElementById("giveup").style.display = "inline-block";
}, 10000);
setTimeout(function () {
document.getElementById("statustext").innerHTML = "Well this is awkward.";
}, 20000);
setTimeout(function () {
document.getElementById("statustext").innerHTML = "[fidgets nervously]";
}, 25000);
setTimeout(function () {
document.getElementById("statustext").innerHTML = "Either something is broken or your connection is too slow.";
}, 30000);
}
});
</script>

View File

@ -5,17 +5,21 @@
<circle class="path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle> <circle class="path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle>
</svg> </svg>
</div> </div>
<div style="width: 100%;"></div>
<p class="loading-text">Loading...</p>
</div> </div>
</div> </div>
<script> <script>
function loadapps() { function loadapps() {
$(".loading-text").html("Loading Apps...");
$.post(localStorage.getItem("syncurl"), { $.post(localStorage.getItem("syncurl"), {
username: localStorage.getItem("username"), username: localStorage.getItem("username"),
key: localStorage.getItem("key"), key: localStorage.getItem("key"),
action: "listapps" action: "listapps"
}, function (data) { }, function (data) {
if (data.status === 'OK') { if (data.status === 'OK') {
$("#loading-text").text("One moment...");
$('#app-dock').html(""); $('#app-dock').html("");
Object.keys(data.apps).forEach(function (k) { Object.keys(data.apps).forEach(function (k) {
var app = data.apps[k]; var app = data.apps[k];