summaryrefslogtreecommitdiff
path: root/app/load.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/load.js')
-rw-r--r--app/load.js105
1 files changed, 78 insertions, 27 deletions
diff --git a/app/load.js b/app/load.js
index 9efff3c..9e4d3b9 100644
--- a/app/load.js
+++ b/app/load.js
@@ -18,73 +18,119 @@ window.connected = false;
let valuesToGet = {
"pluralkit-cloudburst-members": {
url: "/api/data?f=ynmuc-members.json",
- limited: false
+ limited: false,
+ name: "Members at Cloudburst...",
},
"pluralkit-cloudburst-fronters": {
url: "/api/data?f=ynmuc-fronters.json",
- limited: false
+ limited: false,
+ name: "Fronters at Cloudburst...",
},
"pluralkit-cloudburst-switches": {
url: "/api/data?f=ynmuc-switches.json",
- limited: false
+ limited: false,
+ name: "Switches at Cloudburst...",
},
"pluralkit-raindrops-members": {
url: "/api/data?f=gdapd-members.json",
- limited: false
+ limited: false,
+ name: "Members at Raindrops...",
},
"pluralkit-raindrops-fronters": {
url: "/api/data?f=gdapd-fronters.json",
- limited: false
+ limited: false,
+ name: "Fronters at Raindrops...",
},
"pluralkit-raindrops-switches": {
url: "/api/data?f=gdapd-switches.json",
- limited: false
+ limited: false,
+ name: "Switches at Raindrops...",
},
"peh-cloudburst-data": {
url: "/api/cloudburst-data",
- limited: false
+ limited: false,
+ name: "Cloudburst data...",
},
"peh-raindrops-data": {
url: "/api/raindrops-data",
- limited: false
+ limited: false,
+ name: "Raindrops data...",
},
"peh-cloudburst-banners": {
url: "/api/cloudburst-banners",
- limited: false
+ limited: false,
+ name: "Cloudburst banner data...",
},
"peh-raindrops-banners": {
url: "/api/raindrops-banners",
- limited: false
+ limited: false,
+ name: "Raindrops banner data...",
},
"identity": {
url: "/api/me",
- limited: false
+ limited: false,
+ name: "Identity...",
},
"images": {
url: "/api/app-images",
- limited: false
+ limited: false,
+ name: "Images...",
+ condition: async () => {
+ let known = await localforage.getItem("images-refresh");
+ let currentKnown;
+
+ try {
+ currentKnown = btoa(Object.keys(JSON.parse(await localforage.getItem("peh-cloudburst-data")).members).join("") + Object.keys(JSON.parse(await localforage.getItem("peh-raindrops-data")).members).join("") + new Date().toDateString());
+ } catch (e) {
+ return true;
+ }
+
+ localforage.setItem("images-refresh", currentKnown);
+
+ if (known) {
+ return known !== currentKnown;
+ } else {
+ return true;
+ }
+ }
},
"image-me": {
url: "/api/me-picture",
- limited: false
+ limited: false,
+ name: "Identity avatar...",
},
"bits-transactions": {
url: "/bits/Application/TransactionsList/index.php",
- limited: false
+ limited: false,
+ name: "Bits transactions...",
},
"bits-goal": {
url: "/bits/Application/GetGoal/index.php",
- limited: false
+ limited: false,
+ name: "Bits goal...",
},
"bits-username": {
url: "/bits/Authentication/Username/index.php",
- limited: false
+ limited: false,
+ name: "Bits user info...",
}
}
let keys = Object.keys(valuesToGet);
let index = 2;
+window.onerror = (event, source, lineno, colno, error) => {
+ console.log(event, source, lineno, colno, error);
+ document.getElementById("loader-message").classList.add("text-danger");
+ document.getElementById("loader-message").innerText = "An error occurred.";
+}
+
+window.onunhandledrejection = (handler, event) => {
+ console.log(handler, event);
+ document.getElementById("loader-message").classList.add("text-danger");
+ document.getElementById("loader-message").innerText = "An error occurred.";
+}
+
async function getNewValue() {
if (!keys[0]) {
await postLoad();
@@ -92,6 +138,9 @@ async function getNewValue() {
}
try {
+ if (valuesToGet[keys[0]].condition && !(await valuesToGet[keys[0]].condition())) throw new Error();
+
+ document.getElementById("loader-message").innerText = valuesToGet[keys[0]].name;
await localforage.setItem(keys[0], (await (await fetchPlus(valuesToGet[keys[0]]["url"], { timeout: 3000 })).text()));
keys.shift();
@@ -198,21 +247,23 @@ async function postLoad() {
document.getElementById("home-app-emergency").classList.add("disabled");
}
- if (window.serviceWorkerRegistration.sync) {
- window.serviceWorkerRegistration.sync.register('data-sync')
- .catch(function(err) {
- return err;
- })
- .then(() => {
- console.log("Scheduled background sync for the next time connection is available");
- })
- } else {
- console.log("Background sync not possible on this platform");
+ if (window.serviceWorkerRegistration) {
+ if (window.serviceWorkerRegistration.sync) {
+ window.serviceWorkerRegistration.sync.register('data-sync')
+ .catch(function(err) {
+ return err;
+ })
+ .then(() => {
+ console.log("Scheduled background sync for the next time connection is available");
+ })
+ } else {
+ console.log("Background sync not possible on this platform");
+ }
}
window.currentMemberData = JSON.parse(localStorage.getItem("peh-" + JSON.parse(localStorage.getItem("identity")).id + "-banners"))[JSON.parse(localStorage.getItem("pluralkit-" + JSON.parse(localStorage.getItem("identity")).id + "-fronters")).members[0].name];
- await refreshBanner(true); refreshTooltips();
+ //await refreshBanner(true); refreshTooltips();
setInterval(async () => {
Array.from(document.getElementsByClassName("relative-time")).forEach((el) => {