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
feat(run): say once when a game starts in Low Power Mode (#202)
Raystormsccf40fd9a11a
diff --git a/AGENTS.md b/AGENTS.mdindex ca45873..55479f9 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -61,7 +61,7 @@ The checks the workflows run (`make -s <target>`):- **C and shell suites:** `sigcheck`, `callscheck`, `webpatch-fixtures`, `peicon-fixtures`,`panel-behavior`, `spawn-env`, `activatecheck`, `compatcheck`, `compatsvc-check`, `prefixstate-check`,`shortcutcheck`, `launch-shell`, `envcheck`, `buildcheck`, `settingscheck`, `routecheck`,- `bridgecheck`, `envpasscheck`, `prefixnotecheck`, `gamedrivecheck`, `launchercheck`, `seedcheck`, `gamefixescheck`, `versioncheck`, `cicheck`,+ `bridgecheck`, `envpasscheck`, `prefixnotecheck`, `powernotecheck`, `gamedrivecheck`, `launchercheck`, `seedcheck`, `gamefixescheck`, `versioncheck`, `cicheck`,`compat-reported-check`- **Hardware-free device checks:** `game-host-check`, `dualsense-check`, `steam-rumble-check`diff --git a/Makefile b/Makefileindex ff0783a..f520110 100644--- a/Makefile+++ b/Makefile@@ -74,7 +74,7 @@ DEPS := $(OBJS:.o=.d)tests-list overlay-shim overlay-shim-install overlay-shim-tests \overlay-shim-bench iconmaker icon \appinfo helpers-install ntdll-resolve bridge runcheck compatcheck \- compatsvc-check prefixstate-check shortcutcheck scriptcheck envcheck buildcheck settingscheck routecheck bridgecheck envpasscheck prefixnotecheck gamedrivecheck \+ compatsvc-check prefixstate-check shortcutcheck scriptcheck envcheck buildcheck settingscheck routecheck bridgecheck envpasscheck prefixnotecheck powernotecheck gamedrivecheck \gamefixescheck launchercheck padcheck launch-shell activatecheck stamp-check versioncheck cicheck compat-reported-check FORCEAPP_PAYLOAD := app/Sources/BridgeplayApp/Resources/payload@@ -139,6 +139,10 @@ prefixnotecheck:@if [ ! -f dylib/tests/prefixnotecheck.sh ]; then $(call SKIP,prefixnotecheck,dylib/tests/prefixnotecheck.sh); exit 0; fi; \sh dylib/tests/prefixnotecheck.sh dylib/feats/compat_run.sh+powernotecheck:+ @if [ ! -f dylib/tests/powernotecheck.sh ]; then $(call SKIP,powernotecheck,dylib/tests/powernotecheck.sh); exit 0; fi; \+ sh dylib/tests/powernotecheck.sh dylib/feats/compat_run.sh+gamedrivecheck:@if [ ! -f dylib/tests/gamedrivecheck.sh ]; then $(call SKIP,gamedrivecheck,dylib/tests/gamedrivecheck.sh); exit 0; fi; \sh dylib/tests/gamedrivecheck.sh dylib/feats/compat_run.sh@@ -940,7 +944,7 @@ native-shim-tests:CI_CHECKS := mincheck l10ncheck \sigcheck callscheck webpatch-fixtures peicon-fixtures panel-behavior spawn-env \activatecheck compatcheck compatsvc-check prefixstate-check shortcutcheck launch-shell envcheck \- buildcheck settingscheck routecheck bridgecheck envpasscheck prefixnotecheck gamedrivecheck launchercheck \+ buildcheck settingscheck routecheck bridgecheck envpasscheck prefixnotecheck powernotecheck gamedrivecheck launchercheck \seedcheck gamefixescheck versioncheck cicheck padcheck compat-reported-check np-native-tests native-shim-tests \app-tests native-installercheck game-host-check dualsense-check steam-rumble-checkdiff --git a/dylib/AGENTS.md b/dylib/AGENTS.mdindex 79b422e..22a7156 100644--- a/dylib/AGENTS.md+++ b/dylib/AGENTS.md@@ -22,7 +22,7 @@ down for the user. The constructor in `core/loader.c` only does work in `steam_oallow-list in `gamefix_reason`, a row in [docs/GAMEFIXES.md](../docs/GAMEFIXES.md), anda passing `make gamefixescheck`.- Checks for the run script: `runcheck`, `envcheck`, `settingscheck`, `routecheck`,- `gamedrivecheck`, `prefixnotecheck`, `launchercheck`, `gamefixescheck`.+ `gamedrivecheck`, `prefixnotecheck`, `powernotecheck`, `launchercheck`, `gamefixescheck`.- **Tests** live in `dylib/tests/`. They run without Steam or Dobby; several `#include` the`.c` file under test for that reason. Add a new check as a Makefile target and to thecheck list in `.github/workflows/app.yml`.diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.shindex 756484c..e66abcd 100755--- a/dylib/feats/compat_run.sh+++ b/dylib/feats/compat_run.sh@@ -1046,6 +1046,39 @@ first_launch_notice() {notify_user "Getting this game ready" "The first launch sets the game up and prepares its graphics. It can take a few minutes, and the screen may stay black until it is ready."}+# Prints 1 when Low Power Mode is on, 0 when off, nothing when pmset does not say. pmset's+# "Currently in use" values are what ProcessInfo.isLowPowerModeEnabled reports, the lowPower+# field of compatibility reports (GameReport.swift). Macs with High Power Mode call it+# powermode (0 automatic, 1 low, 2 high).+low_power_mode() {+ pmset -g 2>/dev/null | awk '$1 == "lowpowermode" || $1 == "powermode" { seen = 1; if ($2 == "1") low = 1 }+ END { if (seen) print low ? 1 : 0 }'+}++# Low Power Mode lowers the GPU's clocks, and players do not tie that to a slow game. Says so+# once per Low Power Mode session for each macOS user: the mark goes when a launch finds it+# off. Runs beside the launch, and when pmset gives no answer nothing is shown or cleared.+low_power_notice() {+ [ "$verb" = waitforexitandrun ] || return 0+ (+ exec 8>&- 9>&-+ mark="$np_support/low-power-noticed"+ # Games starting together read pmset and change the mark one at a time, so a launch that+ # read "off" cannot remove a mark made after its read. No lock means no notice.+ exec 7>> "$np_support/.low-power.lock" && /usr/bin/lockf -s -t 5 7 || exit 0+ tell=""+ case "$(low_power_mode)" in+ 0) rm -f "$mark" ;;+ 1)+ echo "power: Low Power Mode is on" >> "$log" 2>&1 || true+ [ -e "$mark" ] || { : > "$mark" && tell=1; } || true+ ;;+ esac+ exec 7>&-+ [ -z "$tell" ] || notify_user "Low Power Mode is on" "Games run slower while it is on. Turn it off in System Settings > Battery, or Energy on a desktop Mac."+ ) >/dev/null 2>&1 &+}+# Posted by the Bridgeplay app, so it carries Bridgeplay's name and icon; osascript (shown# as Script Editor) only when the app cannot be found. Never holds up the launch.notify_user() {@@ -2218,6 +2251,7 @@ if [ -n "$STEAM_COMPAT_DATA_PATH" ]; thenstage_step="prefix check"refuse_broken_prefixfi+low_power_noticestage_step="graphics backend"select_backend "$1"diff --git a/dylib/tests/powernotecheck.sh b/dylib/tests/powernotecheck.shnew file mode 100755index 0000000..a8ac89a--- /dev/null+++ b/dylib/tests/powernotecheck.sh@@ -0,0 +1,138 @@+#!/bin/sh+# A game started in Low Power Mode tells the player once per Low Power Mode session, beside+# the launch. An unknown power state says and clears nothing, and games starting together+# take turns.+# shellcheck disable=SC2016 # the sh -ec program expands its own variables+set -e+SRC="${1:-$(dirname "$0")/../feats/compat_run.sh}"+[ -f "$SRC" ] || { echo "powernotecheck: $SRC not present, skipped"; exit 0; }++body=$(sed -n '/^low_power_mode() {/,/^}/p;/^low_power_notice() {/,/^}/p' "$SRC")+case "$body" in+ *low_power_mode*low_power_notice*'/usr/bin/lockf -s -t 5 7'*) ;;+ *) echo "FAIL: the Low Power Mode notice and its lock were not found in $SRC"; exit 1 ;;+esac+# lockf is macOS's. Elsewhere the lock is left out and the cases that need it do not run.+if [ -x /usr/bin/lockf ]; then+ locks=1+ body=$(printf '%s\n' "$body" | sed 's|/usr/bin/lockf -s -t 5 7|/usr/bin/lockf -s -t 1 7|')+else+ locks=0+ body=$(printf '%s\n' "$body" | sed 's|/usr/bin/lockf -s -t 5 7|true|')+fi+body="$body"'+notify_user() { printf "%s|%s\n" "$1" "$2" >> "$notes"; }+pmset() { [ "$1" = -g ] || return 1; [ -z "$during" ] || eval "$during"; [ -n "$pm" ] || return 1; printf "%s\n" "$pm"; }'++# a failed mktemp must not leave work at the current folder, which the trap deletes+work=$(mktemp -d) && work=$(cd "$work" && pwd -P) || exit 1+trap 'rm -rf "$work"' EXIT++fails=0+ok() { printf ' ok %s\n' "$1"; }+bad() { printf ' FAIL %s\n want [%s]\n got [%s]\n' "$1" "$2" "$3"; fails=$((fails + 1)); }+is() { if [ "$2" = "$3" ]; then ok "$1"; else bad "$1" "$2" "$3"; fi; }+has() { if grep -qF -- "$2" "$3"; then ok "$1"; else bad "$1" "$2" "$(cat "$3")"; fi; }+marked() { [ -e "$mark" ] && echo yes || echo no; }++support="$work/Application Support/bridgeplay"+mkdir -p "$support"+mark="$support/low-power-noticed"+lock="$support/.low-power.lock"++# pmset -g as macOS prints it, with the power mode line given+pmset_g() {+ printf 'System-wide power settings:\nCurrently in use:\n standby 1\n%s\n displaysleep 2\n tcpkeepalive 1\n' "$1"+}++mode() { env pm="$1" body="$body" sh -ec 'eval "$body"; low_power_mode'; }++run() { # run PMSET_OUTPUT [VERB [DURING]]: one launch, waits for the notice beside it.+ # DURING runs while pmset is read.+ : > "$work/log"+ : > "$work/notes"+ env log="$work/log" notes="$work/notes" np_support="$support" pm="$1" verb="${2:-waitforexitandrun}" \+ during="${3:-}" body="$body" sh -ec 'eval "$body"; low_power_notice; wait'+}++on=$(pmset_g ' lowpowermode 1')+off=$(pmset_g ' lowpowermode 0')++echo "== reading pmset"+is "lowpowermode 1 is on" 1 "$(mode "$on")"+is "lowpowermode 0 is off" 0 "$(mode "$off")"+is "powermode 1 is on" 1 "$(mode "$(pmset_g ' powermode 1')")"+is "powermode 2 (High Power) is off" 0 "$(mode "$(pmset_g ' powermode 2')")"+is "powermode 0 (Automatic) is off" 0 "$(mode "$(pmset_g ' powermode 0')")"+is "no power mode line is unknown" "" "$(mode "$(pmset_g ' womp 0')")"+is "pmset failing is unknown" "" "$(mode "")"+is "a lowpowermodefoo key is not read" "" "$(mode "$(pmset_g ' lowpowermodefoo 1')")"++echo "== the notice"+rm -f "$mark"+run "$on"+has "Low Power Mode on notifies" "Low Power Mode is on|Games run slower while it is on." "$work/notes"+has "it is logged" "power: Low Power Mode is on" "$work/log"+is "the session is marked" yes "$(marked)"+run "$on"+is "a second launch in the same session says nothing" "" "$(cat "$work/notes")"+has "it is still logged" "power: Low Power Mode is on" "$work/log"+run ""+is "an unknown state says nothing" "" "$(cat "$work/notes" "$work/log")"+is "an unknown state keeps the mark" yes "$(marked)"+run "$off"+is "Low Power Mode off says nothing" "" "$(cat "$work/notes" "$work/log")"+is "Low Power Mode off ends the session" no "$(marked)"+run "$on"+has "the next session notifies again" "Low Power Mode is on|" "$work/notes"++echo "== launches that are not the game"+rm -f "$mark"+run "$on" run+is "install-script helpers say nothing" "" "$(cat "$work/notes" "$work/log")"+is "they leave no mark" no "$(marked)"++echo "== where the mark cannot be written"+: > "$work/notes"+env log="$work/log" notes="$work/notes" np_support="$work/missing" pm="$on" verb=waitforexitandrun \+ body="$body" sh -ec 'eval "$body"; low_power_notice; wait'+is "no support folder says nothing rather than every launch" "" "$(cat "$work/notes")"++echo "== games starting together"+if [ "$locks" = 1 ]; then+ rm -f "$mark"+ run "$off" waitforexitandrun \+ '/usr/bin/lockf -s -t 0 "$np_support/.low-power.lock" true || echo held >> "$notes"'+ is "pmset is read under the lock" held "$(cat "$work/notes")"+ : > "$work/notes"+ env log="$work/log" notes="$work/notes" np_support="$support" pm="$on" verb=waitforexitandrun \+ body="$body" sh -ec 'eval "$body"; low_power_notice; low_power_notice; low_power_notice; wait'+ is "three at once notify once" 1 "$(grep -c 'Low Power Mode is on' "$work/notes")"+ rm -f "$mark"+ /usr/bin/lockf -s -t 0 "$lock" sleep 3 &+ holder=$!+ sleep 1+ run "$on"+ is "a launch that cannot take the lock says nothing" "" "$(cat "$work/notes")"+ is "and leaves no mark" no "$(marked)"+ wait "$holder" || true+ : > "$mark"+ /usr/bin/lockf -s -t 0 "$lock" sleep 3 &+ holder=$!+ sleep 1+ run "$off"+ is "or keeps the mark it found" yes "$(marked)"+ wait "$holder" || true+else+ echo " not run: these need macOS's /usr/bin/lockf"+fi++echo "== the run script"+if grep -qx 'low_power_notice' "$SRC"; then ok "every launch calls it"; else bad "every launch calls it" "low_power_notice" "no call"; fi++[ "$fails" -eq 0 ] || exit 1+if [ "$locks" = 1 ]; then+ echo "==> powernotecheck: Low Power Mode is named once per session, unknown says nothing"+else+ echo "==> powernotecheck: Low Power Mode is named once per session, unknown says nothing (lock cases not run: no /usr/bin/lockf)"+fi