Cross-check HIS against hyprctl instances (dir can linger)
The previous check trusted $XDG_RUNTIME_DIR/hypr/$HIS/ existing, but the directory and its socket files can remain on disk after the session dies. On a real run the stale signature still had a dir, so the guard passed and hyprctl silently failed again. ensure_hyprland_env now queries `hyprctl instances` — the source of truth for live sessions — and rewrites HIS if ours isn't in the list. Watcher mirrors the same logic. Also: drop the outdated "zenity" mention from the installer header.
This commit is contained in:
parent
154bcc85d4
commit
9e201769c9
3 changed files with 39 additions and 33 deletions
|
|
@ -182,28 +182,33 @@ show_header() {
|
||||||
# ===== selection ==============================================================
|
# ===== selection ==============================================================
|
||||||
|
|
||||||
ensure_hyprland_env() {
|
ensure_hyprland_env() {
|
||||||
# The TUI can be launched from contexts whose env doesn't carry a valid
|
# The TUI can be launched from contexts whose HYPRLAND_INSTANCE_SIGNATURE
|
||||||
# HYPRLAND_INSTANCE_SIGNATURE. Two failure modes:
|
# isn't usable. Three failure modes, all silent:
|
||||||
# 1) HIS unset (fresh login shell from a non-graphical context)
|
# 1) HIS unset (fresh login shell, cron, ssh).
|
||||||
# 2) HIS set but STALE — points to a previous Hyprland session whose
|
# 2) HIS set but points to a dead session — the `hypr/<sig>/` directory
|
||||||
# socket no longer exists (seen when Walker's env carries the
|
# and its socket files can linger on disk after the Hyprland process
|
||||||
# signature from an earlier login). The second case is silent but
|
# exits, so a dir-exists check is not enough.
|
||||||
# equally broken: hyprctl dumps a plain-text error on stdout.
|
# 3) Walker's env retained an old HIS across a Hyprland restart.
|
||||||
# `hyprctl instances` always reports the *live* signatures, so recover
|
# `hyprctl instances` is the source of truth: it only reports live
|
||||||
# from that. Leave HIS unchanged if we can't find a live instance.
|
# instances. Always cross-check against it and rewrite HIS if ours isn't
|
||||||
|
# in the list.
|
||||||
local his="${HYPRLAND_INSTANCE_SIGNATURE:-}"
|
local his="${HYPRLAND_INSTANCE_SIGNATURE:-}"
|
||||||
if [ -n "$his" ] && [ -d "$RUNTIME_DIR/hypr/$his" ]; then
|
local live
|
||||||
|
live="$(hyprctl instances 2>/dev/null | awk '/^instance /{sub(/:$/,"",$2); print $2}')"
|
||||||
|
if [ -z "$live" ]; then
|
||||||
|
# No live Hyprland — nothing we can do, let the caller surface an error.
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
if [ -n "$his" ] && printf '%s\n' "$live" | grep -qxF "$his"; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
local sig
|
local sig
|
||||||
sig="$(hyprctl instances 2>/dev/null | awk '/^instance /{sub(/:$/,"",$2); print $2; exit}')"
|
sig="$(printf '%s\n' "$live" | head -n 1)"
|
||||||
if [ -n "$sig" ] && [ "$sig" != "$his" ]; then
|
export HYPRLAND_INSTANCE_SIGNATURE="$sig"
|
||||||
export HYPRLAND_INSTANCE_SIGNATURE="$sig"
|
if [ -n "$his" ]; then
|
||||||
if [ -n "$his" ]; then
|
log "replaced stale HYPRLAND_INSTANCE_SIGNATURE ($his → $sig)"
|
||||||
log "replaced stale HYPRLAND_INSTANCE_SIGNATURE ($his → $sig)"
|
else
|
||||||
else
|
log "recovered HYPRLAND_INSTANCE_SIGNATURE=$sig from hyprctl instances"
|
||||||
log "recovered HYPRLAND_INSTANCE_SIGNATURE=$sig from hyprctl instances"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,17 +21,17 @@ log() {
|
||||||
}
|
}
|
||||||
|
|
||||||
his="${HYPRLAND_INSTANCE_SIGNATURE:-}"
|
his="${HYPRLAND_INSTANCE_SIGNATURE:-}"
|
||||||
if [ -z "$his" ] || [ ! -d "$RUNTIME_DIR/hypr/$his" ]; then
|
# Cross-check against `hyprctl instances` — the socket dir alone can linger
|
||||||
# HIS is missing or stale (points to a dead session). Recover from the
|
# on disk after a session dies, so a dir-exists check isn't reliable.
|
||||||
# live signature reported by `hyprctl instances`.
|
live="$(hyprctl instances 2>/dev/null | awk '/^instance /{sub(/:$/,"",$2); print $2}')"
|
||||||
sig="$(hyprctl instances 2>/dev/null | awk '/^instance /{sub(/:$/,"",$2); print $2; exit}')"
|
if [ -z "$live" ]; then
|
||||||
if [ -n "$sig" ]; then
|
log "no live Hyprland instance reported by hyprctl — exiting"
|
||||||
export HYPRLAND_INSTANCE_SIGNATURE="$sig"
|
exit 0
|
||||||
log "using HYPRLAND_INSTANCE_SIGNATURE=$sig (was: ${his:-unset})"
|
fi
|
||||||
else
|
if [ -z "$his" ] || ! printf '%s\n' "$live" | grep -qxF "$his"; then
|
||||||
log "HYPRLAND_INSTANCE_SIGNATURE not usable and no live instance found — exiting"
|
sig="$(printf '%s\n' "$live" | head -n 1)"
|
||||||
exit 0
|
export HYPRLAND_INSTANCE_SIGNATURE="$sig"
|
||||||
fi
|
log "using HYPRLAND_INSTANCE_SIGNATURE=$sig (was: ${his:-unset})"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
HYPR_SOCK="$RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock"
|
HYPR_SOCK="$RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock"
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,15 @@
|
||||||
# Motion Wallpaper Installer for Omarchy / Hyprland
|
# Motion Wallpaper Installer for Omarchy / Hyprland
|
||||||
#
|
#
|
||||||
# Installs:
|
# Installs:
|
||||||
# ~/.local/bin/motion-wallpaper-toggle runtime script
|
# ~/.local/bin/motion-wallpaper-toggle runtime TUI
|
||||||
|
# ~/.local/bin/motion-wallpaper-watcher auto-pause watcher
|
||||||
# ~/.local/share/applications/motion-wallpaper-toggle.desktop app entry
|
# ~/.local/share/applications/motion-wallpaper-toggle.desktop app entry
|
||||||
# ~/.config/systemd/user/motion-wallpaper.service optional autostart unit
|
# ~/.local/share/icons/hicolor/scalable/apps/motion-wallpaper.svg icon
|
||||||
|
# ~/.config/systemd/user/motion-wallpaper.service optional autostart unit
|
||||||
#
|
#
|
||||||
# Dependencies:
|
# Dependencies:
|
||||||
# mpv, jq, zenity (pacman)
|
# mpv, jq, gum, socat, libnotify (pacman)
|
||||||
# mpvpaper (AUR, via yay or paru)
|
# mpvpaper (AUR, via yay or paru)
|
||||||
# libnotify (pacman) — optional, for notify-send
|
|
||||||
# ==============================================================================
|
# ==============================================================================
|
||||||
|
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue