Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit
Swift apple-silicond3dmetaldxmtdxvkgame-porting-toolkitgptkmac-gamingmacosmetalfxrosetta-2steamsteam-playwinewinecx
Keep the prefix alive after a launcher exits
jacobbinnie38af1d3bf939
diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.shindex 84d1e7d..e086029 100755--- a/dylib/feats/compat_run.sh+++ b/dylib/feats/compat_run.sh@@ -1453,35 +1453,6 @@ install_bundle() ()install_bundle-wine_helpers='winedevice\.exe|services\.exe|plugplay\.exe|svchost\.exe'-wine_helpers="$wine_helpers|rpcss\.exe|explorer\.exe|steam\.exe"-wine_helpers="$wine_helpers|winemenubuilder\.exe|conhost\.exe|start\.exe"-wine_helpers="$wine_helpers|wineboot\.exe|rundll32\.exe|tabtip\.exe"-wine_helpers="$wine_helpers|vc_redist|vcredist|dxsetup\.exe|msiexec\.exe"-wine_helpers="$wine_helpers|installinf|iscriptevaluator\.exe|regsvr32\.exe"-wine_helpers="$wine_helpers|winedbg\.exe|unitycrashhandler"-prefix_game_running() {- command -v lsof >/dev/null 2>&1 || return 1- dir=$(prefix_server_dir) || return 1- [ -d "$dir" ] || return 1- pids=$(lsof -t +D "$dir" 2>/dev/null | sort -u | tr '\n' ',')- pids=${pids%,}- [ -n "$pids" ] || return 1- # shellcheck disable=SC1003 # the pair matches the backslash in a drive path- ps -p "$pids" -o args= 2>/dev/null | grep -E '^[A-Za-z]:\\' | grep -viE "$wine_helpers" | grep -q .-}--wait_prefix_idle() {- idle=0- tick=0- while [ "$idle" -lt 10 ] && [ "$tick" -lt 300 ]; do- tick=$((tick + 1))- if prefix_game_running; then idle=0; else idle=$((idle + 1)); fi- sleep 1- done- echo "wait_prefix_idle done after tick=$tick idle=$idle" >> "$log" 2>&1 || true-}-kill_wine_prefix() {"$WINESERVER" -k >> "$log" 2>&1 || true"$WINESERVER" -w >> "$log" 2>&1 || true@@ -1541,29 +1512,7 @@ lsregister="$lsregister/Frameworks/LaunchServices.framework/Support/lsregister"open -n -W -a "$loader_app" "$@" >> "$log" 2>&1 &open_pid=$!status=0-seen=0-idle=0-while :; do- if prefix_game_running; then- seen=1- idle=0- else- idle=$((idle + 1))- fi- if ! kill -0 "$open_pid" 2>/dev/null; then- wait "$open_pid" || status=$?- echo "=== bundle exited status=$status ===" >> "$log" 2>&1 || true- if [ "$status" -le 128 ]; then- wait_prefix_idle- fi- break- fi- if [ "$seen" -eq 1 ] && [ "$idle" -ge 10 ]; then- echo "=== game tree gone, ending session ===" >> "$log" 2>&1 || true- break- fi- sleep 1-done+wait "$open_pid" || status=$?echo "=== game exited status=$status, killing wine prefix ===" >> "$log" 2>&1 || truekill_wine_prefixecho "=== wine prefix killed, session ending ===" >> "$log" 2>&1 || truediff --git a/dylib/tests/launchercheck.sh b/dylib/tests/launchercheck.shindex c81c1a1..a7cd3f7 100644--- a/dylib/tests/launchercheck.sh+++ b/dylib/tests/launchercheck.sh@@ -255,5 +255,33 @@ is "no artwork, no icon key" "" "$icon_arg"is "no artwork logged" "no icon resolved, launching without one" "$(cat "$log")"if [ -d "$np_support/shortcut-icons" ]; then bad "launch leaves shortcut cache alone" "absent" "present"; else ok "launch leaves shortcut cache alone"; fi+echo "== session lasts as long as the shim =="+session_trap=$(sed -n '/^terminate() {$/,/^trap terminate TERM INT HUP$/p' "$SRC")+session_wait=$(sed -n '/^open -n -W -a "\$loader_app"/,/^exit \$status$/p' "$SRC")+[ -n "$session_trap" ] && [ -n "$session_wait" ] || { echo "FAIL: session code not found"; exit 1; }+{+ printf 'log=%s\nopen() { sleep "$1"; return "$2"; }\n' "$T/session.log"+ printf 'kill_wine_prefix() { echo kill >> "%s"; }\n' "$T/session.ev"+ printf '%s\n' "$session_trap"+ printf 'set -- "$1" "$2"\nloader_app=x\n'+ printf '%s\n' "$session_wait" | sed 's/open -n -W -a "\$loader_app" "\$@"/open "$@"/'+} > "$T/session.sh"+grep -q '^open "\$@"' "$T/session.sh" || { echo "FAIL: session launch line not rewritten"; exit 1; }+: > "$T/session.ev"+start=$(date +%s)+rc=0; sh "$T/session.sh" 3 7 || rc=$?+is "the shim's exit status is the session's" 7 "$rc"+is "the session waits for the shim" yes "$([ $(($(date +%s) - start)) -ge 3 ] && echo yes || echo no)"+is "the prefix is torn down once" kill "$(cat "$T/session.ev")"+: > "$T/session.ev"+start=$(date +%s)+sh "$T/session.sh" 30 0 & sp=$!+sleep 1+kill -TERM "$sp"+rc=0; wait "$sp" || rc=$?+is "exit game ends the session" 143 "$rc"+is "exit game does not wait out the shim" yes "$([ $(($(date +%s) - start)) -lt 5 ] && echo yes || echo no)"+is "exit game tears the prefix down" yes "$(grep -q kill "$T/session.ev" && echo yes || echo no)"+[ "$fails" -eq 0 ] || { echo "launchercheck: $fails failed"; exit 1; }echo "launchercheck: all passed"