summaryrefslogtreecommitdiffstats
path: root/assets/js/setup-storage.js.bvr
blob: 3d3b55415728e9f8f4aa72061b4f18fe67f2fa0e (plain) (blame)
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
<@?i global@>
// @begin=js@
async function setupStorage(force = false) {
	let logged_in;
	promises_check_if_already_installed = [
		localforage.getItem("logged_in").then(function (val) {
			console.log("[setupStorage] logged in status: " + val);
			logged_in = val;
		})
	];
	await Promise.all(promises_check_if_already_installed);

	let promises_update = [
		localforage.setItem("profile", {}),
		localforage.setItem("timetable", []),
		localforage.setItem("teachers", []),
		localforage.setItem("gradings", []),
		localforage.setItem("grades", []),
		localforage.setItem("absences", {}),
		localforage.setItem("messages", [[], [], []]), // see messages.js:129, commit 8eb9ca9caca30fbbe023243657535ab4088be377
		localforage.setItem("directory", {}), //\\ well I could remember my own code but I didn't.
		localforage.setItem("meals", {}),
		localforage.setItem("lastUpdate", 0),
		localforage.setItem("triggerWarningAccepted", false)
	];

	if (logged_in && force == false) { // torej, če je že bila prijava narejena, ne posodobi backwards-compatible vrednosti (username, password,...)
		await Promise.all(promises_update);
		console.log("[setupStorage] user logged in: only updated");
	} else {

		let promises_first_install = [
			localforage.setItem("logged_in", false),
			localforage.setItem("username", ""),
			localforage.setItem("password", ""),
			localforage.setItem("chosenLang", "<@?g app_default_language@>"),
			localforage.setItem("theme", "light"),
			localforage.setItem("errorReporting", "on"),
		];
		await localforage.clear();
		await Promise.all(promises_first_install);
		await Promise.all(promises_update);
		console.log("[setupStorage] user not logged in: set up whole database");
	}
}