From 4e4a070483168f6e43a7137bddbafd9b63c16d00 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 8 Feb 2025 12:46:02 -0500 Subject: [PATCH] chore: copy launch.sh skeleton from other paks --- launch.sh | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/launch.sh b/launch.sh index 9152600..a471de3 100644 --- a/launch.sh +++ b/launch.sh @@ -10,6 +10,8 @@ echo 1 >/tmp/stay_awake SERVICE_NAME="screenshot-monitor" HUMAN_READABLE_NAME="Screenshot Monitor" LAUNCHES_SCRIPT="true" +NETWORK_PORT="" +NETWORK_SCHEME="" service_off() { killall "$SERVICE_NAME" @@ -113,6 +115,40 @@ wait_for_service_to_stop() { done } +get_ip_address() { + if [ -z "$NETWORK_PORT" ]; then + return + fi + + enabled="$(cat /sys/class/net/wlan0/operstate)" + if [ "$enabled" != "up" ]; then + echo "Not connected to WiFi" + return + fi + ip_address="" + + count=0 + while true; do + count=$((count + 1)) + if [ "$count" -gt 5 ]; then + break + fi + + ip_address="$(ip addr show wlan0 | grep 'inet ' | awk '{print $2}' | cut -d'/' -f1)" + if [ -n "$ip_address" ]; then + break + fi + sleep 1 + done + + if [ -z "$ip_address" ]; then + echo "Not connected to WiFi" + return + fi + + echo "$NETWORK_SCHEME://$ip_address:$NETWORK_PORT" +} + main_screen() { minui_list_file="/tmp/minui-list" rm -f "$minui_list_file" @@ -129,8 +165,12 @@ main_screen() { if is_service_running; then service_pid="$(pgrep "$SERVICE_NAME" 2>/dev/null | sort | head -n 1 || true)" + ip_address="$(get_ip_address)" echo "Enabled: true (pid: $service_pid)" >"$minui_list_file" echo "Start on boot: $start_on_boot" >>"$minui_list_file" + if [ -n "$ip_address" ]; then + echo "Address: $ip_address" >>"$minui_list_file" + fi echo "Disable" >>"$minui_list_file" fi @@ -141,7 +181,7 @@ main_screen() { fi killall sdl2imgshow >/dev/null 2>&1 || true - "$progdir/bin/minui-list-$PLATFORM" --file "$minui_list_file" --format text --header "$HUMAN_READABLE_NAME Configuration" + "$progdir/bin/minui-list-$PLATFORM" --file "$minui_list_file" --format text --header "$HUMAN_READABLE_NAME" } main() {