Close #10, improve loading experience on slow connections
This commit is contained in:
parent
968498894d
commit
fb4895b6aa
@ -10,7 +10,7 @@ html, body {
|
||||
.app-dock {
|
||||
margin: 0 auto 10px auto;
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
justify-content: space-evenly;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
@ -78,4 +78,8 @@ span.navbar-brand {
|
||||
|
||||
#navbar {
|
||||
min-height: 56px;
|
||||
}
|
||||
|
||||
.loading-text {
|
||||
font-size: 18px;
|
||||
}
|
@ -38,6 +38,8 @@
|
||||
<circle class="path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle>
|
||||
</svg>
|
||||
</div>
|
||||
<div style="width: 100%;"></div>
|
||||
<p class="loading-text">Loading...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -30,6 +30,7 @@ document.addEventListener("deviceready", function () {
|
||||
* succeeds.
|
||||
*/
|
||||
function getuserinfo(callback) {
|
||||
$(".loading-text").text("Loading account...");
|
||||
$.post(localStorage.getItem("syncurl"), {
|
||||
username: localStorage.getItem("username"),
|
||||
key: localStorage.getItem("key"),
|
||||
@ -37,6 +38,7 @@ function getuserinfo(callback) {
|
||||
action: "user_info"
|
||||
}, function (data) {
|
||||
if (data.status === 'OK') {
|
||||
$(".loading-text").text("Loading...");
|
||||
userinfo = data.info;
|
||||
if (typeof callback == 'function') {
|
||||
callback();
|
||||
@ -196,7 +198,12 @@ function restartApplication() {
|
||||
// Handle back button to close things
|
||||
document.addEventListener("backbutton", function (event) {
|
||||
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");
|
||||
_returnscreen = null;
|
||||
} else {
|
||||
|
File diff suppressed because one or more lines are too long
@ -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>
|
||||
var historyctr = -1;
|
||||
/**
|
||||
* Open an app with native Android UI elements
|
||||
* @param String id Application ID
|
||||
@ -14,102 +16,121 @@
|
||||
* @returns {undefined}
|
||||
*/
|
||||
function launchapp(id, api, url, icon, title, injectcode, shownavbar) {
|
||||
if (typeof shownavbar === 'undefined' || shownavbar === false) {
|
||||
setnavbar(false);
|
||||
} else {
|
||||
setnavbar("app", title);
|
||||
$('#appframe').css('top', '75px');
|
||||
}
|
||||
$.post(url + api, {
|
||||
username: localStorage.getItem("username"),
|
||||
key: localStorage.getItem("key"),
|
||||
password: localStorage.getItem("password"),
|
||||
action: "start_session"
|
||||
}, function (data) {
|
||||
if (data.status === 'OK') {
|
||||
if (typeof injectcode === 'undefined' || injectcode === true) {
|
||||
$('#appframe').on("load", function () {
|
||||
$.get("css/sidemenu.css", function (style) {
|
||||
$('#appframe').contents().find('head').append("<style>" + style + "</style>");
|
||||
$.get("js/sidemenu.js", function (script) {
|
||||
script = script.replace("%%JQUERYFXOFF%%", !(localStorage.getItem("animations") === null || localStorage.getItem("animations") === "true"));
|
||||
script = script.replace("%%USERNAME%%", userinfo.realname);
|
||||
script = script.replace("%%LOGO%%", icon);
|
||||
$('#appframe').contents().find('body').append("<script>" + script + "<\/script>");
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Only inject minimal CSS
|
||||
$('#appframe').on("load", function () {
|
||||
$.get("css/inject_mini.css", function (style) {
|
||||
$('#appframe').contents().find('head').append("<style>" + style + "</style>");
|
||||
});
|
||||
});
|
||||
}
|
||||
$('#appframe').attr('src', url);
|
||||
} else {
|
||||
navigator.notification.alert(data.msg, null, "Error", 'Dismiss');
|
||||
openscreen("home");
|
||||
}
|
||||
}, "json").fail(function () {
|
||||
navigator.notification.alert("Could not connect to the server. Try again later.", null, "Error", 'Dismiss');
|
||||
openscreen("home");
|
||||
});
|
||||
if (typeof shownavbar === 'undefined' || shownavbar === false) {
|
||||
setnavbar(false);
|
||||
} else {
|
||||
setnavbar("app", title);
|
||||
$('#appframe').css('top', '75px');
|
||||
}
|
||||
$.post(url + api, {
|
||||
username: localStorage.getItem("username"),
|
||||
key: localStorage.getItem("key"),
|
||||
password: localStorage.getItem("password"),
|
||||
action: "start_session"
|
||||
}, function (data) {
|
||||
if (data.status === 'OK') {
|
||||
document.getElementById("loadframe").contentWindow.postMessage("loginok", "*");
|
||||
if (typeof injectcode === 'undefined' || injectcode === true) {
|
||||
$('#appframe').on("load", function () {
|
||||
$("#loadframe").fadeOut(300);
|
||||
historyctr++;
|
||||
$.get("css/sidemenu.css", function (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) {
|
||||
script = script.replace("%%JQUERYFXOFF%%", !(localStorage.getItem("animations") === null || localStorage.getItem("animations") === "true"));
|
||||
script = script.replace("%%USERNAME%%", userinfo.realname);
|
||||
script = script.replace("%%LOGO%%", icon);
|
||||
$('#appframe').contents().find('body').append("<script>" + script + "<\/script>");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Only inject minimal CSS
|
||||
$('#appframe').on("load", function () {
|
||||
$.get("css/inject_mini.css", function (style) {
|
||||
$('#appframe').contents().find('head').append("<style>" + style + "</style>");
|
||||
});
|
||||
});
|
||||
}
|
||||
$('#appframe').attr('src', url);
|
||||
} else {
|
||||
navigator.notification.alert(data.msg, null, "Error", 'Dismiss');
|
||||
openscreen("home");
|
||||
}
|
||||
}, "json").fail(function () {
|
||||
navigator.notification.alert("Could not connect to the server. Try again later.", null, "Error", 'Dismiss');
|
||||
openscreen("home");
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
var scanningactive = false;
|
||||
var dedup = false;
|
||||
window.addEventListener('message', function (event) {
|
||||
console.log("app event: " + event.data);
|
||||
if (event.data == "quit") {
|
||||
openscreen("home");
|
||||
} else if (event.data.startsWith("setcolor ")) {
|
||||
var color = event.data.split(" ", 2)[1];
|
||||
if (cordova.platformId == 'android') {
|
||||
window.plugins.headerColor.tint(color);
|
||||
for (var swatch in _PALETTE) {
|
||||
if (color == _PALETTE[swatch]["shade_500"]) {
|
||||
StatusBar.backgroundColorByHexString(_PALETTE[swatch]["shade_700"]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
StatusBar.backgroundColorByHexString(color);
|
||||
}
|
||||
} else if (event.data.startsWith("scancode ")) {
|
||||
var callbackcode = event.data.split(" ").slice(1).join(" ");
|
||||
console.log("got scancode " + callbackcode);
|
||||
try {
|
||||
if (scanningactive) {
|
||||
console.log("Scanner already active, ignoring request.");
|
||||
return;
|
||||
}
|
||||
scanningactive = true;
|
||||
cordova.plugins.barcodeScanner.scan(
|
||||
function (result) {
|
||||
scanningactive = false;
|
||||
if (!result.cancelled) {
|
||||
var iframe = document.getElementById("appframe");
|
||||
iframe.contentWindow.postMessage("coderesult~|~" + callbackcode + "~|~" + result.text, "*");
|
||||
}
|
||||
},
|
||||
function (error) {
|
||||
scanningactive = false;
|
||||
navigator.notification.alert("Scanning failed: " + error, null, "Error", 'Dismiss');
|
||||
},
|
||||
{
|
||||
"showFlipCameraButton": true,
|
||||
"prompt": "Scan Code"
|
||||
}
|
||||
);
|
||||
} catch (ex) {
|
||||
scanningactive = false;
|
||||
navigator.notification.alert(ex.message, null, "Error", 'Dismiss');
|
||||
}
|
||||
console.log("app event: " + event.data);
|
||||
setTimeout(function () {
|
||||
dedup = false;
|
||||
}, 500);
|
||||
if (dedup) {
|
||||
return;
|
||||
}
|
||||
dedup = true;
|
||||
if (event.data == "quit") {
|
||||
openscreen("home");
|
||||
} else if (event.data == "goneback") {
|
||||
historyctr -= 1;
|
||||
} else if (event.data.startsWith("setcolor ")) {
|
||||
var color = event.data.split(" ", 2)[1];
|
||||
if (cordova.platformId == 'android') {
|
||||
window.plugins.headerColor.tint(color);
|
||||
for (var swatch in _PALETTE) {
|
||||
if (color == _PALETTE[swatch]["shade_500"]) {
|
||||
StatusBar.backgroundColorByHexString(_PALETTE[swatch]["shade_700"]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
StatusBar.backgroundColorByHexString(color);
|
||||
}
|
||||
} else if (event.data.startsWith("scancode ")) {
|
||||
var callbackcode = event.data.split(" ").slice(1).join(" ");
|
||||
console.log("got scancode " + callbackcode);
|
||||
try {
|
||||
if (scanningactive) {
|
||||
console.log("Scanner already active, ignoring request.");
|
||||
return;
|
||||
}
|
||||
scanningactive = true;
|
||||
cordova.plugins.barcodeScanner.scan(
|
||||
function (result) {
|
||||
scanningactive = false;
|
||||
if (!result.cancelled) {
|
||||
var iframe = document.getElementById("appframe");
|
||||
iframe.contentWindow.postMessage("coderesult~|~" + callbackcode + "~|~" + result.text, "*");
|
||||
}
|
||||
},
|
||||
function (error) {
|
||||
scanningactive = false;
|
||||
navigator.notification.alert("Scanning failed: " + error, null, "Error", 'Dismiss');
|
||||
},
|
||||
{
|
||||
"showFlipCameraButton": true,
|
||||
"prompt": "Scan Code"
|
||||
}
|
||||
);
|
||||
} catch (ex) {
|
||||
scanningactive = false;
|
||||
navigator.notification.alert(ex.message, null, "Error", 'Dismiss');
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
|
||||
if (userinfo == null) {
|
||||
getuserinfo();
|
||||
getuserinfo();
|
||||
}
|
||||
</script>
|
@ -1,96 +1,141 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Loading</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<style>
|
||||
html, body {
|
||||
height: 100%;
|
||||
}
|
||||
<title>Loading</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<style>
|
||||
html, body {
|
||||
height: 100%;
|
||||
background-color: white;
|
||||
font-family: "Roboto","Helvetica Neue",Helvetica,Arial,sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
body {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.spinner {
|
||||
-webkit-animation: rotator 1.4s linear infinite;
|
||||
animation: rotator 1.4s linear infinite;
|
||||
}
|
||||
.spinner {
|
||||
-webkit-animation: rotator 1.4s linear infinite;
|
||||
animation: rotator 1.4s linear infinite;
|
||||
}
|
||||
|
||||
@-webkit-keyframes rotator {
|
||||
0% {
|
||||
-webkit-transform: rotate(0deg);
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
-webkit-transform: rotate(270deg);
|
||||
transform: rotate(270deg);
|
||||
}
|
||||
}
|
||||
@-webkit-keyframes rotator {
|
||||
0% {
|
||||
-webkit-transform: rotate(0deg);
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
-webkit-transform: rotate(270deg);
|
||||
transform: rotate(270deg);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes rotator {
|
||||
0% {
|
||||
-webkit-transform: rotate(0deg);
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
-webkit-transform: rotate(270deg);
|
||||
transform: rotate(270deg);
|
||||
}
|
||||
}
|
||||
.spinner .path {
|
||||
stroke-dasharray: 187;
|
||||
stroke-dashoffset: 0;
|
||||
-webkit-transform-origin: center;
|
||||
transform-origin: center;
|
||||
-webkit-animation: dash 1.4s ease-in-out infinite, 5.6s ease-in-out infinite;
|
||||
animation: dash 1.4s ease-in-out infinite, 5.6s ease-in-out infinite;
|
||||
stroke: #448aff;
|
||||
}
|
||||
@keyframes rotator {
|
||||
0% {
|
||||
-webkit-transform: rotate(0deg);
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
-webkit-transform: rotate(270deg);
|
||||
transform: rotate(270deg);
|
||||
}
|
||||
}
|
||||
.spinner .path {
|
||||
stroke-dasharray: 187;
|
||||
stroke-dashoffset: 0;
|
||||
-webkit-transform-origin: center;
|
||||
transform-origin: center;
|
||||
-webkit-animation: dash 1.4s ease-in-out infinite, 5.6s ease-in-out infinite;
|
||||
animation: dash 1.4s ease-in-out infinite, 5.6s ease-in-out infinite;
|
||||
stroke: #448aff;
|
||||
}
|
||||
|
||||
@-webkit-keyframes dash {
|
||||
0% {
|
||||
stroke-dashoffset: 187;
|
||||
}
|
||||
50% {
|
||||
stroke-dashoffset: 46.75;
|
||||
-webkit-transform: rotate(135deg);
|
||||
transform: rotate(135deg);
|
||||
}
|
||||
100% {
|
||||
stroke-dashoffset: 187;
|
||||
-webkit-transform: rotate(450deg);
|
||||
transform: rotate(450deg);
|
||||
}
|
||||
}
|
||||
@-webkit-keyframes dash {
|
||||
0% {
|
||||
stroke-dashoffset: 187;
|
||||
}
|
||||
50% {
|
||||
stroke-dashoffset: 46.75;
|
||||
-webkit-transform: rotate(135deg);
|
||||
transform: rotate(135deg);
|
||||
}
|
||||
100% {
|
||||
stroke-dashoffset: 187;
|
||||
-webkit-transform: rotate(450deg);
|
||||
transform: rotate(450deg);
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes dash {
|
||||
0% {
|
||||
stroke-dashoffset: 187;
|
||||
}
|
||||
50% {
|
||||
stroke-dashoffset: 46.75;
|
||||
-webkit-transform: rotate(135deg);
|
||||
transform: rotate(135deg);
|
||||
}
|
||||
100% {
|
||||
stroke-dashoffset: 187;
|
||||
-webkit-transform: rotate(450deg);
|
||||
transform: rotate(450deg);
|
||||
}
|
||||
}
|
||||
@keyframes dash {
|
||||
0% {
|
||||
stroke-dashoffset: 187;
|
||||
}
|
||||
50% {
|
||||
stroke-dashoffset: 46.75;
|
||||
-webkit-transform: rotate(135deg);
|
||||
transform: rotate(135deg);
|
||||
}
|
||||
100% {
|
||||
stroke-dashoffset: 187;
|
||||
-webkit-transform: rotate(450deg);
|
||||
transform: rotate(450deg);
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<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>
|
||||
</svg>
|
||||
|
||||
<p>Logging in...</p>
|
||||
</body>
|
||||
</html>
|
||||
#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>
|
||||
<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>
|
||||
</svg>
|
||||
|
||||
<p id="statustext">Logging in...</p>
|
||||
<br />
|
||||
<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>
|
@ -5,40 +5,44 @@
|
||||
<circle class="path" fill="none" stroke-width="6" stroke-linecap="round" cx="33" cy="33" r="30"></circle>
|
||||
</svg>
|
||||
</div>
|
||||
<div style="width: 100%;"></div>
|
||||
<p class="loading-text">Loading...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function loadapps() {
|
||||
$.post(localStorage.getItem("syncurl"), {
|
||||
username: localStorage.getItem("username"),
|
||||
key: localStorage.getItem("key"),
|
||||
action: "listapps"
|
||||
}, function (data) {
|
||||
if (data.status === 'OK') {
|
||||
$('#app-dock').html("");
|
||||
Object.keys(data.apps).forEach(function (k) {
|
||||
var app = data.apps[k];
|
||||
var iconurl = app.icon;
|
||||
if (!app.icon.startsWith("http")) {
|
||||
iconurl = app.url + app.icon;
|
||||
}
|
||||
$("<div class=\"app-dock-item\" onclick=\"openapp('" + k + "', '" + app.mobileapi + "', '" + app.url + "', '" + iconurl + "', '" + app.title + "')\"><p><img src=\"" + iconurl + "\" class=\"img-responsive app-icon\" /><span>" + app.title + "</span></p></div>").hide().appendTo("#app-dock").fadeIn(200);
|
||||
});
|
||||
} else {
|
||||
navigator.notification.alert(data.msg, null, "Error", 'Dismiss');
|
||||
openscreen("homeloaderror");
|
||||
}
|
||||
}, "json").fail(function () {
|
||||
navigator.notification.alert("Could not connect to the server. Try again later.", null, "Error", 'Dismiss');
|
||||
openscreen("homeloaderror");
|
||||
});
|
||||
$(".loading-text").html("Loading Apps...");
|
||||
$.post(localStorage.getItem("syncurl"), {
|
||||
username: localStorage.getItem("username"),
|
||||
key: localStorage.getItem("key"),
|
||||
action: "listapps"
|
||||
}, function (data) {
|
||||
if (data.status === 'OK') {
|
||||
$("#loading-text").text("One moment...");
|
||||
$('#app-dock').html("");
|
||||
Object.keys(data.apps).forEach(function (k) {
|
||||
var app = data.apps[k];
|
||||
var iconurl = app.icon;
|
||||
if (!app.icon.startsWith("http")) {
|
||||
iconurl = app.url + app.icon;
|
||||
}
|
||||
$("<div class=\"app-dock-item\" onclick=\"openapp('" + k + "', '" + app.mobileapi + "', '" + app.url + "', '" + iconurl + "', '" + app.title + "')\"><p><img src=\"" + iconurl + "\" class=\"img-responsive app-icon\" /><span>" + app.title + "</span></p></div>").hide().appendTo("#app-dock").fadeIn(200);
|
||||
});
|
||||
} else {
|
||||
navigator.notification.alert(data.msg, null, "Error", 'Dismiss');
|
||||
openscreen("homeloaderror");
|
||||
}
|
||||
}, "json").fail(function () {
|
||||
navigator.notification.alert("Could not connect to the server. Try again later.", null, "Error", 'Dismiss');
|
||||
openscreen("homeloaderror");
|
||||
});
|
||||
}
|
||||
|
||||
if (localStorage.getItem('setupcomplete')) {
|
||||
setnavbar("home");
|
||||
loadapps();
|
||||
setnavbar("home");
|
||||
loadapps();
|
||||
} else {
|
||||
openscreen("setup1");
|
||||
openscreen("setup1");
|
||||
}
|
||||
</script>
|
Loading…
x
Reference in New Issue
Block a user