From 562f2c63b2f2907aa1e84329c4308172f0e65d4b Mon Sep 17 00:00:00 2001 From: yegorius Date: Sat, 23 Dec 2023 17:03:34 +0000 Subject: [PATCH 1/2] change session cleanup mechanism --- src/session.sh | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/src/session.sh b/src/session.sh index 1a5b86b..6649a68 100755 --- a/src/session.sh +++ b/src/session.sh @@ -43,7 +43,7 @@ VARIABLES="DESKTOP_SESSION XDG_CURRENT_DESKTOP XDG_SESSION_DESKTOP XDG_SESSION_T VARIABLES="${VARIABLES} DISPLAY I3SOCK SWAYSOCK WAYLAND_DISPLAY" SESSION_TARGET="sway-session.target" SESSION_SHUTDOWN_TARGET="sway-session-shutdown.target" -WITH_CLEANUP=1 +ENV_FILE="$XDG_RUNTIME_DIR/$SESSION_TARGET.env" print_usage() { cat <&2 print_usage @@ -111,26 +121,4 @@ systemctl --user reset-failed # shellcheck disable=SC2086 systemctl --user import-environment $VARIABLES systemctl --user start "$SESSION_TARGET" - -# Optionally, wait until the compositor exits and cleanup variables and services. -if [ -z "$WITH_CLEANUP" ] || - [ -z "$SWAYSOCK" ] || - ! hash swaymsg 2>/dev/null -then - exit 0; -fi - -# declare cleanup handler and run it on script termination via kill or Ctrl-C -session_cleanup () { - # stop the session target and unset the variables - systemctl --user start --job-mode=replace-irreversibly "$SESSION_SHUTDOWN_TARGET" - if [ -n "$VARIABLES" ]; then - # shellcheck disable=SC2086 - systemctl --user unset-environment $VARIABLES - fi -} -trap session_cleanup INT TERM -# wait until the compositor exits -swaymsg -t subscribe '["shutdown"]' -# run cleanup handler on normal exit -session_cleanup +echo "$VARIABLES" > "$ENV_FILE" From c896cc3868301242678b2116720551b387251ded Mon Sep 17 00:00:00 2001 From: Yegor Gemba Date: Tue, 16 Apr 2024 17:02:31 +0300 Subject: [PATCH 2/2] Minor improvement --- src/session.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/session.sh b/src/session.sh index 6649a68..e1d69d8 100755 --- a/src/session.sh +++ b/src/session.sh @@ -64,7 +64,6 @@ session_cleanup () { xargs -a "$ENV_FILE" systemctl --user unset-environment rm "$ENV_FILE" fi - swaymsg exit } while [ $# -gt 0 ]; do @@ -85,6 +84,7 @@ while [ $# -gt 0 ]; do VARIABLES="${VARIABLES} ${1}" ;; --exit) session_cleanup + swaymsg exit exit ;; -*) echo "Unexpected option: $1" 1>&2