Skip to content
Merged
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
42 changes: 41 additions & 1 deletion launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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

Expand All @@ -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() {
Expand Down
Loading