Skip to content

Commit

Permalink
feat: implement upower module
Browse files Browse the repository at this point in the history
  • Loading branch information
p00f authored and JakeStanger committed Apr 29, 2023
1 parent 1e1d65a commit ad3c171
Show file tree
Hide file tree
Showing 9 changed files with 1,121 additions and 441 deletions.
1,143 changes: 703 additions & 440 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ default = [
"music+all",
"sys_info",
"tray",
"upower",
"workspaces+all"
]

http = ["dep:reqwest"]
upower = ["upower_dbus", "zbus", "futures-lite"]

"config+all" = ["config+json", "config+yaml", "config+toml", "config+corn"]
"config+json" = ["universal-config/json"]
Expand Down Expand Up @@ -88,6 +89,11 @@ sysinfo = { version = "0.28.4", optional = true }
# tray
stray = { version = "0.1.3", optional = true }

# upower
upower_dbus = { version = "0.3.2", optional = true }
futures-lite = { version = "1.12.0", optional = true }
zbus = { version = "3.11.0", optional = true }

# workspaces
swayipc-async = { version = "2.0.1", optional = true }
hyprland = { version = "0.3.1", optional = true }
Expand Down
80 changes: 80 additions & 0 deletions docs/modules/Upower.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
Displays system power information such as the battery percentage, and estimated time to empty.

`TODO: ADD SCREENSHOT`

[//]: # (![Screenshot](https://user-images.githubusercontent.com/5057870/184540521-2278bdec-9742-46f0-9ac2-58a7b6f6ea1d.png))


## Configuration

> Type: `upower`
| Name | Type | Default | Description |
|----------|----------|-----------------|---------------------------------------------------|
| `format` | `string` | `{percentage}%` | Format string to use for the widget button label. |

<details>
<summary>JSON</summary>

```json
{
"end": [
{
"type": "upower",
"format": "{percentage}%"
}
]
}

```

</details>

<details>
<summary>TOML</summary>

```toml
[[end]]
type = "upower"
format = "{percentage}%"
```

</details>

<details>
<summary>YAML</summary>

```yaml
end:
- type: "upower"
format: "{percentage}%"
```
</details>
<details>
<summary>Corn</summary>
```corn
{
end = [
{
type = "upower"
format = "{percentage}%"
}
]
}
```

</details>

## Styling

| Selector | Description |
|---------------------------------|-----------------------------|
| `#upower` | Upower widget container. |
| `#upower #icon` | Upower widget battery icon. |
| `#upower #button` | Upower widget button. |
| `#upower #button #label` | Upower widget button label. |
| `#popup-upower` | Clock popup box. |
| `#popup-upower #upower-details` | Label inside the popup. |
2 changes: 2 additions & 0 deletions src/bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ fn add_modules(
ModuleConfig::SysInfo(mut module) => add_module!(module, id),
#[cfg(feature = "tray")]
ModuleConfig::Tray(mut module) => add_module!(module, id),
#[cfg(feature = "upower")]
ModuleConfig::Upower(mut module) => add_module!(module, id),
#[cfg(feature = "workspaces")]
ModuleConfig::Workspaces(mut module) => add_module!(module, id),
}
Expand Down
2 changes: 2 additions & 0 deletions src/clients/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ pub mod compositor;
pub mod music;
#[cfg(feature = "tray")]
pub mod system_tray;
#[cfg(feature = "upower")]
pub mod upower;
pub mod wayland;
40 changes: 40 additions & 0 deletions src/clients/upower.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use async_once::AsyncOnce;
use lazy_static::lazy_static;
use std::sync::Arc;
use upower_dbus::UPowerProxy;
use zbus::fdo::PropertiesProxy;

lazy_static! {
static ref DISPLAY_PROXY: AsyncOnce<Arc<PropertiesProxy<'static>>> = AsyncOnce::new(async {
let dbus = zbus::Connection::system()
.await
.expect("failed to create connection to system bus");

let device_proxy = UPowerProxy::new(&dbus)
.await
.expect("failed to create upower proxy");

let display_device = device_proxy
.get_display_device()
.await
.unwrap_or_else(|_| panic!("failed to get display device for {device_proxy:?}"));

let path = display_device.path().to_owned();

let proxy = PropertiesProxy::builder(&dbus)
.destination("org.freedesktop.UPower")
.expect("failed to set proxy destination address")
.path(path)
.expect("failed to set proxy path")
.cache_properties(zbus::CacheProperties::No)
.build()
.await
.expect("failed to build proxy");

Arc::new(proxy)
});
}

pub async fn get_display_proxy() -> &'static PropertiesProxy<'static> {
DISPLAY_PROXY.get().await
}
4 changes: 4 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ use crate::modules::script::ScriptModule;
use crate::modules::sysinfo::SysInfoModule;
#[cfg(feature = "tray")]
use crate::modules::tray::TrayModule;
#[cfg(feature = "upower")]
use crate::modules::upower::UpowerModule;
#[cfg(feature = "workspaces")]
use crate::modules::workspaces::WorkspacesModule;
use crate::script::ScriptInput;
Expand Down Expand Up @@ -57,6 +59,8 @@ pub enum ModuleConfig {
SysInfo(Box<SysInfoModule>),
#[cfg(feature = "tray")]
Tray(Box<TrayModule>),
#[cfg(feature = "upower")]
Upower(Box<UpowerModule>),
#[cfg(feature = "workspaces")]
Workspaces(Box<WorkspacesModule>),
}
Expand Down
2 changes: 2 additions & 0 deletions src/modules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub mod script;
pub mod sysinfo;
#[cfg(feature = "tray")]
pub mod tray;
#[cfg(feature = "upower")]
pub mod upower;
#[cfg(feature = "workspaces")]
pub mod workspaces;

Expand Down
Loading

0 comments on commit ad3c171

Please sign in to comment.