fix(battery): aggregate physical UPower devices - #346
Open
kaiyasi wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR moves the shell to a new shell-specific BatteryService that aggregates physical UPower battery/UPS devices (instead of relying on UPower’s DisplayDevice) and wires it through bootstrap + UI modules.
Changes:
- Introduces
crates/wayle-shell/src/services/battery.rs, aggregating percentage/energy/state/rates/capacity/warnings and charge-threshold capabilities across physical power sources. - Updates shell/bootstrap wiring to initialize the new aggregated battery service.
- Refactors UI modules to import
BatteryServicefromcrate::servicesinstead ofwayle_battery.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/wayle-shell/src/shell/services.rs | Switches shell service container to use the shell’s aggregated BatteryService. |
| crates/wayle-shell/src/shell/bar/modules/battery/watchers.rs | Updates battery module watchers to use crate::services::BatteryService. |
| crates/wayle-shell/src/shell/bar/modules/battery/messages.rs | Updates battery module message/init types to use crate::services::BatteryService. |
| crates/wayle-shell/src/shell/bar/dropdowns/dashboard/messages.rs | Wires dashboard dropdown init to use the new battery service type. |
| crates/wayle-shell/src/shell/bar/dropdowns/dashboard/battery_section/watchers.rs | Updates dashboard battery section watchers to use shell battery service while keeping DeviceState from wayle_battery. |
| crates/wayle-shell/src/shell/bar/dropdowns/dashboard/battery_section/messages.rs | Updates dashboard battery section message/init types to use shell battery service. |
| crates/wayle-shell/src/shell/bar/dropdowns/battery/messages.rs | Updates battery dropdown init types to use shell battery service. |
| crates/wayle-shell/src/shell/bar/dropdowns/battery/battery_section/watchers.rs | Updates battery dropdown section watchers to use shell battery service. |
| crates/wayle-shell/src/shell/bar/dropdowns/battery/battery_section/mod.rs | Updates section module imports to use shell battery service and keep DeviceState/WarningLevel from wayle_battery. |
| crates/wayle-shell/src/shell/bar/dropdowns/battery/battery_section/messages.rs | Updates battery dropdown section init types to use shell battery service. |
| crates/wayle-shell/src/services/mod.rs | Adds services::battery module and re-exports BatteryService (crate-visible). |
| crates/wayle-shell/src/services/battery.rs | New aggregated battery service built from physical UPower devices, with aggregation logic + unit tests. |
| crates/wayle-shell/src/bootstrap/mod.rs | Boots battery service via new bootstrap::battery module (and keeps it optional via try_service!). |
| crates/wayle-shell/src/bootstrap/battery.rs | New helper to build the aggregated battery service. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+172
to
+190
| let mut controlled_devices = 0; | ||
|
|
||
| for device in &self.threshold_devices { | ||
| if !device.is_present.get() { | ||
| continue; | ||
| } | ||
|
|
||
| if !device.charge_threshold_supported.get() { | ||
| return Err(String::from( | ||
| "not all physical batteries support charge thresholds", | ||
| )); | ||
| } | ||
|
|
||
| device | ||
| .enable_charge_threshold(enabled) | ||
| .await | ||
| .map_err(|error| error.to_string())?; | ||
| controlled_devices += 1; | ||
| } |
Comment on lines
+365
to
+367
| fn update_aggregate(aggregate: &BatteryDevice, sources: &[Arc<PhysicalDevice>]) { | ||
| let reading = aggregate_readings(&readings_from_devices(sources)); | ||
| aggregate.percentage.set(reading.percentage); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Validation