diff --git a/src/giph b/src/giph index b4852cc..a9cde0b 100755 --- a/src/giph +++ b/src/giph @@ -17,6 +17,8 @@ MICROPHONE=0 MICROPHONE_SOURCE=default FORMAT_OVERWRITE="" +LAST_NOTIFICATION_ID=0 + function print_version() { echo "$VERSION" exit 0 @@ -79,7 +81,7 @@ function log() { } function log_error() { - notify "$1" "critical" + notify "$1" log "\033[0;31mERROR:\033[0m $1" -1 "${2:-true}" true } @@ -88,7 +90,7 @@ function log_warning() { } function log_success() { - notify "$1" "normal" + notify "$1" log "\033[0;32mSUCCESS:\033[0m $1" 0 "${2:-true}" } @@ -96,12 +98,27 @@ function log_info() { log "\033[0;36mINFO:\033[0m $1" 0 "${2:-true}" } +# send a notification - (message:string, durationms:int) function notify() { [ "$NOTIFY" = 1 ] && { - notify=(notify-send -t 3000) - notify+=(-u "$2") - notify+=("giph" "$1") - "${notify[@]}" + LAST_NOTIFICATION_ID=$(gdbus call \ + --session \ + --dest=org.freedesktop.Notifications \ + --object-path=/org/freedesktop/Notifications \ + --method=org.freedesktop.Notifications.Notify \ + "giph" "$LAST_NOTIFICATION_ID" "" "giph" "$1" \ + '[]' '{"urgency": <1>}' "${3:-5000}" | sed -E 's/^.* ([0-9]+).*$/\1/') + } +} + +function close_last_notification() { + [ "$NOTIFY" = 1 ] && { + gdbus call \ + --session \ + --dest org.freedesktop.Notifications \ + --object-path /org/freedesktop/Notifications \ + --method org.freedesktop.Notifications.CloseNotification "$LAST_NOTIFICATION_ID" + LAST_NOTIFICATION_ID=0 } } @@ -373,7 +390,7 @@ function record() { ;; esac - [ -n "$DELAY" ] && [ "$DELAY" -gt 0 ] && countdown_cli "$DELAY" "recording starts in" + [ -n "$DELAY" ] && [ "$DELAY" -gt 0 ] && countdown "$DELAY" "recording starts in" ffmpeg_command="${ffmpeg[*]}" log "ffmpeg command: '$ffmpeg_command'" 2 true @@ -384,7 +401,7 @@ function record() { log "started recording video with ffmpeg" 1 true if [ -n "$TIMER" ] && [ "$TIMER" -gt 0 ]; then - countdown_cli "$TIMER" "recording stops in" + countdown "$TIMER" "recording stops in" else stop_recording_handler_cli fi @@ -395,14 +412,16 @@ function record() { log "completed ffmpeg video recording" 1 true } -function countdown_cli() { +function countdown() { seconds="$1" while [ "$seconds" -ge 0 ]; do log "\r\033[K\033[0;36m$2:\033[0m $seconds" 0 false false true + notify "$2 $seconds" 2000 if [ "$seconds" -gt 0 ]; then sleep 1 else log "\r\033[K" 0 false false true + close_last_notification fi : "$((seconds--))" done