fix(replace,wm,autostart): preserve workspaces across slow/3rd-party replace and guard polkit agent startup
This commit is contained in:
1 parent
4ec3f59e02
commit
c5ce065c33
6 files changed
+759
-53
No files matched your search
+40
-7
@@ -11,6 +11,7 @@ PROFILE="${ANODE_SESSION_PROFILE:-}"
|
||||
KEEP_PANELS=0
|
||||
FOREGROUND=0
|
||||
NO_AUTOSTART=0
|
||||
FORCE_AUTOSTART=0
|
||||
FORCE=0
|
||||
SWITCH_SESSION=0
|
||||
DRY_RUN=0
|
||||
@@ -26,7 +27,8 @@ Options:
|
||||
--profile NAME Pass session autostart profile NAME to anode-session
|
||||
--keep-panels Do not stop existing panel, notification, or xsettings daemons
|
||||
--foreground Exec anode-session in the foreground instead of detaching
|
||||
--no-autostart Skip anode-autostart start during replacement
|
||||
--no-autostart Skip anode-autostart completely during replacement
|
||||
--autostart Run full anode-autostart start even during replacement
|
||||
--force Proceed with in-place replacement even if WM is DM session leader
|
||||
--switch-session Switch to an ANODE LightDM session cleanly (schedules one-shot ~/.xprofile handoff when a user session is already active)
|
||||
--dry-run Print detected WM and planned actions without replacing
|
||||
@@ -55,6 +57,12 @@ while [ $# -gt 0 ]; do
|
||||
;;
|
||||
--no-autostart)
|
||||
NO_AUTOSTART=1
|
||||
FORCE_AUTOSTART=0
|
||||
shift
|
||||
;;
|
||||
--autostart)
|
||||
FORCE_AUTOSTART=1
|
||||
NO_AUTOSTART=0
|
||||
shift
|
||||
;;
|
||||
--force)
|
||||
@@ -474,6 +482,8 @@ if [ -n "$PROFILE" ]; then
|
||||
fi
|
||||
if [ "$NO_AUTOSTART" = "1" ]; then
|
||||
set -- "$@" --no-autostart
|
||||
elif [ "$FORCE_AUTOSTART" = "1" ]; then
|
||||
set -- "$@" --autostart
|
||||
fi
|
||||
|
||||
if [ "$DRY_RUN" = "1" ]; then
|
||||
@@ -525,19 +535,35 @@ if [ "$KEEP_PANELS" != "1" ]; then
|
||||
dunst xfce4-notifyd xsettingsd xfsettingsd
|
||||
fi
|
||||
|
||||
_snap_dir="${XDG_RUNTIME_DIR:-${TMPDIR:-/tmp}}"
|
||||
[ -d "$_snap_dir" ] && [ -w "$_snap_dir" ] || _snap_dir="/tmp"
|
||||
SNAP_READY_FILE="$_snap_dir/anode-replace-snap.$$"
|
||||
rm -f "$SNAP_READY_FILE"
|
||||
ANODE_REPLACE_SNAP_FILE="$SNAP_READY_FILE"
|
||||
ANODE_REPLACE_PREV_WM_WIN="${PREV_WM_WIN:-}"
|
||||
export ANODE_REPLACE_SNAP_FILE ANODE_REPLACE_PREV_WM_WIN
|
||||
|
||||
if [ "$FOREGROUND" = "1" ]; then
|
||||
if [ -n "${PREV_WM_PID:-}" ] && is_my_pid "$PREV_WM_PID"; then
|
||||
(
|
||||
_w=0
|
||||
while [ "$_w" -lt 40 ] && [ ! -e "$SNAP_READY_FILE" ]; do
|
||||
_w=$(( _w + 1 ))
|
||||
sleep 0.1
|
||||
done
|
||||
sleep 1.5
|
||||
_cur_win="$(get_root_wm_win || true)"
|
||||
if [ -n "${PREV_WM_WIN:-}" ] && [ "$_cur_win" = "$PREV_WM_WIN" ] && kill -0 "$PREV_WM_PID" 2>/dev/null; then
|
||||
kill -TERM "$PREV_WM_PID" 2>/dev/null || true
|
||||
fi
|
||||
rm -f "$SNAP_READY_FILE"
|
||||
) </dev/null >/dev/null 2>&1 &
|
||||
fi
|
||||
exec "$ANODE_SESSION_BIN" "$@"
|
||||
fi
|
||||
|
||||
trap 'rm -f "$SNAP_READY_FILE"' EXIT INT TERM
|
||||
|
||||
(
|
||||
trap '' HUP
|
||||
exec "$ANODE_SESSION_BIN" "$@"
|
||||
@@ -545,19 +571,26 @@ fi
|
||||
SESSION_PID=$!
|
||||
|
||||
_tick=0
|
||||
_snap_tick=""
|
||||
_fallback_sent=0
|
||||
_replaced=0
|
||||
while [ "$_tick" -lt 50 ]; do
|
||||
while [ "$_tick" -lt 80 ]; do
|
||||
if ! kill -0 "$SESSION_PID" 2>/dev/null; then
|
||||
printf 'anode-replace: error: anode-session exited prematurely\n' >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ "$_tick" -ge 15 ] && [ "$_fallback_sent" = "0" ] && [ -n "${PREV_WM_PID:-}" ]; then
|
||||
_cur_win="$(get_root_wm_win || true)"
|
||||
if [ -n "${PREV_WM_WIN:-}" ] && [ "$_cur_win" = "$PREV_WM_WIN" ] && is_my_pid "$PREV_WM_PID"; then
|
||||
kill -TERM "$PREV_WM_PID" 2>/dev/null || true
|
||||
_fallback_sent=1
|
||||
if [ -z "$_snap_tick" ] && [ -e "$SNAP_READY_FILE" ]; then
|
||||
_snap_tick="$_tick"
|
||||
fi
|
||||
|
||||
if [ "$_fallback_sent" = "0" ] && [ -n "${PREV_WM_PID:-}" ]; then
|
||||
if { [ -n "$_snap_tick" ] && [ $(( _tick - _snap_tick )) -ge 15 ]; } || [ "$_tick" -ge 45 ]; then
|
||||
_cur_win="$(get_root_wm_win || true)"
|
||||
if [ -n "${PREV_WM_WIN:-}" ] && [ "$_cur_win" = "$PREV_WM_WIN" ] && is_my_pid "$PREV_WM_PID"; then
|
||||
kill -TERM "$PREV_WM_PID" 2>/dev/null || true
|
||||
_fallback_sent=1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
Reference in new issue
Block a user