Merge pull request #20 from outis1one/claude/fix-pause-button-rotation-01EAoiabjaWEeEbZ1WxWfp7j

Claude/fix pause button rotation 01 e aoiabja w ee eb z1 wx wfp7j
This commit is contained in:
outis1one
2025-11-18 22:01:34 -05:00
committed by GitHub
4 changed files with 604 additions and 72 deletions
+156
View File
@@ -0,0 +1,156 @@
################################################################################
# MANUAL FIX FOR PAUSE BUTTON ISSUES
# Use this if the automated update didn't work
################################################################################
ISSUE: Pause button not appearing on rotation sites
CAUSE: The pause button code might not be properly set up
SOLUTION: Manually verify/fix these sections in your kiosk files
================================================================================
FIX 1: In main.js - Find the attachView function
================================================================================
SEARCH FOR (around line 3735):
// Control pause button visibility based on site duration
REPLACE THE NEXT 3-4 LINES WITH:
// Control pause button visibility based on site duration
// Show on rotation sites (duration > 0), hide on manual sites (duration = 0)
const siteDuration=parseInt(tabs[tabIdx].duration)||0;
const shouldShow=siteDuration>0;
console.log('[MAIN] Sending pause-button-visibility to tab '+tabIdx+' ('+tabs[tabIdx].url+') - duration='+siteDuration+'s, shouldShow='+shouldShow);
views[i].webContents.send('pause-button-visibility',shouldShow);
VERIFY: shouldShow=siteDuration>0 (NOT ===0 and NOT !==0)
================================================================================
FIX 2: In preload.js - Add pause button hide timer variables
================================================================================
SEARCH FOR (around line 5151):
let pauseButton=null;
let pauseButtonShouldShow=false;
let pauseButtonShown=false;
MAKE SURE IT INCLUDES THESE TWO LINES:
let pauseButtonHideTimer=null;
const PAUSE_BUTTON_HIDE_DELAY=5000; // Hide after 5 seconds of inactivity
================================================================================
FIX 3: In preload.js - Update showPauseButton function
================================================================================
SEARCH FOR:
function showPauseButton(){
REPLACE ENTIRE FUNCTION WITH:
function showPauseButton(){
if(!pauseButton)createPauseButton();
pauseButton.style.display='flex';
pauseButtonShown=true;
// Clear existing hide timer
if(pauseButtonHideTimer){
clearTimeout(pauseButtonHideTimer);
pauseButtonHideTimer=null;
}
// Set new hide timer - button will auto-hide after inactivity
pauseButtonHideTimer=setTimeout(()=>{
console.log('[PAUSE-BTN] Auto-hiding after '+PAUSE_BUTTON_HIDE_DELAY+'ms inactivity');
hidePauseButton();
},PAUSE_BUTTON_HIDE_DELAY);
}
================================================================================
FIX 4: In preload.js - Update hidePauseButton function
================================================================================
SEARCH FOR:
function hidePauseButton(){
REPLACE ENTIRE FUNCTION WITH:
function hidePauseButton(){
if(pauseButtonHideTimer){
clearTimeout(pauseButtonHideTimer);
pauseButtonHideTimer=null;
}
if(pauseButton){
pauseButton.style.display='none';
pauseButtonShown=false;
}
}
================================================================================
FIX 5: In preload.js - Update handleUserInteraction function
================================================================================
SEARCH FOR:
function handleUserInteraction
REPLACE WITH THIS VERSION (note the eventType parameter):
function handleUserInteraction(eventType){
const now=Date.now();
if(now-lastUserInteraction<USER_INTERACTION_THROTTLE)return;
lastUserInteraction=now;
console.log('[PAUSE-BTN] User interaction ('+eventType+') - shouldShow='+pauseButtonShouldShow+', shown='+pauseButtonShown);
// Show/refresh pause button if allowed on this site
if(pauseButtonShouldShow){
if(!pauseButtonShown){
console.log('[PAUSE-BTN] Showing pause button now');
}else{
console.log('[PAUSE-BTN] Resetting auto-hide timer');
}
showPauseButton(); // This will reset the hide timer
}
}
================================================================================
FIX 6: In preload.js - Update event listener registration
================================================================================
SEARCH FOR:
const pauseButtonTriggers=['mousedown','touchstart','keydown'];
pauseButtonTriggers.forEach(eventType=>{
document.addEventListener(eventType,handleUserInteraction,{passive:true,capture:true});
});
REPLACE WITH (note the arrow function that passes eventType):
const pauseButtonTriggers=['mousedown','touchstart','keydown'];
pauseButtonTriggers.forEach(eventType=>{
document.addEventListener(eventType,()=>handleUserInteraction(eventType),{passive:true,capture:true});
});
================================================================================
AFTER MAKING CHANGES:
================================================================================
1. Save all files
2. Restart kiosk: sudo systemctl restart kiosk
3. Open DevTools console (if enabled) or check logs
4. Look for these messages:
- [MAIN] Sending pause-button-visibility to tab X - duration=15s, shouldShow=true
- [PAUSE-BTN] Visibility update: shouldShow=true
- [PAUSE-BTN] User interaction (mousedown) - shouldShow=true, shown=false
- [PAUSE-BTN] Showing pause button now
5. On rotation sites (15s duration), click/touch the screen
6. Pause button should appear and auto-hide after 5 seconds
7. On manual sites (0 duration), pause button should NOT appear
================================================================================
SIMPLER ALTERNATIVE: Full Reinstall
================================================================================
If manual editing is too complex, run:
cd /home/user/ubk
bash install_kiosk_0.9.2.sh
And choose "Full Reinstall" from the Core Settings menu.
This will apply all fixes automatically.
+101
View File
@@ -0,0 +1,101 @@
#!/bin/bash
################################################################################
# Pause Button Diagnostic Script
# Checks the actual state of pause button code in installed kiosk
################################################################################
echo "===================================="
echo " Pause Button Diagnostic Tool"
echo "===================================="
echo ""
# Find kiosk directory
KIOSK_DIR=""
if [ -f "/home/kiosk/kiosk-app/main.js" ]; then
KIOSK_DIR="/home/kiosk/kiosk-app"
elif systemctl show -p WorkingDirectory kiosk.service 2>/dev/null | grep -q "/"; then
KIOSK_DIR=$(systemctl show -p WorkingDirectory kiosk.service 2>/dev/null | cut -d= -f2)
fi
if [ -z "$KIOSK_DIR" ] || [ ! -f "$KIOSK_DIR/main.js" ]; then
echo "✗ Cannot find kiosk installation"
echo " Please run this on the kiosk machine"
exit 1
fi
echo "Found kiosk at: $KIOSK_DIR"
echo ""
echo "=== CHECK 1: Pause button visibility logic in main.js ==="
echo ""
grep -A 2 "pause-button-visibility" "$KIOSK_DIR/main.js" | head -5
echo ""
echo "=== CHECK 2: Duration check logic ==="
echo ""
grep -B 1 -A 1 "siteDuration>0\|siteDuration!==0\|siteDuration===0" "$KIOSK_DIR/main.js" | head -10
echo ""
echo "=== CHECK 3: Pause button auto-hide in preload.js ==="
echo ""
if grep -q "PAUSE_BUTTON_HIDE_DELAY" "$KIOSK_DIR/preload.js"; then
echo "✓ Auto-hide timer found"
grep "PAUSE_BUTTON_HIDE_DELAY" "$KIOSK_DIR/preload.js"
else
echo "✗ Auto-hide timer NOT found"
fi
echo ""
echo "=== CHECK 4: Return-to-home logic ==="
echo ""
grep -A 3 "ONLY show inactivity prompt\|Don't show inactivity prompt" "$KIOSK_DIR/main.js" | head -8
echo ""
echo "=== CHECK 5: User interaction handler ==="
echo ""
if grep -q "function handleUserInteraction(eventType)" "$KIOSK_DIR/preload.js"; then
echo "✓ Event type parameter found"
else
echo "✗ Event type parameter NOT found - might be broken"
fi
echo ""
echo "===================================="
echo "RECOMMENDATIONS:"
echo "===================================="
echo ""
# Check each issue
NEEDS_FIX=0
if ! grep -q "siteDuration>0" "$KIOSK_DIR/main.js"; then
echo "⚠ Pause button visibility logic needs update"
echo " Current: Should check siteDuration>0"
NEEDS_FIX=1
fi
if ! grep -q "PAUSE_BUTTON_HIDE_DELAY" "$KIOSK_DIR/preload.js"; then
echo "⚠ Pause button auto-hide not implemented"
NEEDS_FIX=1
fi
if ! grep -q "Rotation site - skip return-to-home" "$KIOSK_DIR/main.js"; then
echo "⚠ Return-to-home logic needs update"
NEEDS_FIX=1
fi
if [ $NEEDS_FIX -eq 1 ]; then
echo ""
echo ">> Run a full reinstall with install_kiosk_0.9.2.sh"
echo " The update script may not have applied correctly"
else
echo "✓ All fixes appear to be in place!"
echo ""
echo "If pause button still not showing:"
echo " 1. Open Electron DevTools (if available)"
echo " 2. Check console for [MAIN] and [PAUSE-BTN] messages"
echo " 3. Verify site duration is > 0 for rotation sites"
echo " 4. Try clicking/touching the screen on a rotation site"
fi
echo ""
+146 -72
View File
@@ -3631,7 +3631,17 @@ function startMasterTimer(){
if(homeTabIndex>=0&&!showingHidden){
const homeViewIdx=getHomeViewIndex();
const currentTabIdx=viewIndexToTabIndex(currentIndex);
// ONLY show inactivity prompt on manual sites (duration=0)
// Rotation sites handle their own timing and should NOT show inactivity prompt
if(currentTabIdx>=0&&tabs[currentTabIdx]){
const currentSiteDuration=parseInt(tabs[currentTabIdx].duration)||0;
if(currentSiteDuration>0){
// Rotation site - skip return-to-home logic (uses auto-rotation instead)
return;
}
}
if(homeViewIdx>=0&&currentIndex!==homeViewIdx){
const idleTime=now-lastUserInteraction;
@@ -3736,6 +3746,7 @@ function attachView(i){
// Show on rotation sites (duration > 0), hide on manual sites (duration = 0)
const siteDuration=parseInt(tabs[tabIdx].duration)||0;
const shouldShow=siteDuration>0;
console.log('[MAIN] Sending pause-button-visibility to tab '+tabIdx+' ('+tabs[tabIdx].url+') - duration='+siteDuration+'s, shouldShow='+shouldShow);
views[i].webContents.send('pause-button-visibility',shouldShow);
}
@@ -5040,6 +5051,82 @@ contextBridge.exposeInMainWorld('electronAPI',{
showPauseDialog:()=>ipcRenderer.send('show-pause-dialog')
});
// Pause button state (MUST be outside DOMContentLoaded to persist across page loads)
let pauseButton=null;
let pauseButtonShouldShow=false;
let pauseButtonShown=false;
let pauseButtonHideTimer=null;
const PAUSE_BUTTON_HIDE_DELAY=5000; // Hide after 5 seconds of inactivity
// Pause button functions (must be outside DOMContentLoaded for IPC listener)
function createPauseButton(){
if(pauseButton)return;
pauseButton=document.createElement('div');
pauseButton.id='electron-pause-button';
pauseButton.innerHTML='<div style="display:flex;gap:4px;"><div style="width:6px;height:24px;background:white;border-radius:2px;"></div><div style="width:6px;height:24px;background:white;border-radius:2px;"></div></div>';
pauseButton.title='Pause rotation';
pauseButton.style.cssText=`
position:fixed;bottom:20px;left:20px;width:60px;height:60px;
background:rgba(230,126,34,0.95);border:3px solid rgba(255,255,255,0.9);
border-radius:50%;display:none;align-items:center;justify-content:center;
font-size:32px;cursor:pointer;z-index:999999;
box-shadow:0 4px 12px rgba(0,0,0,0.4);user-select:none;
`;
pauseButton.addEventListener('click',(e)=>{
e.preventDefault();
e.stopPropagation();
ipcRenderer.send('show-pause-dialog');
});
document.body.appendChild(pauseButton);
}
function showPauseButton(){
if(!pauseButton)createPauseButton();
pauseButton.style.display='flex';
pauseButtonShown=true;
// Clear existing hide timer
if(pauseButtonHideTimer){
clearTimeout(pauseButtonHideTimer);
pauseButtonHideTimer=null;
}
// Set new hide timer - button will auto-hide after inactivity
pauseButtonHideTimer=setTimeout(()=>{
console.log('[PAUSE-BTN] Auto-hiding after '+PAUSE_BUTTON_HIDE_DELAY+'ms inactivity');
hidePauseButton();
},PAUSE_BUTTON_HIDE_DELAY);
}
function hidePauseButton(){
if(pauseButtonHideTimer){
clearTimeout(pauseButtonHideTimer);
pauseButtonHideTimer=null;
}
if(pauseButton){
pauseButton.style.display='none';
pauseButtonShown=false;
}
}
// Listen for pause button visibility control from main process
// CRITICAL: This must be outside DOMContentLoaded so it doesn't reset on page load
ipcRenderer.on('pause-button-visibility',(event,shouldShow)=>{
console.log('[PAUSE-BTN] Visibility update: shouldShow='+shouldShow);
pauseButtonShouldShow=shouldShow;
if(!shouldShow){
// If button should not show on this site, hide it immediately
console.log('[PAUSE-BTN] Hiding button (manual site)');
hidePauseButton();
}else{
console.log('[PAUSE-BTN] Button enabled - will show on user interaction');
}
// If shouldShow is true, button will appear on user interaction
});
window.addEventListener('DOMContentLoaded',()=>{
document.addEventListener('contextmenu',e=>e.preventDefault());
@@ -5137,78 +5224,32 @@ window.addEventListener('DOMContentLoaded',()=>{
if(keyboardIcon)keyboardIcon.style.display='none';
}
// Pause button functionality
let pauseButton=null;
let pauseButtonShouldShow=false;
let pauseButtonShown=false;
function createPauseButton(){
if(pauseButton)return;
pauseButton=document.createElement('div');
pauseButton.id='electron-pause-button';
pauseButton.innerHTML='<div style="display:flex;gap:4px;"><div style="width:6px;height:24px;background:white;border-radius:2px;"></div><div style="width:6px;height:24px;background:white;border-radius:2px;"></div></div>';
pauseButton.title='Pause rotation';
pauseButton.style.cssText=`
position:fixed;bottom:20px;left:20px;width:60px;height:60px;
background:rgba(230,126,34,0.95);border:3px solid rgba(255,255,255,0.9);
border-radius:50%;display:none;align-items:center;justify-content:center;
font-size:32px;cursor:pointer;z-index:999999;
box-shadow:0 4px 12px rgba(0,0,0,0.4);user-select:none;
`;
pauseButton.addEventListener('click',(e)=>{
e.preventDefault();
e.stopPropagation();
ipcRenderer.send('show-pause-dialog');
});
document.body.appendChild(pauseButton);
}
function showPauseButton(){
if(!pauseButton)createPauseButton();
pauseButton.style.display='flex';
pauseButtonShown=true;
}
function hidePauseButton(){
if(pauseButton){
pauseButton.style.display='none';
pauseButtonShown=false;
}
}
// Listen for pause button visibility control from main process
// Main process controls whether button should be available on this site
ipcRenderer.on('pause-button-visibility',(event,shouldShow)=>{
pauseButtonShouldShow=shouldShow;
if(!shouldShow){
// If button should not show on this site, hide it immediately
hidePauseButton();
}
// If shouldShow is true, button will appear on user interaction
});
// Pause button user interaction handler
// Show pause button on user interaction (only if allowed on this site)
let lastUserInteraction=0;
const USER_INTERACTION_THROTTLE=100;
function handleUserInteraction(){
function handleUserInteraction(eventType){
const now=Date.now();
if(now-lastUserInteraction<USER_INTERACTION_THROTTLE)return;
lastUserInteraction=now;
// Only show if this site allows pause button and it's not already shown
if(pauseButtonShouldShow&&!pauseButtonShown){
showPauseButton();
console.log('[PAUSE-BTN] User interaction ('+eventType+') - shouldShow='+pauseButtonShouldShow+', shown='+pauseButtonShown);
// Show/refresh pause button if allowed on this site
if(pauseButtonShouldShow){
if(!pauseButtonShown){
console.log('[PAUSE-BTN] Showing pause button now');
}else{
console.log('[PAUSE-BTN] Resetting auto-hide timer');
}
showPauseButton(); // This will reset the hide timer
}
}
// Show pause button on any user interaction
const pauseButtonTriggers=['mousedown','touchstart','keydown'];
pauseButtonTriggers.forEach(eventType=>{
document.addEventListener(eventType,handleUserInteraction,{passive:true,capture:true});
document.addEventListener(eventType,()=>handleUserInteraction(eventType),{passive:true,capture:true});
});
function isTextInput(el){
@@ -5397,14 +5438,16 @@ xset dpms force on
on_mins=$(( 10#$(echo "$don" | cut -d: -f1) * 60 + 10#$(echo "$don" | cut -d: -f2) ))
# Check if we're in the "display off" window
if [[ $off_mins -lt $on_mins ]]; then
# Normal case: off time is before on time (e.g., 22:00 to 06:00 next day)
if [[ $current_mins -ge $off_mins && $current_mins -lt $on_mins ]]; then
if [[ $off_mins -gt $on_mins ]]; then
# Overnight case: off time is after on time (e.g., turn off at 22:00, on at 06:00)
# Display is OFF from off_mins to midnight AND from midnight to on_mins
if [[ $current_mins -ge $off_mins || $current_mins -lt $on_mins ]]; then
schedule_active=true
fi
else
# Overnight case: off time is after on time (e.g., 06:00 to 22:00)
if [[ $current_mins -ge $off_mins || $current_mins -lt $on_mins ]]; then
# Same-day case: off time is before on time (e.g., turn off at 08:00, on at 17:00)
# Display is OFF from off_mins to on_mins
if [[ $current_mins -ge $off_mins && $current_mins -lt $on_mins ]]; then
schedule_active=true
fi
fi
@@ -8255,7 +8298,7 @@ manual_electron_update() {
# Method 1: Check if default kiosk user exists and has kiosk-app
if id "$KIOSK_USER" &>/dev/null; then
local kiosk_home=$(eval echo ~$KIOSK_USER)
if [ -d "$kiosk_home/kiosk-app" ]; then
if [ -d "$kiosk_home/kiosk-app" ] && [ -f "$kiosk_home/kiosk-app/main.js" ]; then
DETECTED_KIOSK_USER="$KIOSK_USER"
DETECTED_KIOSK_DIR="$kiosk_home/kiosk-app"
fi
@@ -8291,9 +8334,32 @@ manual_electron_update() {
# Method 5: Check parent directory
if [ -z "$DETECTED_KIOSK_DIR" ]; then
if [ -f "$(dirname "$PWD")/kiosk-app/main.js" ]; then
local parent_dir="$(dirname "$PWD")"
if [ -f "$parent_dir/kiosk-app/main.js" ]; then
DETECTED_KIOSK_USER=$(whoami)
DETECTED_KIOSK_DIR="$(dirname "$PWD")/kiosk-app"
DETECTED_KIOSK_DIR="$parent_dir/kiosk-app"
fi
fi
# Method 6: Check common system locations
if [ -z "$DETECTED_KIOSK_DIR" ]; then
for sys_dir in /opt/kiosk-app /usr/local/kiosk-app; do
if [ -f "$sys_dir/main.js" ]; then
DETECTED_KIOSK_USER=$(whoami)
DETECTED_KIOSK_DIR="$sys_dir"
break
fi
done
fi
# Method 7: Use systemd service to find kiosk directory
if [ -z "$DETECTED_KIOSK_DIR" ]; then
if systemctl list-units --all kiosk.service | grep -q kiosk.service; then
local service_dir=$(systemctl show -p WorkingDirectory kiosk.service 2>/dev/null | cut -d= -f2)
if [ -n "$service_dir" ] && [ -f "$service_dir/main.js" ]; then
DETECTED_KIOSK_USER=$(systemctl show -p User kiosk.service 2>/dev/null | cut -d= -f2)
DETECTED_KIOSK_DIR="$service_dir"
fi
fi
fi
@@ -8302,18 +8368,26 @@ manual_electron_update() {
echo "✗ Kiosk installation not found!"
echo ""
echo "Searched locations:"
echo " - /home/$KIOSK_USER/kiosk-app"
echo " - /home/*/kiosk-app"
echo " - $HOME/kiosk-app"
echo " - $PWD/kiosk-app"
echo " - $(dirname "$PWD")/kiosk-app"
echo " 1. /home/$KIOSK_USER/kiosk-app"
echo " 2. /home/*/kiosk-app (all users)"
echo " 3. $HOME/kiosk-app"
echo " 4. $PWD/kiosk-app"
echo " 5. $(dirname "$PWD")/kiosk-app"
echo " 6. /opt/kiosk-app"
echo " 7. /usr/local/kiosk-app"
echo " 8. systemd kiosk.service location"
echo ""
echo "Debug info:"
echo " Current user: $(whoami)"
echo " Current directory: $PWD"
echo " HOME: $HOME"
echo " Kiosk user exists: $(id "$KIOSK_USER" &>/dev/null && echo 'yes' || echo 'no')"
if id "$KIOSK_USER" &>/dev/null; then
echo " Kiosk user home: $(eval echo ~$KIOSK_USER)"
fi
echo ""
echo "Please install the kiosk first (Main Menu > Install Kiosk)"
echo "Or run this script from the directory where kiosk-app is located"
pause
return 1
fi
+201
View File
@@ -0,0 +1,201 @@
#!/bin/bash
################################################################################
# Kiosk 0.9.2 Critical Fixes Update Script
# Applies fixes for:
# - Return-to-home logic (manual sites only)
# - Pause button auto-hide (5 second timeout)
# - Display schedule overnight/same-day logic
################################################################################
set -e
KIOSK_USER="${KIOSK_USER:-kiosk}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "========================================"
echo " Kiosk 0.9.2 Critical Fixes Updater"
echo "========================================"
echo ""
# Find kiosk installation
find_kiosk_dir() {
local DETECTED_DIR=""
# Method 1: Check default kiosk user
if id "$KIOSK_USER" &>/dev/null; then
local kiosk_home=$(eval echo ~$KIOSK_USER)
if [ -f "$kiosk_home/kiosk-app/main.js" ]; then
DETECTED_DIR="$kiosk_home/kiosk-app"
fi
fi
# Method 2: Search all /home directories
if [ -z "$DETECTED_DIR" ]; then
for user_home in /home/*; do
if [ -f "$user_home/kiosk-app/main.js" ]; then
DETECTED_DIR="$user_home/kiosk-app"
break
fi
done
fi
# Method 3: Check systemd service
if [ -z "$DETECTED_DIR" ]; then
if systemctl list-units --all kiosk.service | grep -q kiosk.service; then
local service_dir=$(systemctl show -p WorkingDirectory kiosk.service 2>/dev/null | cut -d= -f2)
if [ -n "$service_dir" ] && [ -f "$service_dir/main.js" ]; then
DETECTED_DIR="$service_dir"
fi
fi
fi
echo "$DETECTED_DIR"
}
KIOSK_DIR=$(find_kiosk_dir)
if [ -z "$KIOSK_DIR" ] || [ ! -d "$KIOSK_DIR" ]; then
echo "✗ Kiosk installation not found!"
echo ""
echo "Searched:"
echo " - /home/$KIOSK_USER/kiosk-app"
echo " - /home/*/kiosk-app"
echo " - systemd kiosk.service location"
echo ""
echo "Please ensure kiosk is installed first"
exit 1
fi
echo "Found kiosk at: $KIOSK_DIR"
echo ""
# Detect kiosk user
KIOSK_OWNER=$(stat -c '%U' "$KIOSK_DIR")
echo "Kiosk owner: $KIOSK_OWNER"
echo ""
# Backup existing files
echo "Creating backups..."
sudo -u "$KIOSK_OWNER" cp "$KIOSK_DIR/main.js" "$KIOSK_DIR/main.js.backup.$(date +%Y%m%d_%H%M%S)"
sudo -u "$KIOSK_OWNER" cp "$KIOSK_DIR/preload.js" "$KIOSK_DIR/preload.js.backup.$(date +%Y%m%d_%H%M%S)"
sudo -u "$KIOSK_OWNER" cp "$KIOSK_DIR/autostart.sh" "$KIOSK_DIR/autostart.sh.backup.$(date +%Y%m%d_%H%M%S)" 2>/dev/null || true
echo "✓ Backups created"
echo ""
################################################################################
# Fix 1: Return-to-home logic in main.js
################################################################################
echo "Applying Fix 1: Return-to-home logic (manual sites only)..."
sudo -u "$KIOSK_OWNER" sed -i '/\/\/ 7\. HOME RETURN CHECK/,/if(homeViewIdx>=0&&currentIndex!==homeViewIdx){/ {
/\/\/ Don'"'"'t show inactivity prompt on manual sites (duration=0)/ {
s/.*/ \/\/ ONLY show inactivity prompt on manual sites (duration=0)/
a\ \/\/ Rotation sites handle their own timing and should NOT show inactivity prompt
}
/if(currentSiteDuration===0){/ s/===0/>0/
/\/\/ Manual site - skip return-to-home logic/ s/Manual site/Rotation site/
/\/\/ Manual site - skip return-to-home logic/ s/return-to-home logic/return-to-home logic (uses auto-rotation instead)/
}' "$KIOSK_DIR/main.js"
echo "✓ Fix 1 applied"
################################################################################
# Fix 2: Pause button auto-hide in preload.js
################################################################################
echo "Applying Fix 2: Pause button auto-hide..."
# Add pause button hide timer variables
sudo -u "$KIOSK_OWNER" sed -i '/let pauseButtonShown=false;/a\ let pauseButtonHideTimer=null;\n const PAUSE_BUTTON_HIDE_DELAY=5000; \/\/ Hide after 5 seconds of inactivity' "$KIOSK_DIR/preload.js"
# Update showPauseButton function
sudo -u "$KIOSK_OWNER" sed -i '/function showPauseButton(){/,/^ }$/ {
/pauseButtonShown=true;/a\
\n \/\/ Clear existing hide timer\
if(pauseButtonHideTimer){\
clearTimeout(pauseButtonHideTimer);\
pauseButtonHideTimer=null;\
}\
\n \/\/ Set new hide timer - button will auto-hide after inactivity\
pauseButtonHideTimer=setTimeout(()=>{\
console.log('"'"'[PAUSE-BTN] Auto-hiding after '"'"'\''+PAUSE_BUTTON_HIDE_DELAY+'\''ms inactivity'"'"');\
hidePauseButton();\
},PAUSE_BUTTON_HIDE_DELAY);
}' "$KIOSK_DIR/preload.js"
# Update hidePauseButton function
sudo -u "$KIOSK_OWNER" sed -i '/function hidePauseButton(){/a\ if(pauseButtonHideTimer){\n clearTimeout(pauseButtonHideTimer);\n pauseButtonHideTimer=null;\n }' "$KIOSK_DIR/preload.js"
# Update handleUserInteraction to reset timer on each interaction
sudo -u "$KIOSK_OWNER" sed -i '/function handleUserInteraction(eventType){/,/^ }$/ {
/if(pauseButtonShouldShow&&!pauseButtonShown){/ {
s/.*/ \/\/ Show\/refresh pause button if allowed on this site\
if(pauseButtonShouldShow){\
if(!pauseButtonShown){\
console.log('"'"'[PAUSE-BTN] Showing pause button now'"'"');\
}else{\
console.log('"'"'[PAUSE-BTN] Resetting auto-hide timer'"'"');\
}\
showPauseButton(); \/\/ This will reset the hide timer/
N
N
d
}
}' "$KIOSK_DIR/preload.js"
echo "✓ Fix 2 applied"
################################################################################
# Fix 3: Display schedule logic in autostart.sh
################################################################################
if [ -f "$KIOSK_DIR/autostart.sh" ]; then
echo "Applying Fix 3: Display schedule overnight/same-day logic..."
sudo -u "$KIOSK_OWNER" sed -i '/# Check if we'"'"'re in the "display off" window/,/fi$/ {
/if \[\[ \$off_mins -lt \$on_mins \]\]; then/ s/-lt/-gt/
/# Normal case:.*22:00 to 06:00/ {
s/Normal case/Overnight case/
s/off time is before on time/off time is after on time/
s/turn off at 22:00, on at 06:00)/
s/# Display is OFF from off_mins to midnight AND from midnight to on_mins/
}
/# Overnight case:.*06:00 to 22:00/ {
s/Overnight case/Same-day case/
s/off time is after on time/off time is before on time/
s/turn off at 06:00, on at 22:00)/turn off at 08:00, on at 17:00)/
s/# Display is OFF from off_mins to on_mins/
}
}' "$KIOSK_DIR/autostart.sh"
echo "✓ Fix 3 applied"
else
echo "⚠ autostart.sh not found, skipping Fix 3"
fi
################################################################################
# Summary and Restart
################################################################################
echo ""
echo "========================================"
echo " ✓ All fixes applied successfully!"
echo "========================================"
echo ""
echo "Applied fixes:"
echo " 1. Return-to-home popup now appears ONLY on manual sites"
echo " 2. Pause button auto-hides after 5 seconds of inactivity"
echo " 3. Display schedule overnight/same-day logic corrected"
echo ""
echo "Backups saved in: $KIOSK_DIR/*.backup.*"
echo ""
read -p "Restart kiosk service now? (y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "Restarting kiosk service..."
sudo systemctl restart kiosk
echo "✓ Kiosk restarted"
else
echo "Please restart kiosk manually: sudo systemctl restart kiosk"
fi
echo ""
echo "Done!"