Power: one Protect battery switch (thresholds, charge_types or conservation_mode) #41
No reviewers
Labels
No labels
breadbug
bug
displays
enhancement
keybinds
network
phase-1
power
privacy
recovery
search
snapshots
sound
ui
ux
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Breadway/bos-settings!41
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/battery-protect"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The charge limit control was gated on
charge_control_{start,end}_threshold, so a laptop like the Yoga Slim 7 (which has/sys/class/power_supply/BAT1/charge_types=[Standard] Long_Lifeand ideapadconservation_mode) had no battery protection in the UI.Backend (
power.rs):get_power_infogainsprotection { kind, enabled, limit_pct }; newset_battery_protection(enabled). Mechanism preference:charge_typesthat listsLong_Life:Long_Life/Standard;conservation_mode:1/0.The control hides itself only when none exist.
Privilege. Writes use the existing
pkexec tee <path>pattern (util::run_with_stdin). The path is never accepted from the webview: it is discovered under/sysby the backend and re-validated byvalid_protect_pathright before each write (exact file names,charge_*only under/sys/class/power_supply/,conservation_modeonly under/sys/bus/platform/drivers/ideapad_acpi/, no.., no whitespace). The same check now guards the existingset_charge_threshold. Values come from a fixed table (80,75,100,0,Long_Life,Standard,1,0).Frontend (Power panel, minimal): a "Protect battery" switch in its own group; the switch moves only after the write succeeded, and a refused or cancelled authentication restores it and shows the reason. The threshold sliders stay for hardware that has them.
Tests (9 new): charge_types parsing, detection priority against a fake sysfs tree,
charge_typeswithoutLong_Lifeis not protection, threshold write order, exact fixed-mode values, and the path allowlist (wrong directory for a file name, traversal, other files).Manual test checklist (UI not run, by instruction)
cat /sys/class/power_supply/BAT1/charge_typesshowsStandard [Long_Life](or[Standard] Long_Lifeafter turning it off).Verification:
npm run check(0 errors, 0 warnings),npm run build,cargo fmt --all -- --check,cargo clippy --all-targets --locked -- -D warnings,cargo test --locked(82 passed).Closes BSET-36
Not merged yet: #42 (now on main) and this PR both add imports at the top of
frontend/src/lib/views/Power.svelte(SwitchField+ theBatteryProtectioninterface vsliveGate), and that one hunk is the only conflict.power.rsandlib.rsmerge cleanly. Rebase onto main keeping both imports and theBatteryProtectioninterface, and it is good to merge.Closing: these commits reached main through #46 (feature/settings-v2 was merged into the v2 branch).
Pull request closed