Read and set power profiles over D-Bus
This commit is contained in:
1 parent
7e747d18bf
commit
00e6038706
3 files changed
+13
-9
No files matched your search
+10
-7
@@ -8,10 +8,13 @@ if [[ ${1:-} != "" && ${1:-} != "--active-state" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
powerprofilesctl list 2>/dev/null |
|
service=org.freedesktop.UPower.PowerProfiles
|
||||||
awk -v with_state="${1:+1}" '/^\s*[* ]\s*[a-zA-Z0-9-]+:$/ {
|
object=/org/freedesktop/UPower/PowerProfiles
|
||||||
active = ($1 == "*") ? 1 : 0
|
|
||||||
gsub(/^[*[:space:]]+|:$/, "")
|
profiles_json=$(busctl --json=short get-property "$service" "$object" "$service" Profiles 2>/dev/null) || exit 0
|
||||||
print $0 (with_state ? "\t" active : "")
|
active_profile=$(busctl --json=short get-property "$service" "$object" "$service" ActiveProfile 2>/dev/null | jq -r '.data // ""')
|
||||||
}' |
|
|
||||||
tac
|
jq -r --arg active "$active_profile" --arg with_state "${1:+1}" '
|
||||||
|
.data[].Profile.data
|
||||||
|
| if $with_state == "1" then "\(.)\t\(if . == $active then 1 else 0 end)" else . end
|
||||||
|
' <<<"$profiles_json"
|
||||||
+2
-1
@@ -55,7 +55,8 @@ if [[ -z ${profile:-} ]] || ! profile_available "$profile"; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
powerprofilesctl set "$profile" || exit
|
busctl set-property org.freedesktop.UPower.PowerProfiles /org/freedesktop/UPower/PowerProfiles \
|
||||||
|
org.freedesktop.UPower.PowerProfiles ActiveProfile s "$profile" || exit
|
||||||
|
|
||||||
if [[ -n $requested_profile ]]; then
|
if [[ -n $requested_profile ]]; then
|
||||||
mkdir -p "$state_dir"
|
mkdir -p "$state_dir"
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ Item {
|
|||||||
actionFor: function(value) { return "blob-font-set " + Util.shellQuote(value) }
|
actionFor: function(value) { return "blob-font-set " + Util.shellQuote(value) }
|
||||||
},
|
},
|
||||||
"power-profiles": {
|
"power-profiles": {
|
||||||
script: "current=$(powerprofilesctl get 2>/dev/null); blob-power-list 2>/dev/null | while read -r p; do [[ -z $p ]] && continue; printf '%s\\t%s\\t%s\\n' \"$p\" \"$p\" \"$current\"; done",
|
script: "current=$(blob-power-list --active-state 2>/dev/null | awk -F '\\t' '$2 == 1 { print $1 }'); blob-power-list 2>/dev/null | while read -r p; do [[ -z $p ]] && continue; printf '%s\\t%s\\t%s\\n' \"$p\" \"$p\" \"$current\"; done",
|
||||||
icon: "\udb81\udc0b",
|
icon: "\udb81\udc0b",
|
||||||
actionFor: function(value) { return "blob-power-set autodetect " + Util.shellQuote(value) }
|
actionFor: function(value) { return "blob-power-set autodetect " + Util.shellQuote(value) }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user