From 7ef49290ea5c90b113387a0456128a1645825b4c Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Sat, 16 May 2026 19:33:22 -0400 Subject: [PATCH] Fixed a small bug in the update notification script and how it was launched. --- i38.sh | 2 +- scripts/i38-update-check.sh | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/i38.sh b/i38.sh index e561900..05476d9 100755 --- a/i38.sh +++ b/i38.sh @@ -1309,7 +1309,7 @@ if command -v waytray-daemon &> /dev/null ; then fi echo "exec_always --no-startup-id ${i3Path}/scripts/i38-clipboard.py --daemon" echo "exec_always --no-startup-id ${i3Path}/scripts/desktop.sh" -echo "exec --no-startup-id ${i3Path}/scripts/i38-update-check.sh" +echo "exec_always --no-startup-id ${i3Path}/scripts/i38-update-check.sh" if [[ $dex -eq 0 ]]; then echo '# Start XDG autostart .desktop files using dex. See also' echo '# https://wiki.archlinux.org/index.php/XDG_Autostart' diff --git a/scripts/i38-update-check.sh b/scripts/i38-update-check.sh index 61b96d0..d0ddd07 100755 --- a/scripts/i38-update-check.sh +++ b/scripts/i38-update-check.sh @@ -21,6 +21,8 @@ i3Dir="$(dirname -- "$scriptDir")" versionFile="${I38_VERSION_FILE:-${i3Dir}/i38-version}" stateDir="${XDG_STATE_HOME:-${HOME}/.local/state}/I38" notifyState="${stateDir}/update-check-notified" +runtimeDir="${XDG_RUNTIME_DIR:-/tmp}" +lockDir="${runtimeDir}/i38-update-check" valid_commit() { [[ "${1:-}" =~ ^[0-9a-fA-F]{40}$ ]] @@ -84,10 +86,32 @@ send_update_notification() { remember_notification "$remoteCommit" } +stop_update_check() { + rm -rf "$lockDir" + exit 0 +} + if ! command -v git > /dev/null || ! command -v notify-send > /dev/null; then exit 0 fi +if [[ -d "$lockDir" ]]; then + if [[ -f "${lockDir}/pid" ]]; then + IFS= read -r existingPid < "${lockDir}/pid" || existingPid="" + if [[ "$existingPid" =~ ^[0-9]+$ ]] && kill -0 "$existingPid" 2> /dev/null; then + exit 0 + fi + fi + rm -rf "$lockDir" +fi + +if ! mkdir "$lockDir" 2> /dev/null; then + exit 0 +fi +printf '%s\n' "$$" > "${lockDir}/pid" +trap 'rm -rf "$lockDir"' EXIT +trap stop_update_check INT TERM + sleep "$initialDelay" while :; do