diff --git a/morning-alarm.sh b/morning-alarm.sh index 7e3de18..2d787a0 100755 --- a/morning-alarm.sh +++ b/morning-alarm.sh @@ -6,7 +6,12 @@ # It turns off Bluetooth, increases the volume, and checks if the alarm has been dismissed. # After the alarm is dismissed, it plays the alarm sound. -echo "Script executed at: $(date)" > /data/scripts/morning-alarm.log +# clear logs +rm -rf /data/scripts/morning-alarm.log +echo "Script executed at: $(date)" + +# Set a flag for the loop +alarm_dismissed=false # Function to turn off Bluetooth turn_off_bluetooth() { @@ -23,18 +28,18 @@ increase_volume() { # Function to check the alarm notification check_notification() { # Run the dumpsys command within a timeout - output=$(timeout 5s dumpsys activity processes | grep "com.urbandroid.sleep/") + output=$(dumpsys activity processes | grep "com.urbandroid.sleep") # Check if the result is not empty and contains the alarm if [ -n "$output" ] && echo "$output" | grep -q "AlarmKlaxon"; then date && echo "Alarm not dismissed yet." + sleep 5 + return 1 else date && echo "Alarm dismissed." - killall mpv - break - #killall /data/data/com.termux/files/usr/bin/mpv - echo "$output" - exit + alarm_dismissed=true + /system/bin/pkill play.sh + /system/bin/pkill mpv fi } @@ -43,16 +48,20 @@ check_notification() { # Turn off Bluetooth turn_off_bluetooth -# Increase volume and check notification +# start play.sh script +/data/scripts/play.sh & + +# Repeat the check_notification function while true; do increase_volume + sleep 2 check_notification -done & -## Play alarm sound -for ((volume = 20; volume <= 100; volume += 10)); do - echo "Actual volume: $volume" - /data/data/com.termux/files/usr/bin/mpv --replaygain=track --volume="$volume" /data/scripts/your-new-morning-alarm.ogg - #check_notification & + # Check if the alarm dismissed flag is set + if [ "$alarm_dismissed" = true ]; then + /system/bin/pkill play.sh + /system/bin/pkill mpv + exit 0 # Exit the script here + fi done