mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-18 17:49:31 -07:00
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:
@@ -349,10 +349,20 @@ const updateFullScreenNavigate = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const documentKeydown = (e) => {
|
const documentKeydown = (e) => {
|
||||||
// don't trigger on ctrl/alt/shift modified key
|
|
||||||
if (e.altKey || e.ctrlKey || e.shiftKey) return false;
|
|
||||||
const { key } = e;
|
const { key } = e;
|
||||||
|
|
||||||
|
// Handle Ctrl+K to exit kiosk mode (even when other modifiers would normally be ignored)
|
||||||
|
if (e.ctrlKey && (key === 'k' || key === 'K')) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (settings.kiosk?.value) {
|
||||||
|
settings.kiosk.value = false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// don't trigger on ctrl/alt/shift modified key for other shortcuts
|
||||||
|
if (e.altKey || e.ctrlKey || e.shiftKey) return false;
|
||||||
|
|
||||||
if (document.fullscreenElement || document.activeElement === document.body) {
|
if (document.fullscreenElement || document.activeElement === document.body) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case ' ': // Space
|
case ' ': // Space
|
||||||
|
|||||||
@@ -26,6 +26,13 @@ const kioskChange = (value) => {
|
|||||||
window.dispatchEvent(new Event('resize'));
|
window.dispatchEvent(new Event('resize'));
|
||||||
} else {
|
} else {
|
||||||
body.classList.remove('kiosk');
|
body.classList.remove('kiosk');
|
||||||
|
window.dispatchEvent(new Event('resize'));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Conditionally store the kiosk setting based on the "Sticky Kiosk" setting
|
||||||
|
// (Need to check if the method exists to handle initialization race condition)
|
||||||
|
if (settings.kiosk?.conditionalStoreToLocalStorage) {
|
||||||
|
settings.kiosk.conditionalStoreToLocalStorage(value, settings.stickyKiosk?.value);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -95,6 +102,12 @@ const init = () => {
|
|||||||
defaultValue: false,
|
defaultValue: false,
|
||||||
changeAction: kioskChange,
|
changeAction: kioskChange,
|
||||||
sticky: false,
|
sticky: false,
|
||||||
|
stickyRead: true,
|
||||||
|
});
|
||||||
|
settings.stickyKiosk = new Setting('stickyKiosk', {
|
||||||
|
name: 'Sticky Kiosk',
|
||||||
|
defaultValue: false,
|
||||||
|
sticky: true,
|
||||||
});
|
});
|
||||||
settings.speed = new Setting('speed', {
|
settings.speed = new Setting('speed', {
|
||||||
name: 'Speed',
|
name: 'Speed',
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const DEFAULTS = {
|
|||||||
defaultValue: undefined,
|
defaultValue: undefined,
|
||||||
changeAction: () => { },
|
changeAction: () => { },
|
||||||
sticky: true,
|
sticky: true,
|
||||||
|
stickyRead: false,
|
||||||
values: [],
|
values: [],
|
||||||
visible: true,
|
visible: true,
|
||||||
};
|
};
|
||||||
@@ -28,6 +29,7 @@ class Setting {
|
|||||||
this.myValue = this.defaultValue;
|
this.myValue = this.defaultValue;
|
||||||
this.type = options?.type;
|
this.type = options?.type;
|
||||||
this.sticky = options.sticky;
|
this.sticky = options.sticky;
|
||||||
|
this.stickyRead = options.stickyRead;
|
||||||
this.values = options.values;
|
this.values = options.values;
|
||||||
this.visible = options.visible;
|
this.visible = options.visible;
|
||||||
this.changeAction = options.changeAction;
|
this.changeAction = options.changeAction;
|
||||||
@@ -51,7 +53,7 @@ class Setting {
|
|||||||
|
|
||||||
// get existing value if present
|
// get existing value if present
|
||||||
const storedValue = urlState ?? this.getFromLocalStorage();
|
const storedValue = urlState ?? this.getFromLocalStorage();
|
||||||
if ((this.sticky || urlValue !== undefined) && storedValue !== null) {
|
if ((this.sticky || this.stickyRead || urlValue !== undefined) && storedValue !== null) {
|
||||||
this.myValue = storedValue;
|
this.myValue = storedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,6 +156,20 @@ class Setting {
|
|||||||
localStorage?.setItem(SETTINGS_KEY, JSON.stringify(allSettings));
|
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() {
|
getFromLocalStorage() {
|
||||||
const allSettings = localStorage?.getItem(SETTINGS_KEY);
|
const allSettings = localStorage?.getItem(SETTINGS_KEY);
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user