Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ res/fonts/*
!bin/screenshot
!bin/arm/screenshot-monitor
!bin/arm64/screenshot-monitor
!bin/service-on
!bin/on-boot
!bin/service-is-running
!bin/service-off
!bin/service-on
25 changes: 25 additions & 0 deletions bin/service-is-running
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh
BIN_DIR="$(dirname "$0")"
PAK_DIR="$(dirname "$BIN_DIR")"
PAK_NAME="$(basename "$PAK_DIR")"
PAK_NAME="${PAK_NAME%.*}"
set -x

SERVICE_NAME="screenshot-monitor"
LAUNCHES_SCRIPT="true"

main() {
if pgrep "$SERVICE_NAME" >/dev/null 2>&1; then
return 0
fi

if [ "$LAUNCHES_SCRIPT" = "true" ]; then
if pgrep -fn "$SERVICE_NAME" >/dev/null 2>&1; then
return 0
fi
fi

return 1
}

main "$@"
13 changes: 13 additions & 0 deletions bin/service-off
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
BIN_DIR="$(dirname "$0")"
PAK_DIR="$(dirname "$BIN_DIR")"
PAK_NAME="$(basename "$PAK_DIR")"
PAK_NAME="${PAK_NAME%.*}"
set -x

echo "$0" "$@"
cd "$PAK_DIR" || exit 1

SERVICE_NAME="screenshot-monitor"

killall "$SERVICE_NAME"
28 changes: 5 additions & 23 deletions launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ LAUNCHES_SCRIPT="true"
NETWORK_PORT=""
NETWORK_SCHEME=""

service_off() {
killall "$SERVICE_NAME"
}

show_message() {
message="$1"
seconds="$2"
Expand Down Expand Up @@ -73,25 +69,11 @@ will_start_on_boot() {
return 1
}

is_service_running() {
if pgrep "$SERVICE_NAME" >/dev/null 2>&1; then
return 0
fi

if [ "$LAUNCHES_SCRIPT" = "true" ]; then
if pgrep -fn "$SERVICE_NAME" >/dev/null 2>&1; then
return 0
fi
fi

return 1
}

wait_for_service() {
max_counter="$1"
counter=0

while ! is_service_running; do
while ! service-is-running; do
counter=$((counter + 1))
if [ "$counter" -gt "$max_counter" ]; then
return 1
Expand All @@ -104,7 +86,7 @@ wait_for_service_to_stop() {
max_counter="$1"
counter=0

while is_service_running; do
while service-is-running; do
counter=$((counter + 1))
if [ "$counter" -gt "$max_counter" ]; then
return 1
Expand Down Expand Up @@ -160,7 +142,7 @@ current_settings() {
rm -f "$minui_list_file"

jq -rM '{settings: .settings}' "$PAK_DIR/settings.json" >"$minui_list_file"
if is_service_running; then
if service-is-running; then
jq '.settings[0].selected = 1' "$minui_list_file" >"$minui_list_file.tmp"
mv "$minui_list_file.tmp" "$minui_list_file"
fi
Expand All @@ -180,7 +162,7 @@ main_screen() {

echo "$settings" >"$minui_list_file"

if is_service_running; then
if service-is-running; then
service_pid="$(get_service_pid)"
jq --arg pid "$service_pid" '.settings[.settings | length] |= . + {"name": "PID", "options": [$pid], "selected": 0, "features": {"unselectable": true}}' "$minui_list_file" >"$minui_list_file.tmp"
mv "$minui_list_file.tmp" "$minui_list_file"
Expand Down Expand Up @@ -277,7 +259,7 @@ main() {
killall minui-presenter >/dev/null 2>&1 || true
else
show_message "Disabling $HUMAN_READABLE_NAME" 2
if ! service_off; then
if ! service-off; then
show_message "Failed to disable $HUMAN_READABLE_NAME!" 2
fi

Expand Down