From edc40e0fbf54d453d3165a06e52a5ee4408de4b3 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 8 Feb 2025 10:19:07 -0500 Subject: [PATCH] refactor: provide the ability to start syncthing on boot - write logs to LOGS_PATH instead of pak dir - remove daemon-mode configuration (no longer needed) - use minui-list to handle interactions instead of evtest - add ability to run on boot - add support for multiple platforms (now including the rg35xxplus) - rebrand as minui-screenshot-monitor.pak --- .gitarchiveinclude | 1 - .gitattributes | 1 - .gitignore | 2 + Dockerfile.evtest | 24 ---- Makefile | 10 +- README.md | 26 ++--- bin/on-boot | 14 +++ bin/service-on | 29 +++++ launch.sh | 284 +++++++++++++++++++++++---------------------- 9 files changed, 200 insertions(+), 191 deletions(-) delete mode 100644 Dockerfile.evtest create mode 100755 bin/on-boot create mode 100755 bin/service-on diff --git a/.gitarchiveinclude b/.gitarchiveinclude index 27bdc57..a65677f 100644 --- a/.gitarchiveinclude +++ b/.gitarchiveinclude @@ -1,3 +1,2 @@ -bin/evtest bin/sdl2imgshow res/fonts/BPreplayBold.otf diff --git a/.gitattributes b/.gitattributes index 70cddbb..5d59ec5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,6 +2,5 @@ .gitattributes export-ignore .gitarchiveinclude export-ignore .gitignore export-ignore -Dockerfile.evtest export-ignore Dockerfile.sdl2imgshow export-ignore Makefile export-ignore diff --git a/.gitignore b/.gitignore index be49ab4..daa4c74 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ res/fonts/* !bin/screenshot !bin/screenshot-monitor +!bin/service-on +!bin/on-boot diff --git a/Dockerfile.evtest b/Dockerfile.evtest deleted file mode 100644 index bfed36d..0000000 --- a/Dockerfile.evtest +++ /dev/null @@ -1,24 +0,0 @@ -FROM golang:1.23.4-bullseye - -ARG EVTEST_VERSION=evtest-1.35 -ENV EVTEST_VERSION=$EVTEST_VERSION - -RUN git clone https://gitlab.freedesktop.org/libevdev/evtest.git/ /go/src/github.com/freedesktop/evtest && \ - git -C /go/src/github.com/freedesktop/evtest checkout "tags/$EVTEST_VERSION" - -WORKDIR /go/src/github.com/freedesktop/evtest - -ENV GOOS=linux -ENV GOARCH=arm64 -ENV CGO_ENABLED=1 -ENV CC=aarch64-linux-gnu-gcc - -RUN apt-get update && apt-get install -y autoconf -RUN ./autogen.sh -RUN ./configure --prefix=/usr --host=aarch64-linux-gnu -RUN make - -RUN apt-get update && apt-get install -y file - -RUN ls -lah /go/src/github.com/freedesktop/evtest -RUN file /go/src/github.com/freedesktop/evtest/evtest diff --git a/Makefile b/Makefile index 2a850e8..ae57eed 100644 --- a/Makefile +++ b/Makefile @@ -3,18 +3,10 @@ BUILD_DATE := "$(shell date -u +%FT%TZ)" PAK_NAME := $(shell jq -r .label config.json) clean: - rm -f bin/evtest || true rm -f bin/sdl2imgshow || true rm -f res/fonts/BPreplayBold.otf || true -build: bin/evtest bin/sdl2imgshow res/fonts/BPreplayBold.otf - -bin/evtest: - docker buildx build --platform linux/arm64 --load -f Dockerfile.evtest --progress plain -t app/evtest:$(TAG) . - docker container create --name extract app/evtest:$(TAG) - docker container cp extract:/go/src/github.com/freedesktop/evtest/evtest bin/evtest - docker container rm extract - chmod +x bin/evtest +build: bin/sdl2imgshow res/fonts/BPreplayBold.otf bin/sdl2imgshow: docker buildx build --platform linux/arm64 --load -f Dockerfile.sdl2imgshow --progress plain -t app/sdl2imgshow:$(TAG) . diff --git a/README.md b/README.md index 825320d..904c482 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,31 @@ -# trimui-brick-screenshot-monitor.pak +# minui-screenshot-monitor.pak -A TrimUI Brick app allowing for taking screenshots on the device using a hotkey. +A MinUI app allowing for taking screenshots on the device using a hotkey. ## Requirements -- Docker (for building) +This pak is designed and tested on the following MinUI Platforms and devices: -## Building +- `tg5040`: Trimui Brick (formerly `tg3040`), Trimui Smart Pro +- `rg35xxplus`: RG-35XX Plus, RG-34XX, RG-35XX H, RG-35XX SP -```shell -make release -``` +Use the correct platform for your device. ## Installation -1. Mount your TrimUI Brick SD card. +1. Mount your MinUI SD card. 2. Download the latest release from Github. It will be named `Screenshot.Monitor.pak.zip`. -3. Copy the zip file to `/Tools/tg5040/Screenshot Monitor.pak.zip`. Please ensure the new zip file name is `Screenshot Monitor.pak.zip`, without a dot (`.`) between the words `Screenshot` and `Monitor`. +3. Copy the zip file to `/Tools/$PLATFORM/Screenshot Monitor.pak.zip`. Please ensure the new zip file name is `Screenshot Monitor.pak.zip`, without a dot (`.`) between the words `Screenshot` and `Monitor`. 4. Extract the zip in place, then delete the zip file. -5. Confirm that there is a `/Tools/tg5040/Screenshot Monitor.pak/launch.sh` file on your SD card. -6. Unmount your SD Card and insert it into your TrimUI Brick. - -> [!NOTE] -> The device directory changed from `/Tools/tg3040` to `/Tools/tg5040` in `MinUI-20250126-0` - released 2025-01-26. If you are using an older version of MinUI, use `/Tools/tg3040` instead. +5. Confirm that there is a `/Tools/$PLATFORM/Screenshot Monitor.pak/launch.sh` file on your SD card. +6. Unmount your SD Card and insert it into your MinUI device. ## Usage > [!IMPORTANT] > If the zip file was not extracted correctly, the pak may show up under `Tools > Screenshot`. Rename the folder to `Screenshot Monitor.pak` to fix this. -Browse to `Tools > Screenshot Monitor` and press `A` to turn on the screenshot monitor. At this time, it must be turned on manually when the Brick starts in order to function. +Browse to `Tools > Screenshot Monitor` and press `A` to turn on the screenshot monitor. Press the hotkey when in game. A png screenshot will appear on the SDCard, in `/mnt/SDCARD/Screenshots`, with the name of the game and the current date as the filename. diff --git a/bin/on-boot b/bin/on-boot new file mode 100755 index 0000000..4d58647 --- /dev/null +++ b/bin/on-boot @@ -0,0 +1,14 @@ +#!/bin/sh +bindir="$(dirname "$0")" +progdir="$(dirname "$bindir")" +PAK_NAME="$(basename "$progdir")" + +main() { + "$bindir/service-on" & +} + +if [ -f "$LOGS_PATH/$PAK_NAME.txt" ]; then + mv "$LOGS_PATH/$PAK_NAME.txt" "$LOGS_PATH/$PAK_NAME.txt.old" +fi + +main "$@" >"$LOGS_PATH/$PAK_NAME.txt" 2>&1 diff --git a/bin/service-on b/bin/service-on new file mode 100755 index 0000000..340ceca --- /dev/null +++ b/bin/service-on @@ -0,0 +1,29 @@ +#!/bin/sh +bindir="$(dirname "$0")" +progdir="$(dirname "$bindir")" +cd "$progdir" || exit 1 +PAK_NAME="$(basename "$progdir")" +export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$progdir/lib" + +main() { + cd "$SDCARD_PATH" || exit 1 + if [ -f "$LOGS_PATH/$PAK_NAME.service.log" ]; then + mv "$LOGS_PATH/$PAK_NAME.service.log" "$LOGS_PATH/$PAK_NAME.service.log.old" + fi + + hotkey="HOTKEY_1" + if [ -f "$progdir/hotkey" ]; then + hotkey="$(cat "$progdir/hotkey")" + fi + + if [ -z "$hotkey" ]; then + hotkey="HOTKEY_1" + fi + if [ "$hotkey" != "HOTKEY_1" ] && [ "$hotkey" != "HOTKEY_2" ]; then + hotkey="HOTKEY_1" + fi + + (PROGDIR="$progdir" HOTKEY="$hotkey" "$bindir/screenshot-monitor" >"$LOGS_PATH/$PAK_NAME.service.log" 2>&1 &) & +} + +main "$@" diff --git a/launch.sh b/launch.sh index 6abb423..1432545 100644 --- a/launch.sh +++ b/launch.sh @@ -2,49 +2,23 @@ echo "$0" "$@" progdir="$(dirname "$0")" cd "$progdir" || exit 1 +PAK_NAME="$(basename "$progdir")" export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$progdir/lib" echo 1 >/tmp/stay_awake -trap "rm -f /tmp/stay_awake" EXIT INT TERM HUP QUIT -BUTTON_LOG="$progdir/log/buttons.log" SERVICE_NAME="screenshot-monitor" HUMAN_READABLE_NAME="Screenshot Monitor" -ONLY_LAUNCH_THEN_EXIT=1 LAUNCHES_SCRIPT="true" -service_on() { - cd "$SDCARD_PATH" || exit 1 - if [ -f "$progdir/log/service.log" ]; then - mv "$progdir/log/service.log" "$progdir/log/service.log.old" - fi - - hotkey="HOTKEY_1" - if [ -f "$progdir/hotkey" ]; then - hotkey="$(cat "$progdir/hotkey")" - fi - - if [ -z "$hotkey" ]; then - hotkey="HOTKEY_1" - fi - if [ "$hotkey" != "HOTKEY_1" ] && [ "$hotkey" != "HOTKEY_2" ]; then - hotkey="HOTKEY_1" - fi - - service_off - - show_message "Enabling the $HUMAN_READABLE_NAME" 2 - PROGDIR="$progdir" HOTKEY="$hotkey" "$progdir/bin/screenshot-monitor" >"$progdir/log/service.log" 2>&1 & - if ! wait_for_service 10; then - show_message "Failed to start $HUMAN_READABLE_NAME" 2 - return 1 - fi - - show_message "Started $HUMAN_READABLE_NAME" 2 -} service_off() { killall "$SERVICE_NAME" } +cleanup() { + rm -f /tmp/stay_awake + killall sdl2imgshow >/dev/null 2>&1 || true +} + show_message() { message="$1" seconds="$2" @@ -53,7 +27,7 @@ show_message() { seconds="forever" fi - killall sdl2imgshow + killall sdl2imgshow >/dev/null 2>&1 || true echo "$message" if [ "$seconds" = "forever" ]; then "$progdir/bin/sdl2imgshow" \ @@ -62,7 +36,7 @@ show_message() { -s 27 \ -c "220,220,220" \ -q \ - -t "$message" & + -t "$message" >/dev/null 2>&1 & else "$progdir/bin/sdl2imgshow" \ -i "$progdir/res/background.png" \ @@ -70,74 +44,32 @@ show_message() { -s 27 \ -c "220,220,220" \ -q \ - -t "$message" + -t "$message" >/dev/null 2>&1 sleep "$seconds" fi } -monitor_buttons() { - if [ -f "$BUTTON_LOG" ]; then - mv "$BUTTON_LOG" "$BUTTON_LOG.old" - fi - touch "$BUTTON_LOG" - - chmod +x "$progdir/bin/evtest" - for dev in /dev/input/event*; do - [ -e "$dev" ] || continue - "$progdir/bin/evtest" "$dev" 2>&1 | while read -r line; do - if echo "$line" | grep -q "code 17 (ABS_HAT0Y).*value -1"; then - echo "D_PAD_UP detected" >>"$BUTTON_LOG" - elif echo "$line" | grep -q "code 17 (ABS_HAT0Y).*value 1"; then - echo "D_PAD_DOWN detected" >>"$BUTTON_LOG" - elif echo "$line" | grep -q "code 16 (ABS_HAT0X).*value 1"; then - echo "D_PAD_RIGHT detected" >>"$BUTTON_LOG" - elif echo "$line" | grep -q "code 16 (ABS_HAT0X).*value -1"; then - echo "D_PAD_LEFT detected" >>"$BUTTON_LOG" - elif echo "$line" | grep -q "code 308 (BTN_WEST).*value 1"; then - echo "BUTTON_X detected" >>"$BUTTON_LOG" - elif echo "$line" | grep -q "code 305 (BTN_EAST).*value 1"; then - echo "BUTTON_A detected" >>"$BUTTON_LOG" - elif echo "$line" | grep -q "code 304 (BTN_SOUTH).*value 1"; then - echo "BUTTON_B detected" >>"$BUTTON_LOG" - elif echo "$line" | grep -q "code 307 (BTN_NORTH).*value 1"; then - echo "BUTTON_Y detected" >>"$BUTTON_LOG" - elif echo "$line" | grep -q "code 317 (BTN_THUMBL).*value 1"; then - echo "HOTKEY_1 detected" >>"$BUTTON_LOG" - elif echo "$line" | grep -q "code 318 (BTN_THUMBR).*value 1"; then - echo "HOTKEY_2 detected" >>"$BUTTON_LOG" - elif echo "$line" | grep -q "code 310 (BTN_TL).*value 1"; then - echo "L1 detected" >>"$BUTTON_LOG" - elif echo "$line" | grep -q "code 311 (BTN_TR).*value 1"; then - echo "R1 detected" >>"$BUTTON_LOG" - elif echo "$line" | grep -q "code 2 (ABS_Z).*value 255"; then - echo "L2 detected" >>"$BUTTON_LOG" - elif echo "$line" | grep -q "code 5 (ABS_RZ).*value 255"; then - echo "R2 detected" >>"$BUTTON_LOG" - elif echo "$line" | grep -q "code 316 (BTN_MODE).*value 1"; then - echo "MENU detected" >>"$BUTTON_LOG" - elif echo "$line" | grep -q "code 314 (BTN_SELECT).*value 1"; then - echo "SELECT detected" >>"$BUTTON_LOG" - elif echo "$line" | grep -q "code 315 (BTN_START).*value 1"; then - echo "START detected" >>"$BUTTON_LOG" - elif echo "$line" | grep -q "code 115 (KEY_VOLUMEUP).*value 1"; then - echo "VOLUME_UP detected" >>"$BUTTON_LOG" - elif echo "$line" | grep -q "code 114 (KEY_VOLUMEDOWN).*value 1"; then - echo "VOLUME_DOWN detected" >>"$BUTTON_LOG" - elif echo "$line" | grep -q "code 116 (KEY_POWER).*value 1"; then - echo "POWER detected" >>"$BUTTON_LOG" - fi - done & - done +disable_start_on_boot() { + sed -i "/${PAK_NAME}-on-boot/d" "$SDCARD_PATH/.userdata/$PLATFORM/auto.sh" + return 0 } -wait_for_button() { - button="$1" - while true; do - if grep -q "$button" "$BUTTON_LOG"; then - break - fi - sleep 0.1 - done +enable_start_on_boot() { + if [ ! -f "$SDCARD_PATH/.userdata/$PLATFORM/auto.sh" ]; then + echo '#!/bin/sh' >"$SDCARD_PATH/.userdata/$PLATFORM/auto.sh" + echo '' >>"$SDCARD_PATH/.userdata/$PLATFORM/auto.sh" + fi + + echo "test -f \"\$SDCARD_PATH/Tools/\$PLATFORM/$PAK_NAME/bin/on-boot\" && \"\$SDCARD_PATH/Tools/\$PLATFORM/$PAK_NAME/bin/on-boot\" # ${PAK_NAME}-on-boot" >>"$SDCARD_PATH/.userdata/$PLATFORM/auto.sh" + chmod +x "$SDCARD_PATH/.userdata/$PLATFORM/auto.sh" + return 0 +} + +will_start_on_boot() { + if grep -q "${PAK_NAME}-on-boot" "$SDCARD_PATH/.userdata/$PLATFORM/auto.sh" >/dev/null 2>&1; then + return 0 + fi + return 1 } is_service_running() { @@ -167,69 +99,139 @@ wait_for_service() { done } -main_daemonize() { - echo "Toggling $SERVICE_NAME..." - if is_service_running; then - show_message "Disabling the $HUMAN_READABLE_NAME" 2 - service_off - else - show_message "Enabling the $HUMAN_READABLE_NAME" 2 - service_on +wait_for_service_to_stop() { + max_counter="$1" + counter=0 - if ! wait_for_service 10; then - show_message "Failed to start $HUMAN_READABLE_NAME" 2 + while is_service_running; do + counter=$((counter + 1)) + if [ "$counter" -gt "$max_counter" ]; then return 1 fi - fi - - show_message "Done" 1 + sleep 1 + done } -main_process() { - if is_service_running; then - show_message "Disabling the $HUMAN_READABLE_NAME" 2 - service_off +main_screen() { + minui_list_file="/tmp/minui-list" + rm -f "$minui_list_file" + touch "$minui_list_file" + + start_on_boot=false + if will_start_on_boot; then + start_on_boot=true fi - show_message "Starting $HUMAN_READABLE_NAME" 2 - service_on - sleep 1 + echo "Enabled: false" >>"$minui_list_file" + echo "Start on boot: $start_on_boot" >>"$minui_list_file" + echo "Enable" >>"$minui_list_file" - echo "Waiting for $HUMAN_READABLE_NAME to be running" - if ! wait_for_service 10; then - show_message "Failed to start $HUMAN_READABLE_NAME" 2 - return 1 + if is_service_running; then + service_pid="$(pgrep "$SERVICE_NAME" 2>/dev/null | sort | head -n 1 || true)" + echo "Enabled: true (pid: $service_pid)" >"$minui_list_file" + echo "Start on boot: $start_on_boot" >>"$minui_list_file" + echo "Disable" >>"$minui_list_file" fi - show_message "Press B to exit" - monitor_buttons + if [ "$start_on_boot" = "true" ]; then + echo "Disable start on boot" >>"$minui_list_file" + else + echo "Enable start on boot" >>"$minui_list_file" + fi - wait_for_button "BUTTON_B" - show_message "Stopping $HUMAN_READABLE_NAME" - service_off - killall evtest - sync - sleep 1 - show_message "Done" 1 + killall sdl2imgshow >/dev/null 2>&1 || true + "$progdir/bin/minui-list-$PLATFORM" --file "$minui_list_file" --format text --header "$HUMAN_READABLE_NAME Configuration" } main() { - if [ "$ONLY_LAUNCH_THEN_EXIT" -eq 1 ]; then - service_on - return $? + trap "cleanup" EXIT INT TERM HUP QUIT + + if [ "$PLATFORM" = "tg3040" ] && [ -z "$DEVICE" ]; then + export DEVICE="brick" + export PLATFORM="tg5040" fi - if [ -f "$progdir/daemon-mode" ]; then - main_daemonize - else - main_process + allowed_platforms="tg5040 rg35xxplus" + if ! echo "$allowed_platforms" | grep -q "$PLATFORM"; then + show_message "$PLATFORM is not a supported platform" 2 + exit 1 + fi + + if [ ! -f "$progdir/bin/minui-keyboard-$PLATFORM" ]; then + show_message "$progdir/bin/minui-keyboard-$PLATFORM not found" 2 + exit 1 + fi + if [ ! -f "$progdir/bin/minui-list-$PLATFORM" ]; then + show_message "$progdir/bin/minui-list-$PLATFORM not found" 2 + exit 1 + fi + + if ! cd "$progdir/bin"; then + show_message "Failed to cd to $progdir/bin" 2 + exit 1 + fi + chmod +x * + if ! cd "$progdir"; then + show_message "Failed to cd to $progdir" 2 + exit 1 + fi + + if [ "$PLATFORM" = "rg35xxplus" ]; then + RGXX_MODEL="$(strings /mnt/vendor/bin/dmenu.bin | grep ^RG)" + if [ "$RGXX_MODEL" = "RG28xx" ]; then + show_message "Wifi not supported on RG28XX" 2 + exit 1 + fi fi - killall sdl2imgshow + + while true; do + sync + selection="$(main_screen)" + exit_code=$? + # exit codes: 2 = back button, 3 = menu button + if [ "$exit_code" -ne 0 ]; then + break + fi + + if echo "$selection" | grep -q "^Enable$"; then + show_message "Enabling $HUMAN_READABLE_NAME..." 1 + if ! "$progdir/bin/service-on"; then + show_message "Failed to enable $HUMAN_READABLE_NAME!" 2 + continue + fi + + show_message "Waiting for $HUMAN_READABLE_NAME to be running" forever + if ! wait_for_service 10; then + show_message "Failed to start $HUMAN_READABLE_NAME" 2 + fi + elif echo "$selection" | grep -q "^Disable$"; then + show_message "Disabling $HUMAN_READABLE_NAME..." 1 + if ! service_off; then + show_message "Failed to disable $HUMAN_READABLE_NAME!" 2 + fi + + show_message "Waiting for $HUMAN_READABLE_NAME to stop" forever + if ! wait_for_service_to_stop 10; then + show_message "Failed to stop $HUMAN_READABLE_NAME" 2 + fi + elif echo "$selection" | grep -q "^Enable start on boot$"; then + show_message "Enabling start on boot..." 1 + if ! enable_start_on_boot; then + show_message "Failed to enable start on boot!" 2 + fi + elif echo "$selection" | grep -q "^Disable start on boot$"; then + show_message "Disabling start on boot..." 1 + if ! disable_start_on_boot; then + show_message "Failed to disable start on boot!" 2 + fi + fi + done + sync } -mkdir -p "$progdir/log" -if [ -f "$progdir/log/launch.log" ]; then - mv "$progdir/log/launch.log" "$progdir/log/launch.log.old" +mkdir -p "$LOGS_PATH" +if [ -f "$LOGS_PATH/$PAK_NAME.txt" ]; then + mv "$LOGS_PATH/$PAK_NAME.txt" "$LOGS_PATH/$PAK_NAME.txt.old" fi -main "$@" >"$progdir/log/launch.log" 2>&1 +main "$@" >"$LOGS_PATH/$PAK_NAME.txt" 2>&1