diff --git a/scripts/fan-profile.sh b/scripts/fan-profile.sh index fe0fd8b..c0308ab 100755 --- a/scripts/fan-profile.sh +++ b/scripts/fan-profile.sh @@ -36,6 +36,19 @@ if [ "$1" = "--menu" ]; then exit fi +if [ -f "$STATE_FILE" ]; then + PROFILE=$(powerprofilesctl get 2>/dev/null) + MAPPED=$(map_profile_to_strategy "$PROFILE" 2>/dev/null) + if [ -n "$MAPPED" ]; then + ACTIVE=$(fw-fanctrl print 2>/dev/null | awk -F"'" '/^Strategy:/{print $2}') + [ "$ACTIVE" != "$MAPPED" ] && fw-fanctrl use "$MAPPED" >/dev/null 2>&1 + printf '{"text": "󰈐 auto", "tooltip": "Auto fan strategy\\nProfile: %s → %s\\nClick to change", "class": "auto"}\n' "$PROFILE" "$MAPPED" + else + printf '{"text": "󰈐 auto (?)", "tooltip": "Auto: power-profiles-daemon unreachable or unknown profile\\nClick to change", "class": "auto"}\n' + fi + exit +fi + OUTPUT=$(fw-fanctrl print 2>/dev/null) CURRENT=$(echo "$OUTPUT" | awk -F"'" '/^Strategy:/{print $2}') SPEED=$(echo "$OUTPUT" | awk '/^Speed:/{print $2}')