relaunch ui last
This commit is contained in:
@@ -182,21 +182,42 @@ unload_launchd_helpers_user() {
|
|||||||
|
|
||||||
restart_launchagents_from_snapshot() {
|
restart_launchagents_from_snapshot() {
|
||||||
[[ -n "${snapfile:-}" && -f "${snapfile}" ]] || return 0
|
[[ -n "${snapfile:-}" && -f "${snapfile}" ]] || return 0
|
||||||
|
|
||||||
local uid count=0 ui_seen=0
|
local uid count=0 ui_seen=0
|
||||||
uid="$(id -u)"
|
uid="$(id -u)"
|
||||||
|
|
||||||
|
# Pass 1: restart all non-UI agents first
|
||||||
while IFS=$'\t' read -r plist label; do
|
while IFS=$'\t' read -r plist label; do
|
||||||
[[ -z "$plist" || -z "$label" ]] && continue
|
[[ -n "$plist" && -n "$label" ]] || continue
|
||||||
[[ -f "$plist" ]] || continue
|
[[ -f "$plist" ]] || continue
|
||||||
|
[[ "$label" == "$UI_LABEL" ]] && continue
|
||||||
|
|
||||||
log "Re-starting LaunchAgent: ${label}"
|
log "Re-starting LaunchAgent: ${label}"
|
||||||
/bin/launchctl bootstrap "gui/${uid}" "$plist" 2>/dev/null || true
|
/bin/launchctl bootstrap "gui/${uid}" "$plist" 2>/dev/null || true
|
||||||
/bin/launchctl kickstart -k "gui/${uid}/${label}" 2>/dev/null || true
|
/bin/launchctl kickstart -k "gui/${uid}/${label}" 2>/dev/null || true
|
||||||
((count++)) || true
|
((count++)) || true
|
||||||
[[ "$label" == "$UI_LABEL" ]] && ui_seen=1 || true
|
|
||||||
done <"$snapfile"
|
done <"$snapfile"
|
||||||
|
|
||||||
|
# Give helpers a moment to settle (e.g., automounts)
|
||||||
|
sleep 0.3
|
||||||
|
|
||||||
|
# Pass 2: restart the UI agent last (if present in the snapshot)
|
||||||
|
while IFS=$'\t' read -r plist label; do
|
||||||
|
[[ -n "$plist" && -n "$label" ]] || continue
|
||||||
|
[[ -f "$plist" ]] || continue
|
||||||
|
[[ "$label" == "$UI_LABEL" ]] || continue
|
||||||
|
|
||||||
|
log "Re-starting UI LaunchAgent last: ${label}"
|
||||||
|
/bin/launchctl bootstrap "gui/${uid}" "$plist" 2>/dev/null || true
|
||||||
|
/bin/launchctl kickstart -k "gui/${uid}/${label}" 2>/dev/null || true
|
||||||
|
ui_seen=1
|
||||||
|
((count++)) || true
|
||||||
|
done <"$snapfile"
|
||||||
|
|
||||||
log "Re-started ${count} LaunchAgent(s) with prefix ${LABEL_PREFIX}." || true
|
log "Re-started ${count} LaunchAgent(s) with prefix ${LABEL_PREFIX}." || true
|
||||||
|
|
||||||
if ((ui_seen)); then
|
if ((ui_seen)); then
|
||||||
sleep 0.3
|
# If the UI label is active, skip manual open(1).
|
||||||
if /bin/launchctl list | /usr/bin/awk '{print $3}' | /usr/bin/grep -Fxq "$UI_LABEL"; then
|
if /bin/launchctl list | /usr/bin/awk '{print $3}' | /usr/bin/grep -Fxq "$UI_LABEL"; then
|
||||||
log "UI LaunchAgent (${UI_LABEL}) active after restart; skipping manual UI launch."
|
log "UI LaunchAgent (${UI_LABEL}) active after restart; skipping manual UI launch."
|
||||||
skip_ui_launch=1
|
skip_ui_launch=1
|
||||||
|
|||||||
Reference in New Issue
Block a user