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
- [x] Open in new tab setting
- [x] Better icon colors in 'More' page
- [ ] Work with blocked cookies
- [x] Work with blocked cookies
- [ ] Minor code optimizations
blah blah blah

View File

@ -390,3 +390,10 @@ a.box {
.hostedby b {
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>
<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="setting" onclick="switch_theme()" id="setting-theme">
<div class="icon">dark_mode</div>

View File

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

View File

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