Harden Panama launcher actions
This commit is contained in:
@@ -7,18 +7,12 @@ set -euo pipefail
|
||||
|
||||
script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
||||
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}"
|
||||
|
||||
if command -v panama-osd >/dev/null 2>&1; then
|
||||
osd_command=(panama-osd)
|
||||
else
|
||||
osd_command=("$script_dir/panama-osd")
|
||||
fi
|
||||
|
||||
if command -v panama-prism-gallery >/dev/null 2>&1; then
|
||||
gallery_command=(panama-prism-gallery)
|
||||
else
|
||||
gallery_command=("$script_dir/panama-prism-gallery")
|
||||
fi
|
||||
osd_command=("$helper_dir/panama-osd")
|
||||
gallery_command=("$helper_dir/panama-prism-gallery")
|
||||
|
||||
report_failure() {
|
||||
local status=$?
|
||||
@@ -35,8 +29,8 @@ trap report_failure EXIT
|
||||
show_state() {
|
||||
local state="$1" on_icon="$2" off_icon="$3" label="$4"
|
||||
case "$state" in
|
||||
true) "${osd_command[@]}" message "$on_icon" "$label On" ;;
|
||||
false) "${osd_command[@]}" message "$off_icon" "$label Off" ;;
|
||||
true) PANAMA_OSD_STRICT=1 "${osd_command[@]}" message "$on_icon" "$label On" ;;
|
||||
false) PANAMA_OSD_STRICT=1 "${osd_command[@]}" message "$off_icon" "$label Off" ;;
|
||||
*)
|
||||
printf 'Panama action returned an invalid state: %s\n' "$state" >&2
|
||||
return 1
|
||||
@@ -44,12 +38,55 @@ show_state() {
|
||||
esac
|
||||
}
|
||||
|
||||
state_is_active() {
|
||||
local target="$1"
|
||||
case "$target" in
|
||||
caffeine)
|
||||
systemd-inhibit --list --no-pager --no-legend 2>/dev/null \
|
||||
| awk '$1 == "Panama" && $(NF - 1) == "Caffeine" && $NF == "block" { found = 1 } END { exit !found }'
|
||||
;;
|
||||
night-light)
|
||||
pgrep -u "$(id -u)" -x hyprsunset >/dev/null 2>&1
|
||||
;;
|
||||
*) return 2 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
wait_for_confirmed_state() {
|
||||
local target="$1" expected="$2" attempt
|
||||
for ((attempt = 0; attempt < confirm_attempts; attempt++)); do
|
||||
if [[ $expected == true ]] && state_is_active "$target"; then
|
||||
return 0
|
||||
fi
|
||||
if [[ $expected == false ]] && ! state_is_active "$target"; then
|
||||
return 0
|
||||
fi
|
||||
sleep "$confirm_delay"
|
||||
done
|
||||
printf 'Panama action could not confirm %s reached state %s\n' "$target" "$expected" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
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
|
||||
wait_for_confirmed_state "$target" "$state"
|
||||
show_state "$state" "$on_icon" "$off_icon" "$label"
|
||||
}
|
||||
|
||||
wait_for_shell() {
|
||||
local attempt
|
||||
for ((attempt = 0; attempt < confirm_attempts; attempt++)); do
|
||||
if qs ipc show >/dev/null 2>&1; then
|
||||
return 0
|
||||
fi
|
||||
sleep "$confirm_delay"
|
||||
done
|
||||
printf 'Panama shell did not become ready after restart\n' >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
case "$action" in
|
||||
control-center) qs ipc call quicksettings open ;;
|
||||
notifications) qs ipc call notifications open ;;
|
||||
@@ -69,23 +106,30 @@ case "$action" in
|
||||
toggle_state night-light night-light-symbolic night-light-disabled-symbolic "Night Light"
|
||||
;;
|
||||
focus-start)
|
||||
qs ipc call focus start
|
||||
"${osd_command[@]}" message preferences-system-time-symbolic "Focus Session Started"
|
||||
state="$(qs ipc call focus start)"
|
||||
[[ $state == true ]]
|
||||
PANAMA_OSD_STRICT=1 "${osd_command[@]}" message preferences-system-time-symbolic "Focus Session Started"
|
||||
;;
|
||||
focus-end)
|
||||
qs ipc call focus end
|
||||
"${osd_command[@]}" message media-playback-stop-symbolic "Focus Session Ended"
|
||||
state="$(qs ipc call focus end)"
|
||||
if [[ $state == true ]]; then
|
||||
PANAMA_OSD_STRICT=1 "${osd_command[@]}" message media-playback-stop-symbolic "Focus Session Ended"
|
||||
else
|
||||
PANAMA_OSD_STRICT=1 "${osd_command[@]}" message dialog-information-symbolic "No Focus Session Running"
|
||||
fi
|
||||
;;
|
||||
|
||||
capture) qs ipc call capture open ;;
|
||||
intelligence) qs ipc call screen-intelligence open ;;
|
||||
screenshot) qs ipc call capture screenNow ;;
|
||||
microphone) "${osd_command[@]}" microphone toggle ;;
|
||||
microphone) PANAMA_OSD_STRICT=1 "${osd_command[@]}" microphone toggle ;;
|
||||
|
||||
gallery) "${gallery_command[@]}" ;;
|
||||
restart-shell)
|
||||
qs kill
|
||||
qs kill >/dev/null 2>&1 || true
|
||||
quickshell --daemonize
|
||||
wait_for_shell
|
||||
PANAMA_OSD_STRICT=1 "${osd_command[@]}" message view-refresh-symbolic "Panama Restarted"
|
||||
;;
|
||||
*)
|
||||
printf 'Usage: panama-action {%s}\n' \
|
||||
|
||||
Reference in New Issue
Block a user