Release stale Caffeine inhibitors
This commit is contained in:
@@ -10,6 +10,7 @@ action="${1:-}"
|
||||
helper_dir="${PANAMA_ACTION_HELPER_DIR:-$script_dir}"
|
||||
confirm_attempts="${PANAMA_ACTION_CONFIRM_ATTEMPTS:-20}"
|
||||
confirm_delay="${PANAMA_ACTION_CONFIRM_DELAY:-0.1}"
|
||||
kill_command="${PANAMA_ACTION_KILL_COMMAND:-/usr/bin/kill}"
|
||||
|
||||
osd_command=("$helper_dir/panama-osd")
|
||||
gallery_command=("$helper_dir/panama-prism-gallery")
|
||||
@@ -52,6 +53,17 @@ state_is_active() {
|
||||
esac
|
||||
}
|
||||
|
||||
release_caffeine_inhibitors() {
|
||||
local inhibitors pid uid
|
||||
uid="$(id -u)"
|
||||
inhibitors="$(systemd-inhibit --list --no-pager --no-legend 2>/dev/null \
|
||||
| awk -v uid="$uid" '$1 == "Panama" && $2 == uid && $(NF - 1) == "Caffeine" && $NF == "block" { print $4 }')"
|
||||
while IFS= read -r pid; do
|
||||
[[ $pid =~ ^[0-9]+$ ]] || continue
|
||||
"$kill_command" "$pid" 2>/dev/null || true
|
||||
done <<<"$inhibitors"
|
||||
}
|
||||
|
||||
wait_for_confirmed_state() {
|
||||
local target="$1" expected="$2" attempt
|
||||
for ((attempt = 0; attempt < confirm_attempts; attempt++)); do
|
||||
@@ -71,6 +83,9 @@ toggle_state() {
|
||||
local target="$1" on_icon="$2" off_icon="$3" label="$4" state
|
||||
state="$(qs ipc call "$target" toggle)"
|
||||
case "$state" in true|false) ;; *) show_state "$state" "$on_icon" "$off_icon" "$label"; return ;; esac
|
||||
if [[ $target == caffeine && $state == false ]]; then
|
||||
release_caffeine_inhibitors
|
||||
fi
|
||||
wait_for_confirmed_state "$target" "$state"
|
||||
show_state "$state" "$on_icon" "$off_icon" "$label"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user