refactor screenshot, feat: option to disable notifications

This commit is contained in:
thek4n 2025-05-21 18:58:56 +03:00
parent 9081fef1ff
commit ff3d5064b8

View File

@ -3,42 +3,51 @@
set -euo pipefail set -euo pipefail
readonly LOG_FILE="${HOME}/.screenshots.log" readonly LOG_FILE="${HOME}/.screenshots.log"
readonly NOTIFY_TIME_MS=3000 readonly NOTIFY_TIME_LOW_MS=1500
readonly NOTIFY_TIME_ERROR_MS=5000 readonly NOTIFY_TIME_NORMAL_MS=3000
readonly NOTIFY_TIME_CRITICAL_MS=5000
readonly CODE_CANCELED=22 readonly CODE_CANCELED=22
readonly NOTIFY_LABEL="Screenshot" readonly NOTIFY_LABEL="Screenshot"
readonly SCREENSHOTS_DIR="${SCREENSHOTS_DIR:-${HOME}/Pictures/screenshots}" readonly SCREENSHOTS_DIR="${SCREENSHOTS_DIR:-${HOME}/Pictures/screenshots}"
readonly TIMESTAMP_FORMAT="%H-%M-%S_%Y-%m-%d" readonly TIMESTAMP_FORMAT="%H-%M-%S_%Y-%m-%d"
readonly NOOPENGL="${NOOPENGL:-false}" readonly NOOPENGL="${NOOPENGL:-}"
readonly NONOTIFY="${NONOTIFY:-}"
mkdir -p "${SCREENSHOTS_DIR}" mkdir -p "${SCREENSHOTS_DIR}"
_notify() { _notify() {
notify-send --urgency normal \ local -r level="${1}"
--expire-time "${NOTIFY_TIME_MS}" \ local -r notify_time_ms="${2}"
local -r msg="${3}"
if [ -n "${NONOTIFY}" ]; then
return 0
fi
notify-send --urgency "${level}" \
--expire-time "${notify_time_ms}" \
"${NOTIFY_LABEL}" \ "${NOTIFY_LABEL}" \
"${1}" "${msg}"
} }
_notify_low() { _notify_low() {
notify-send --urgency low \ _notify low "${NOTIFY_TIME_LOW_MS}" "${1}"
--expire-time "${NOTIFY_TIME_MS}" \
"${NOTIFY_LABEL}" \
"${1}"
} }
_notify_normal() {
_notify normal "${NOTIFY_TIME_NORMAL_MS}" "${1}"
}
_notify_error() { _notify_error() {
notify-send --urgency critical \ _notify critical "${NOTIFY_TIME_CRITICAL_MS}" "Error: ${1}"
--expire-time "${NOTIFY_TIME_ERROR_MS}" \
"${NOTIFY_LABEL}" \
"Error: ${1}"
} }
_maim() { _maim() {
local maim_args=(--quality 10) local maim_args=(--quality 10)
if ${NOOPENGL}; then if [ -n "${NOOPENGL}" ]; then
maim_args+=--noopengl maim_args+=--noopengl
fi fi
@ -90,7 +99,7 @@ _process_screenshot() {
return 1 return 1
fi fi
_notify "${success_msg}" _notify_normal "${success_msg}"
return 0 return 0
} }