Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions scripts/chromium-next-tab.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# Chromium remote debugging port (default: 9222)
DEBUG_PORT=9222

# Get the list of open tabs in JSON format
tabs_json=$(curl -s http://localhost:$DEBUG_PORT/json)

# Index of the currently focused tab (assumed to be the first)
focused_index=0

# Total number of tabs
total_tabs=$(echo "$tabs_json" | jq 'length')

# Calculate next index (wrap around if at the end)
#next_index=$(( (focused_index + 1) % total_tabs ))
next_index=$(( (total_tabs - 1) % total_tabs )) # The last json object seems to be the next tab

# Extract the ID of the next tab
next_tab_id=$(echo "$tabs_json" | jq -r ".[$next_index].id")
next_tab_title=$(echo "$tabs_json" | jq -r ".[$next_index].title")
next_tab_url=$(echo "$tabs_json" | jq -r ".[$next_index].url")

# Occasionally there appears to be created a new empty and unusable tab. Not sure why.
# We tried to remove that tab when that happend, but was unsuccessfull.
# So now we just skip that tab when that happens:
if [ -z "$next_tab_url" ] || [ "$next_tab_url" = "about:blank" ]; then
echo "Tab [$next_index] [$next_tab_id] is empty, falling back to second-last"
next_index=$(( next_index - 1 ))
next_tab_id=$(echo "$tabs_json" | jq -r ".[$next_index].id")
next_tab_title=$(echo "$tabs_json" | jq -r ".[$next_index].title")
next_tab_url=$(echo "$tabs_json" | jq -r ".[$next_index].url")
fi

# Activate the next tab
curl -s "http://localhost:$DEBUG_PORT/json/activate/$next_tab_id" > /dev/null
echo "Switched to tab [$next_index]: $next_tab_title ($next_tab_url | $next_tab_id) (total of $total_tabs)"
25 changes: 25 additions & 0 deletions scripts/chromium-reload-tab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python3
# This is done in Python because doing websocket comms in bash is a pain in the ...
# Needs: "sudo apt install python3-websockets" to work
import asyncio
import websockets
import json
import subprocess

# Get the WebSocket URL for the first tab
debug_info = subprocess.check_output(["curl", "-s", "http://localhost:9222/json"])
tabs = json.loads(debug_info)
ws_url = tabs[0]["webSocketDebuggerUrl"]

# Send reload command
async def reload_tab():
async with websockets.connect(ws_url) as ws:
await ws.send(json.dumps({
"id": 1,
"method": "Page.reload",
"params": {"ignoreCache": False}
}))
response = await ws.recv()
print("Reloaded tab:", response)

asyncio.run(reload_tab())
4 changes: 2 additions & 2 deletions scripts/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ chromium-browser \
--disable-smooth-scrolling \
--enable-accelerated-video-decode \
--enable-gpu-rasterization \
--enable-low-end-device-mode \
--enable-oop-rasterization \
--force-device-scale-factor=1 \
--ignore-gpu-blocklist \
--kiosk \
--no-first-run \
--noerrdialogs
--noerrdialogs \
--remote-debugging-port=9222
2 changes: 1 addition & 1 deletion scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ else
fi

echo -e "${INFO}Installing dependencies...${RESET}"
apt install -y git jq wtype nodejs npm
apt install -y git jq wtype nodejs npm python3-websockets

echo -e "${INFO}Cloning repository...${RESET}"
git clone https://github.com/debloper/piosk.git "$PIOSK_DIR"
Expand Down
4 changes: 2 additions & 2 deletions scripts/switcher.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ URLS=$(jq -r '.urls | length' /opt/piosk/config.json)
# swich tabs each 10s, refresh tabs each 10th cycle & then reset
for ((TURN=1; TURN<=$((10*URLS)); TURN++)) do
if [ $TURN -le $((10*URLS)) ]; then
wtype -M ctrl -P Tab
/opt/piosk/scripts/chromium-next-tab.sh
if [ $TURN -gt $((9*URLS)) ]; then
wtype -M ctrl r
/opt/piosk/scripts/chromium-reload-tab.py
if [ $TURN -eq $((10*URLS)) ]; then
(( TURN=0 ))
fi
Expand Down