From 397d0e85771b20b479f4cad84e717b4511d5b3a7 Mon Sep 17 00:00:00 2001 From: Ben Wadsworth Date: Thu, 8 May 2025 15:00:52 +0100 Subject: [PATCH 1/8] feat: start stop game tracker --- bin/shutdown | 1 + bin/suspend | 2 ++ 2 files changed, 3 insertions(+) diff --git a/bin/shutdown b/bin/shutdown index a502828..aa98133 100755 --- a/bin/shutdown +++ b/bin/shutdown @@ -27,6 +27,7 @@ show_message() { shutdown_system() { show_message "Powering off" forever + tracker stop sync poweroff while :; do diff --git a/bin/suspend b/bin/suspend index 3fd7b75..e794bf8 100755 --- a/bin/suspend +++ b/bin/suspend @@ -22,6 +22,7 @@ suspend_system() { if [ -n "$PID" ]; then echo "Suspending emulator process with PID: $PID" + tracker stop kill -STOP "$PID" || true fi @@ -29,6 +30,7 @@ suspend_system() { if [ -n "$PID" ]; then echo "Resuming emulator process with PID: $PID" + tracker start kill -CONT "$PID" || true fi } From b1e72b38f28a443e63ccd6544143b81717151b4f Mon Sep 17 00:00:00 2001 From: Ben Wadsworth Date: Thu, 8 May 2025 15:02:13 +0100 Subject: [PATCH 2/8] feat: add tracker script --- .gitignore | 3 ++- bin/tracker | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 bin/tracker diff --git a/.gitignore b/.gitignore index b74dd2f..41d026f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ makeself* !bin/suspend !bin/shutdown -!bin/launch \ No newline at end of file +!bin/launch +!bin/tracker diff --git a/bin/tracker b/bin/tracker new file mode 100644 index 0000000..0f3a434 --- /dev/null +++ b/bin/tracker @@ -0,0 +1,48 @@ +#!/bin/sh + +print_usage() { + echo "Usage: $0 start|stop" + exit 1 +} + +main() { + if [ "$#" -lt 1 ] || [ "$#" -gt 1 ]; then + print_usage + fi + + if [ ! -f /tmp/powercontrol-rom-path ]; then + echo "ROM path file not found. Unable to start or stop the tracker for the emulator." + exit + fi + + if [ ! -f /usr/bin/gametimectl.elf ]; then + echo "gametimectl.elf not found. Unable to start or stop the tracker for the emulator." + exit + fi + + ACTION="$1" + ROM_PATH=$(cat /tmp/powercontrol-rom-path) + + if [ ! -f "$ROM_PATH" ]; then + echo "Invalid ROM path: $ROM_PATH" + exit 1 + fi + + case "$ACTION" in + start) + if [ -n "$ROM_PATH" ]; then + gametimectl.elf start "$ROM_PATH" + fi + ;; + stop) + if [ -n "$ROM_PATH" ]; then + gametimectl.elf stop "$ROM_PATH" + fi + ;; + *) + print_usage + ;; + esac +} + +main "$@" \ No newline at end of file From a01baf381efb09ca5d3b5995ccf3574b46315c80 Mon Sep 17 00:00:00 2001 From: Ben Wadsworth Date: Thu, 8 May 2025 15:15:00 +0100 Subject: [PATCH 3/8] fix: update tracker script --- bin/tracker | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/tracker b/bin/tracker index 0f3a434..3a76315 100644 --- a/bin/tracker +++ b/bin/tracker @@ -1,5 +1,7 @@ #!/bin/sh +TRACKER_PATH="$SDCARD_PATH/Tools/$PLATFORM/Game Tracker.pak/gametimectl.elf" + print_usage() { echo "Usage: $0 start|stop" exit 1 @@ -15,8 +17,8 @@ main() { exit fi - if [ ! -f /usr/bin/gametimectl.elf ]; then - echo "gametimectl.elf not found. Unable to start or stop the tracker for the emulator." + if [ ! -f "$TRACKER_PATH" ]; then + echo "Game tracker $TRACKER_PATH not found. Unable to start or stop the tracker for the emulator." exit fi @@ -31,12 +33,12 @@ main() { case "$ACTION" in start) if [ -n "$ROM_PATH" ]; then - gametimectl.elf start "$ROM_PATH" + "$TRACKER_PATH" start "$ROM_PATH" fi ;; stop) if [ -n "$ROM_PATH" ]; then - gametimectl.elf stop "$ROM_PATH" + "$TRACKER_PATH" stop "$ROM_PATH" fi ;; *) From ff6ae8654948a75bed0231903d6bad19c7503b37 Mon Sep 17 00:00:00 2001 From: Ben Wadsworth Date: Thu, 8 May 2025 15:30:33 +0100 Subject: [PATCH 4/8] feat: update command-line options and readme --- README.md | 30 ++++++++++++++++++++++----- bin/launch | 61 +++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 79 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 9692613..3d52b26 100644 --- a/README.md +++ b/README.md @@ -34,18 +34,38 @@ Currently, the app supports the following features: ## Usage ```bash -minui-power-control & +minui-power-control [OPTIONS] ``` -Before starting `minui-power-control`, make sure the emulator is already running. Replace `` with the actual name of the emulator’s binary. The app will run in the background, watching for power button events and carrying out the actions. Once the emulator closes, the app will automatically exit as well. To make things more convenient and reliable, it’s best to start the app in the emulator’s `launch.sh` script, placing it before the emulator command. This makes sure it launches alongside the emulator, removing the need to start it manually. +**Options:** -Alternatively, it is possible to run `minui-power-control` without specifying an emulator: +- `-e`, `--emulator ` Specify the emulator binary to monitor. +- `-r`, `--rom ` Specify the ROM path. +- `-h`, `--help` Show help message and exit. + +If no emulator binary is specified, a dummy PID file will be created at `/tmp/powercontrol-dummy-pid` and the app will continue running until that file is deleted. This is useful for testing or for scenarios where the name of the emulator is not known in advance. + +**How to use:** + +Before starting `minui-power-control`, make sure the emulator is already running. Use the `-e` or `--emulator` option to specify the emulator’s binary. The app will run in the background, watching for power button events and carrying out the actions. Once the emulator closes, the app will automatically exit as well. To make things more convenient and reliable, it’s best to start the app in the emulator’s `launch.sh` script, placing it before the emulator command. This ensures it launches alongside the emulator, removing the need to start it manually. + +Example: ```bash -minui-power-control & +minui-power-control -e & ``` -In this mode, the app creates a file at `/tmp/powercontrol-dummy-pid` and will continue running until that file is deleted. This is useful for testing or for scenarios where the name of the emulator is not known in advance. +You can also specify the ROM path if needed: + +```bash +minui-power-control -e -r & +``` + +To see all available options, run: + +```bash +minui-power-control --help +``` ## Building diff --git a/bin/launch b/bin/launch index 3c62804..f546b75 100755 --- a/bin/launch +++ b/bin/launch @@ -9,8 +9,16 @@ fi export PATH="$BIN_DIR/$architecture:$BIN_DIR/$PLATFORM:$BIN_DIR:$PATH" print_usage() { - echo "Usage: $0 " + echo "Usage: $0 [OPTIONS]" + echo "" + echo "Options:" + echo " -e, --emulator Specify the emulator binary to monitor." + echo " -r, --rom Specify the ROM path." + #echo " -s, --save-key Specify the save key." + echo " -h, --help Show this help message and exit." + echo "" echo "If no emulator binary is specified, a dummy PID file will be created." + exit 1 } cleanup() { @@ -72,11 +80,48 @@ main() { chmod +x "$BIN_DIR/shutdown" chmod +x "$BIN_DIR/suspend" - if [ "$#" -eq 0 ]; then - echo "Emulator process not specified. Creating a dummy PID file." - touch /tmp/powercontrol-dummy-pid - elif [ "$#" -eq 1 ]; then - EMULATOR_BIN="$1" + EMULATOR_BIN="" + ROM_PATH="" + #SAVE_KEY="" + + while [ $# -gt 0 ]; do + case "$1" in + -e|--emulator) + EMULATOR_BIN="$2" + shift 2 + ;; + -r|--rom) + ROM_PATH="$2" + shift 2 + ;; + # -s|--save-key) + # SAVE_KEY="$2" + # shift 2 + # ;; + -h|--help) + print_usage + ;; + --) + shift + break + ;; + -*) + echo "Unknown option: $1" + print_usage + ;; + *) + # Positional argument (fallback) + break + ;; + esac + done + + if [ -n "$ROM_PATH" ]; then + echo "$ROM_PATH" > /tmp/powercontrol-rom-path + echo "ROM path: $ROM_PATH" + fi + + if [ -n "$EMULATOR_BIN" ]; then EMULATOR_PROCESS_PID="" for _ in $(seq 1 10); do @@ -96,9 +141,11 @@ main() { echo "$EMULATOR_PROCESS_PID" > /tmp/powercontrol-emulator-pid echo "Emulator PID: $EMULATOR_PROCESS_PID" else - print_usage + echo "Creating dummy PID file..." + touch /tmp/powercontrol-dummy-pid fi + echo "Starting button-handler..." button-handler & HANDLER_PROCESS_PID=$! From 696e19c42786cc28c03abe4efe6dd4f931567ac3 Mon Sep 17 00:00:00 2001 From: Ben Wadsworth Date: Thu, 8 May 2025 16:13:31 +0100 Subject: [PATCH 5/8] feat: add tracker script checks --- bin/shutdown | 6 ++++++ bin/suspend | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/bin/shutdown b/bin/shutdown index 3f6d0f8..cf741c7 100755 --- a/bin/shutdown +++ b/bin/shutdown @@ -37,6 +37,12 @@ shutdown_system() { } main() { + if [ ! -f "$BIN_DIR/tracker" ]; then + echo "tracker script not found." + exit 1 + fi + chmod +x "$BIN_DIR/tracker" + if [ -f /tmp/powercontrol-emulator-pid ]; then PROCESS_PID=$(cat /tmp/emulator_pid) echo "Emulator PID file found. Killing the emulator process with PID: $PROCESS_PID" diff --git a/bin/suspend b/bin/suspend index ee12467..673413f 100755 --- a/bin/suspend +++ b/bin/suspend @@ -50,15 +50,23 @@ fallback_suspend() { if [ ! -f /tmp/powercontrol-suspend-active ]; then echo "Pausing emulator process with PID: $PID" kill -STOP "$PID" || true + tracker stop touch /tmp/powercontrol-suspend-active else echo "Resuming emulator process with PID: $PID" kill -CONT "$PID" || true + tracker start rm -f /tmp/powercontrol-suspend-active fi } main() { + if [ ! -f "$BIN_DIR/tracker" ]; then + echo "tracker script not found." + exit 1 + fi + chmod +x "$BIN_DIR/tracker" + if [ -f /tmp/powercontrol-emulator-pid ]; then PROCESS_PID=$(cat /tmp/emulator_pid) echo "Emulator PID file found. Killing the emulator process with PID: $PROCESS_PID" From 5cd814258cae2601290826158082853fc37c3b9b Mon Sep 17 00:00:00 2001 From: Ben Wadsworth Date: Thu, 8 May 2025 16:17:28 +0100 Subject: [PATCH 6/8] fix: clean up additional temporary files --- bin/launch | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/launch b/bin/launch index f546b75..dcdef5f 100755 --- a/bin/launch +++ b/bin/launch @@ -30,6 +30,8 @@ cleanup() { fi rm -f /tmp/powercontrol-emulator-pid rm -f /tmp/powercontrol-dummy-pid + rm -f /tmp/powercontrol-rom-path + rm -f /tmp/powercontrol-suspend-active } main() { From 9b16f3d482f2a80d47859627c2ea56602fb7db2e Mon Sep 17 00:00:00 2001 From: Ben Wadsworth Date: Fri, 9 May 2025 13:01:23 +0100 Subject: [PATCH 7/8] fix: fixes --- bin/shutdown | 2 +- bin/suspend | 2 +- src/button-handler.go | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/bin/shutdown b/bin/shutdown index cf741c7..b389369 100755 --- a/bin/shutdown +++ b/bin/shutdown @@ -44,7 +44,7 @@ main() { chmod +x "$BIN_DIR/tracker" if [ -f /tmp/powercontrol-emulator-pid ]; then - PROCESS_PID=$(cat /tmp/emulator_pid) + PROCESS_PID=$(cat /tmp/powercontrol-emulator-pid) echo "Emulator PID file found. Killing the emulator process with PID: $PROCESS_PID" if [ -z "$PROCESS_PID" ] || ! kill -0 "$PROCESS_PID" 2>/dev/null; then diff --git a/bin/suspend b/bin/suspend index 673413f..dcb753e 100755 --- a/bin/suspend +++ b/bin/suspend @@ -68,7 +68,7 @@ main() { chmod +x "$BIN_DIR/tracker" if [ -f /tmp/powercontrol-emulator-pid ]; then - PROCESS_PID=$(cat /tmp/emulator_pid) + PROCESS_PID=$(cat /tmp/powercontrol-emulator-pid) echo "Emulator PID file found. Killing the emulator process with PID: $PROCESS_PID" if [ -z "$PROCESS_PID" ] || ! kill -0 "$PROCESS_PID" 2>/dev/null; then diff --git a/src/button-handler.go b/src/button-handler.go index bdd11b4..505f06b 100644 --- a/src/button-handler.go +++ b/src/button-handler.go @@ -74,7 +74,11 @@ func main() { func runScript(scriptPath string) { cmd := exec.Command(scriptPath) - if err := cmd.Run(); err != nil { + output, err := cmd.CombinedOutput() + if err != nil { log.Printf("Failed to run %s script: %v", scriptPath, err) } + if len(output) > 0 { + log.Printf("%s", output) + } } From d98225b8c8782f77ef1af49c83da636561b38b8f Mon Sep 17 00:00:00 2001 From: Ben Wadsworth Date: Fri, 9 May 2025 15:54:31 +0100 Subject: [PATCH 8/8] fix: lots more fixes --- .gitignore | 2 +- bin/{tracker => game-tracker} | 15 ++++++--------- bin/launch | 16 ++++++++++------ bin/shutdown | 8 ++------ bin/suspend | 18 +++++++----------- src/button-handler.go | 4 ++-- 6 files changed, 28 insertions(+), 35 deletions(-) rename bin/{tracker => game-tracker} (70%) diff --git a/.gitignore b/.gitignore index 41d026f..b0b6d92 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ makeself* !bin/suspend !bin/shutdown !bin/launch -!bin/tracker +!bin/game-tracker diff --git a/bin/tracker b/bin/game-tracker similarity index 70% rename from bin/tracker rename to bin/game-tracker index 3a76315..52ba306 100644 --- a/bin/tracker +++ b/bin/game-tracker @@ -2,23 +2,19 @@ TRACKER_PATH="$SDCARD_PATH/Tools/$PLATFORM/Game Tracker.pak/gametimectl.elf" -print_usage() { - echo "Usage: $0 start|stop" - exit 1 -} - main() { if [ "$#" -lt 1 ] || [ "$#" -gt 1 ]; then - print_usage + echo "Invalid number of arguments. Usage: $0 " + exit 1 fi if [ ! -f /tmp/powercontrol-rom-path ]; then - echo "ROM path file not found. Unable to start or stop the tracker for the emulator." + echo "ROM path file not found. Unable to $1 the Game Tracker." exit fi if [ ! -f "$TRACKER_PATH" ]; then - echo "Game tracker $TRACKER_PATH not found. Unable to start or stop the tracker for the emulator." + echo "Game tracker $TRACKER_PATH not found. Unable to $1 the Game Tracker." exit fi @@ -42,7 +38,8 @@ main() { fi ;; *) - print_usage + echo "Unknown action: $ACTION. Use 'start' or 'stop'." + exit 1 ;; esac } diff --git a/bin/launch b/bin/launch index dcdef5f..007b12c 100755 --- a/bin/launch +++ b/bin/launch @@ -77,10 +77,17 @@ main() { exit 1 fi + if [ ! -f "$BIN_DIR/game-tracker" ]; then + echo "game-tracker script not found." + exit 1 + fi + + chmod +x "$BIN_DIR/$PLATFORM/minui-presenter" chmod +x "$BIN_DIR/$architecture/button-handler" chmod +x "$BIN_DIR/shutdown" chmod +x "$BIN_DIR/suspend" + chmod +x "$BIN_DIR/game-tracker" EMULATOR_BIN="" ROM_PATH="" @@ -103,17 +110,14 @@ main() { -h|--help) print_usage ;; - --) - shift - break - ;; -*) echo "Unknown option: $1" print_usage ;; *) - # Positional argument (fallback) - break + # Treat positional argument as -e (emulator binary) + EMULATOR_BIN="$1" + shift ;; esac done diff --git a/bin/shutdown b/bin/shutdown index b389369..7698bfc 100755 --- a/bin/shutdown +++ b/bin/shutdown @@ -28,7 +28,7 @@ show_message() { shutdown_system() { echo "Shutting down system..." show_message "Powering off" forever - tracker stop + game-tracker stop sync poweroff while :; do @@ -37,11 +37,7 @@ shutdown_system() { } main() { - if [ ! -f "$BIN_DIR/tracker" ]; then - echo "tracker script not found." - exit 1 - fi - chmod +x "$BIN_DIR/tracker" + echo "Starting shutdown script..." if [ -f /tmp/powercontrol-emulator-pid ]; then PROCESS_PID=$(cat /tmp/powercontrol-emulator-pid) diff --git a/bin/suspend b/bin/suspend index dcb753e..a8eafc1 100755 --- a/bin/suspend +++ b/bin/suspend @@ -25,7 +25,7 @@ suspend_system() { if [ -n "$PID" ]; then echo "Suspending emulator process with PID: $PID" - tracker stop + game-tracker stop kill -STOP "$PID" || true fi @@ -33,14 +33,14 @@ suspend_system() { if [ -n "$PID" ]; then echo "Resuming emulator process with PID: $PID" - tracker start + game-tracker start kill -CONT "$PID" || true fi } fallback_suspend() { PID="$1" - echo "Fallback suspend for emulator process with PID: $PID" + echo "Using fallback suspend method..." if [ -z "$PID" ]; then echo "No PID provided for fallback suspend." @@ -50,26 +50,22 @@ fallback_suspend() { if [ ! -f /tmp/powercontrol-suspend-active ]; then echo "Pausing emulator process with PID: $PID" kill -STOP "$PID" || true - tracker stop + game-tracker stop touch /tmp/powercontrol-suspend-active else echo "Resuming emulator process with PID: $PID" kill -CONT "$PID" || true - tracker start + game-tracker start rm -f /tmp/powercontrol-suspend-active fi } main() { - if [ ! -f "$BIN_DIR/tracker" ]; then - echo "tracker script not found." - exit 1 - fi - chmod +x "$BIN_DIR/tracker" + echo "Starting suspend script..." if [ -f /tmp/powercontrol-emulator-pid ]; then PROCESS_PID=$(cat /tmp/powercontrol-emulator-pid) - echo "Emulator PID file found. Killing the emulator process with PID: $PROCESS_PID" + echo "Emulator PID file found with PID: $PROCESS_PID" if [ -z "$PROCESS_PID" ] || ! kill -0 "$PROCESS_PID" 2>/dev/null; then echo "Emulator process $PROCESS_PID not found." diff --git a/src/button-handler.go b/src/button-handler.go index 505f06b..59b9c7b 100644 --- a/src/button-handler.go +++ b/src/button-handler.go @@ -76,9 +76,9 @@ func runScript(scriptPath string) { cmd := exec.Command(scriptPath) output, err := cmd.CombinedOutput() if err != nil { - log.Printf("Failed to run %s script: %v", scriptPath, err) + log.Printf("Failed to run %s script:\n%v", scriptPath, err) } if len(output) > 0 { - log.Printf("%s", output) + log.Printf("Script %s executed successfully:\n%s", scriptPath, output) } }