mirror of
https://github.com/arthur-pbty/arthur-os.git
synced 2026-08-01 20:28:16 +02:00
Fix power profile auto-switching on USB-C only machines (#5444)
* Fix power profile auto-switching on USB-C only machines * Small nits * Stick with single unit name --------- Co-authored-by: David Heinemeier Hansson <david@hey.com>
This commit is contained in:
co-authored by
David Heinemeier Hansson
parent
d80c98f025
commit
62f6980852
@@ -1,11 +1,31 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# omarchy:summary=Set the power profile to the requested level, falling back to balanced
|
# omarchy:summary=Set the power profile to the requested level, falling back to balanced
|
||||||
# omarchy:args=<ac|battery>
|
# omarchy:args=[autodetect|ac|battery]
|
||||||
|
|
||||||
|
action="${1-}"
|
||||||
|
|
||||||
|
# Auto-detect when called with no argument: treat any Mains or USB
|
||||||
|
# power-supply device reporting online=1 as "on AC". This handles
|
||||||
|
# USB-C only laptops where the legacy AC device may not fire udev
|
||||||
|
# events, and also avoids false negatives from per-port USB-C devices
|
||||||
|
# that are present-but-empty (online=0) while another port supplies power.
|
||||||
|
if [[ -z $action || $action == "autodetect" ]]; then
|
||||||
|
action=battery
|
||||||
|
for ps in /sys/class/power_supply/*; do
|
||||||
|
[[ -r $ps/online && -r $ps/type ]] || continue
|
||||||
|
type=$(cat "$ps/type")
|
||||||
|
[[ $type == "Mains" || $type == "USB" ]] || continue
|
||||||
|
if [[ $(cat "$ps/online") == "1" ]]; then
|
||||||
|
action=ac
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
mapfile -t profiles < <(powerprofilesctl list | awk '/^\s*[* ]\s*[a-zA-Z0-9\-]+:$/ { gsub(/^[*[:space:]]+|:$/,""); print }')
|
mapfile -t profiles < <(powerprofilesctl list | awk '/^\s*[* ]\s*[a-zA-Z0-9\-]+:$/ { gsub(/^[*[:space:]]+|:$/,""); print }')
|
||||||
|
|
||||||
case "$1" in
|
case "$action" in
|
||||||
ac)
|
ac)
|
||||||
# Prefer performance, fall back to balanced
|
# Prefer performance, fall back to balanced
|
||||||
if [[ " ${profiles[*]} " == *" performance "* ]]; then
|
if [[ " ${profiles[*]} " == *" performance "* ]]; then
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
if omarchy-battery-present; then
|
if omarchy-battery-present; then
|
||||||
cat <<EOF | sudo tee "/etc/udev/rules.d/99-power-profile.rules"
|
cat <<EOF | sudo tee "/etc/udev/rules.d/99-power-profile.rules"
|
||||||
SUBSYSTEM=="power_supply", ATTR{type}=="Mains", ATTR{online}=="0", RUN+="/usr/bin/systemd-run --no-block --collect --unit=omarchy-power-profile-battery --property=After=power-profiles-daemon.service $HOME/.local/share/omarchy/bin/omarchy-powerprofiles-set battery"
|
SUBSYSTEM=="power_supply", ATTR{type}=="Mains", RUN+="/usr/bin/systemd-run --no-block --collect --unit=omarchy-power-profile --property=After=power-profiles-daemon.service $HOME/.local/share/omarchy/bin/omarchy-powerprofiles-set"
|
||||||
SUBSYSTEM=="power_supply", ATTR{type}=="Mains", ATTR{online}=="1", RUN+="/usr/bin/systemd-run --no-block --collect --unit=omarchy-power-profile-ac --property=After=power-profiles-daemon.service $HOME/.local/share/omarchy/bin/omarchy-powerprofiles-set ac"
|
SUBSYSTEM=="power_supply", ATTR{type}=="USB", RUN+="/usr/bin/systemd-run --no-block --collect --unit=omarchy-power-profile --property=After=power-profiles-daemon.service $HOME/.local/share/omarchy/bin/omarchy-powerprofiles-set"
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
# Ensure the daemon is running and starts on boot. The arch package preset
|
||||||
|
# leaves it disabled, which would silently break profile switching.
|
||||||
|
sudo systemctl enable --now power-profiles-daemon
|
||||||
|
|
||||||
sudo udevadm control --reload 2>/dev/null
|
sudo udevadm control --reload 2>/dev/null
|
||||||
sudo udevadm trigger --subsystem-match=power_supply 2>/dev/null
|
sudo udevadm trigger --subsystem-match=power_supply 2>/dev/null
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
echo "Fix power profile auto-switching on USB-C only machines and ensure power-profiles-daemon is enabled"
|
||||||
|
|
||||||
|
source "$OMARCHY_PATH/install/config/powerprofilesctl-rules.sh"
|
||||||
Reference in New Issue
Block a user