Make it working with no cookies

This commit is contained in:
Daniel 2023-01-18 17:24:34 +01:00
parent 1c637efae3
commit be40d9642f
5 changed files with 32 additions and 12 deletions

View File

@ -13,7 +13,7 @@ This will be a dashboard hosted on my homeserver with self-hosted stuff. But, fo
- [ ] Fix blur flicker on showing/hiding pages - [ ] Fix blur flicker on showing/hiding pages
- [x] Open in new tab setting - [x] Open in new tab setting
- [x] Better icon colors in 'More' page - [x] Better icon colors in 'More' page
- [ ] Work with blocked cookies - [x] Work with blocked cookies
- [ ] Minor code optimizations - [ ] Minor code optimizations
blah blah blah blah blah blah

View File

@ -389,4 +389,11 @@ a.box {
} }
.hostedby b { .hostedby b {
color: #56F; color: #56F;
}
.warn {
margin: 8px 0;
color: #F60;
}
.none {
display: none;
} }

View File

@ -92,6 +92,7 @@
<div class="hostedby">All services hosted by <b id="app-hostedby"></b></div> <div class="hostedby">All services hosted by <b id="app-hostedby"></b></div>
</div> </div>
<div class="screen hidden"> <div class="screen hidden">
<div class="warn none" id="nocook">WARNING: due to blocked cookies, all settings will be lost after page reload</div>
<div class="settings"> <div class="settings">
<div class="setting" onclick="switch_theme()" id="setting-theme"> <div class="setting" onclick="switch_theme()" id="setting-theme">
<div class="icon">dark_mode</div> <div class="icon">dark_mode</div>

View File

@ -46,16 +46,26 @@ function mk_entry(app) {
</a>`; </a>`;
} }
function config(key, value) { function check_cookies() {
let def = CONFIG["ui"][key]; try {
let val = localStorage.getItem(key); localStorage;
if (def == value && !val) return; return true;
if (value !== undefined) {
localStorage.setItem(key, value);
return;
} }
if (!val) val = CONFIG["ui"][key].toString(); catch {
return val; return false;
}
}
function config(key, value) {
let write = value !== undefined;
if (check_cookies()) {
let val = localStorage.getItem(key);
if (CONFIG["ui"][key] == value && !val) return;
if (write) localStorage.setItem(key, value);
return val;
}
if (write) CONFIG["ui"][key] = value.toString();
return CONFIG["ui"][key].toString();
} }
function get_bool(key) { function get_bool(key) {
@ -63,11 +73,13 @@ function get_bool(key) {
} }
function load_config(conf) { function load_config(conf) {
CONFIG_DEFAULT = conf;
if (conf) CONFIG = JSON.parse(conf); if (conf) CONFIG = JSON.parse(conf);
let ui = CONFIG.ui; let ui = CONFIG.ui;
set("app-name", ui.name); set("app-name", ui.name);
set("app-desc", ui.desc); set("app-desc", ui.desc);
get("app-icon").src = ui.icon; get("app-icon").src = ui.icon;
if (!check_cookies()) get("nocook").classList.remove("none");
if (ui.hosted_by) set("app-hostedby", ui.hosted_by); if (ui.hosted_by) set("app-hostedby", ui.hosted_by);
else get("app-hostedby").parentNode.style.display = "none"; else get("app-hostedby").parentNode.style.display = "none";
load_apps(); load_apps();

View File

@ -74,8 +74,8 @@ function new_tab_toggle(value) {
} }
function reset_all_settings() { function reset_all_settings() {
localStorage.clear(); if (check_cookies()) localStorage.clear();
load_config(); load_config(CONFIG_DEFAULT);
} }
let S_TAP_LOCK; let S_TAP_LOCK;