Add battery percentage toggle to power widget

This commit is contained in:
David Heinemeier Hansson
2026-08-01 12:58:45 -07:00
parent 3d59f9127e
commit 3ffd9cdfc5
3 changed files with 22 additions and 3 deletions
+6
View File
@@ -5,7 +5,9 @@ set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
run_node_test <<'JS'
const fs = require('fs')
const power = requireFromRoot('shell/plugins/panels/power/Model.js')
const panelSource = fs.readFileSync(root + '/shell/plugins/panels/power/Panel.qml', 'utf8')
const states = { Charging: 1, Discharging: 2, FullyCharged: 3, PendingCharge: 4 }
assertEqual(power.selectProfileIndex(0, 1, ['balanced', 'performance']), 1, 'power advances profile selection')
@@ -39,4 +41,8 @@ assertEqual(
power.batteryIcon({ isPresent: true, percentage: 0.4, state: states.Discharging }, true, states),
'power shows battery icon when unplugged before battery state refreshes'
)
assert(/if \(b === Qt\.RightButton\) root\.togglePercentage\(\)/.test(panelSource), 'power right click toggles the bar percentage')
assert(/Object\.assign\([^\n]+showPercentage: !root\.showPercentage[^\n]+\)[\s\S]*updateEntryInline/.test(panelSource), 'power persists the bar percentage setting')
assert(/Math\.round\(root\.batteryFraction \* 100\) \+ "% " \+ root\.batteryIcon\(\)/.test(panelSource), 'power places the percentage before the battery icon')
JS