-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.html
84 lines (74 loc) · 3.18 KB
/
app.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Advantage Scout</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell,
"Helvetica Neue", sans-serif;
-webkit-touch-callout: none;
-webkit-text-size-adjust: none;
-webkit-user-select: none;
user-select: none;
}
</style>
<style id="appStyles"></style>
<script type="module">
window.isWeb = ISWEB; // Replaced by web server or during app build
// Instantiates the app and updates the HTML/CSS
function start(data) {
window.gameConfig = data.config;
document.getElementById("appStyles").innerHTML = data.css;
document.body.innerHTML = "";
const App = new Function("return " + data.js.substring(8))();
window.app = new App();
}
// Loads the app from the cache or server
window.suppressReload = false;
function reload(firstRequest) {
var cache = window.localStorage.getItem("appData");
if (cache != null) {
cache = JSON.parse(cache);
if (firstRequest) {
start(cache);
}
}
serverInterface.request("download_app", { hash: cache == null ? "" : cache.hash }).then((response) => {
if (response != null && response.changed) {
window.localStorage.setItem("appData", JSON.stringify(response.data));
if (!firstRequest && (window.supressReload || !confirm("The app has changed. Reload?"))) {
window.suppressReload = true;
return;
}
start(response.data);
}
});
}
// Update HTML for web or app
window.addEventListener("load", () => {
if (isWeb) {
const link = document.createElement("link");
link.rel = "icon";
link.type = "image/x-icon";
link.href = "/favicon.ico";
document.head.appendChild(link);
} else {
const script = document.createElement("script");
script.src = "cordova.js";
document.head.appendChild(script);
}
});
// Load app
window.addEventListener(isWeb ? "load" : "deviceready", () => {
import(isWeb ? "/ServerInterfaceWeb.js" : "/ServerInterfaceApp.js").then((ServerInterface) => {
window.serverInterface = new ServerInterface.default();
reload(true);
window.setInterval(() => reload(false), 2000);
});
});
</script>
</head>
<body></body>
</html>