Add "Sticky Kiosk" setting that stores "Kiosk" mode when activate

- This setting is important to allow creation ofa Home Screen app on iOS/iPadOS
- If kiosk mode is accidentally made sticky, it can be cleared by adding '&kiosk=false` to the URL
- Ctrl-K will now also exit kiosk mode

This adds a `stickyRead` parameter to settings, that means "read it if it's there, but don't write it"
This commit is contained in:
Eddy G
2025-07-01 21:49:36 -04:00
parent 2761f76117
commit 67dfd7ec08
3 changed files with 42 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ const DEFAULTS = {
defaultValue: undefined,
changeAction: () => { },
sticky: true,
stickyRead: false,
values: [],
visible: true,
};
@@ -28,6 +29,7 @@ class Setting {
this.myValue = this.defaultValue;
this.type = options?.type;
this.sticky = options.sticky;
this.stickyRead = options.stickyRead;
this.values = options.values;
this.visible = options.visible;
this.changeAction = options.changeAction;
@@ -51,7 +53,7 @@ class Setting {
// get existing value if present
const storedValue = urlState ?? this.getFromLocalStorage();
if ((this.sticky || urlValue !== undefined) && storedValue !== null) {
if ((this.sticky || this.stickyRead || urlValue !== undefined) && storedValue !== null) {
this.myValue = storedValue;
}
@@ -154,6 +156,20 @@ class Setting {
localStorage?.setItem(SETTINGS_KEY, JSON.stringify(allSettings));
}
// Conditional storage method for stickyRead settings
conditionalStoreToLocalStorage(value, shouldStore) {
if (!this.stickyRead) return;
const allSettingsString = localStorage?.getItem(SETTINGS_KEY) ?? '{}';
const allSettings = JSON.parse(allSettingsString);
if (shouldStore) {
allSettings[this.shortName] = value;
} else {
delete allSettings[this.shortName];
}
localStorage?.setItem(SETTINGS_KEY, JSON.stringify(allSettings));
}
getFromLocalStorage() {
const allSettings = localStorage?.getItem(SETTINGS_KEY);
try {