Skip to content

Commit fb2b920

Browse files
committed
Hold CAFFEINE for the duration of the app
Long batch scrapes (1000+ ROMs at default thread count) can run for 20+ minutes. On a device with the screen-off timeout shorter than that, muOS would suspend the device mid-scrape — losing in-flight HTTP requests and leaving the user with a half-scraped library. muOS exposes a CAFFEINE function that suppresses sleep while the app is running. Toggle it on right before the run loop and off after. Guarded by `command -v` so the launch script stays compatible with older muOS builds that don't ship CAFFEINE.
1 parent 07b75b3 commit fb2b920

1 file changed

Lines changed: 30 additions & 23 deletions

File tree

‎mux_launch.sh‎

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ APP_BIN="app"
1717
# back to resolving paths relative to this script (works on SD1 or SD2).
1818
# ---------------------------------------------------------------------------
1919
if command -v SETUP_APP >/dev/null 2>&1; then
20-
SETUP_APP "$APP_BIN" ""
21-
APP_DIR="/run/muos/storage/application/Artie"
22-
if [ ! -d "$APP_DIR" ]; then
23-
# SETUP_APP didn't provide the expected location; fall back.
24-
APP_DIR="$(dirname "$(realpath "$0")")"
25-
fi
20+
SETUP_APP "$APP_BIN" ""
21+
APP_DIR="/run/muos/storage/application/Artie"
22+
if [ ! -d "$APP_DIR" ]; then
23+
# SETUP_APP didn't provide the expected location; fall back.
24+
APP_DIR="$(dirname "$(realpath "$0")")"
25+
fi
2626
else
27-
# Legacy muOS (pre-Jacaranda). SETUP_SDL_ENVIRONMENT sets up scaler/rotation.
28-
if command -v SETUP_SDL_ENVIRONMENT >/dev/null 2>&1; then
29-
SETUP_SDL_ENVIRONMENT
30-
fi
31-
APP_DIR="$(dirname "$(realpath "$0")")"
27+
# Legacy muOS (pre-Jacaranda). SETUP_SDL_ENVIRONMENT sets up scaler/rotation.
28+
if command -v SETUP_SDL_ENVIRONMENT >/dev/null 2>&1; then
29+
SETUP_SDL_ENVIRONMENT
30+
fi
31+
APP_DIR="$(dirname "$(realpath "$0")")"
3232
fi
3333

3434
ARTIE_DIR="$APP_DIR/.artie"
@@ -37,7 +37,7 @@ BINDIR="$ARTIE_DIR/bin"
3737

3838
# Kill background music if running (frees the audio device for SDL_mixer)
3939
if pgrep -f "playbgm.sh" >/dev/null; then
40-
killall -q "playbgm.sh" "mpg123"
40+
killall -q "playbgm.sh" "mpg123"
4141
fi
4242

4343
echo app >/tmp/act_go
@@ -57,19 +57,19 @@ export LD_LIBRARY_PATH="$BINDIR/libs.aarch64:$LD_LIBRARY_PATH"
5757

5858
SYSTEM_SDL2="/usr/lib/libSDL2-2.0.so.0"
5959
if [ -f "$SYSTEM_SDL2" ]; then
60-
export LD_PRELOAD="$SYSTEM_SDL2:$LD_PRELOAD"
60+
export LD_PRELOAD="$SYSTEM_SDL2:$LD_PRELOAD"
6161
fi
6262

6363
cd "$ARTIE_DIR" || exit 1
6464

6565
if command -v SET_VAR >/dev/null 2>&1; then
66-
SET_VAR "system" "foreground_process" "$APP_BIN"
66+
SET_VAR "system" "foreground_process" "$APP_BIN"
6767
fi
6868

6969
# Device resolution
7070
if command -v GET_VAR >/dev/null 2>&1; then
71-
SCREEN_WIDTH=$(GET_VAR device mux/width 2>/dev/null)
72-
SCREEN_HEIGHT=$(GET_VAR device mux/height 2>/dev/null)
71+
SCREEN_WIDTH=$(GET_VAR device mux/width 2>/dev/null)
72+
SCREEN_HEIGHT=$(GET_VAR device mux/height 2>/dev/null)
7373
fi
7474
SCREEN_WIDTH="${SCREEN_WIDTH:-640}"
7575
SCREEN_HEIGHT="${SCREEN_HEIGHT:-480}"
@@ -81,16 +81,23 @@ log_file="${ARTIE_DIR}/log.txt"
8181
# Fresh log each launch
8282
>"$log_file"
8383

84+
# Keep the device awake during long batch scrapes. CAFFEINE is provided
85+
# by recent muOS builds; the `command -v` guard makes this a no-op on
86+
# older versions that don't ship it.
87+
command -v CAFFEINE >/dev/null 2>&1 && CAFFEINE on
88+
8489
# Run Application — pygame/SDL2 handles controller input directly.
8590
# Exit code 42 = restart after OTA update; anything else = normal exit.
8691
while true; do
87-
$program "${SCREEN_RESOLUTION}" >>"$log_file" 2>&1
88-
exit_code=$?
92+
$program "${SCREEN_RESOLUTION}" >>"$log_file" 2>&1
93+
exit_code=$?
8994

90-
if [ "$exit_code" -ne 42 ]; then
91-
break
92-
fi
95+
if [ "$exit_code" -ne 42 ]; then
96+
break
97+
fi
9398

94-
echo "Restarting after update..." >>"$log_file"
95-
sleep 1
99+
echo "Restarting after update..." >>"$log_file"
100+
sleep 1
96101
done
102+
103+
command -v CAFFEINE >/dev/null 2>&1 && CAFFEINE off

0 commit comments

Comments
 (0)