battery: Use upower_dbus instead of including bindings here
This commit is contained in:
parent
df6232090e
commit
4e3eb0a396
6 changed files with 20 additions and 222 deletions
17
Cargo.lock
generated
17
Cargo.lock
generated
|
|
@ -963,6 +963,7 @@ dependencies = [
|
||||||
"tracing-log",
|
"tracing-log",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
"udev",
|
"udev",
|
||||||
|
"upower_dbus",
|
||||||
"zbus 4.2.2",
|
"zbus 4.2.2",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -6057,6 +6058,16 @@ version = "0.2.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
|
checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "upower_dbus"
|
||||||
|
version = "0.3.2"
|
||||||
|
source = "git+https://github.com/pop-os/dbus-settings-bindings?branch=upower#eb5cd58587db538fee38da45d560dc92631b8f99"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"serde_repr",
|
||||||
|
"zbus 4.2.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "url"
|
name = "url"
|
||||||
version = "2.5.0"
|
version = "2.5.0"
|
||||||
|
|
@ -6448,7 +6459,7 @@ dependencies = [
|
||||||
"js-sys",
|
"js-sys",
|
||||||
"log",
|
"log",
|
||||||
"naga",
|
"naga",
|
||||||
"parking_lot 0.12.3",
|
"parking_lot 0.11.2",
|
||||||
"profiling",
|
"profiling",
|
||||||
"raw-window-handle",
|
"raw-window-handle",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
|
|
@ -6475,7 +6486,7 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"naga",
|
"naga",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"parking_lot 0.12.3",
|
"parking_lot 0.11.2",
|
||||||
"profiling",
|
"profiling",
|
||||||
"raw-window-handle",
|
"raw-window-handle",
|
||||||
"rustc-hash",
|
"rustc-hash",
|
||||||
|
|
@ -6515,7 +6526,7 @@ dependencies = [
|
||||||
"naga",
|
"naga",
|
||||||
"objc",
|
"objc",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
"parking_lot 0.12.3",
|
"parking_lot 0.11.2",
|
||||||
"profiling",
|
"profiling",
|
||||||
"range-alloc",
|
"range-alloc",
|
||||||
"raw-window-handle",
|
"raw-window-handle",
|
||||||
|
|
|
||||||
|
|
@ -19,3 +19,5 @@ tracing-subscriber.workspace = true
|
||||||
tracing.workspace = true
|
tracing.workspace = true
|
||||||
udev = "0.8"
|
udev = "0.8"
|
||||||
zbus.workspace = true
|
zbus.workspace = true
|
||||||
|
# TODO branch
|
||||||
|
upower_dbus = { git = "https://github.com/pop-os/dbus-settings-bindings", branch = "upower" }
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ mod backend;
|
||||||
mod config;
|
mod config;
|
||||||
mod dgpu;
|
mod dgpu;
|
||||||
mod localize;
|
mod localize;
|
||||||
mod upower;
|
|
||||||
mod upower_device;
|
mod upower_device;
|
||||||
mod upower_kbdbacklight;
|
mod upower_kbdbacklight;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
//! # DBus interface proxy for: `org.freedesktop.UPower`
|
|
||||||
//!
|
|
||||||
//! This code was generated by `zbus-xmlgen` `2.0.1` from DBus introspection data.
|
|
||||||
//! Source: `Interface '/org/freedesktop/UPower' from service 'org.freedesktop.UPower' on system bus`.
|
|
||||||
|
|
||||||
use zbus::proxy;
|
|
||||||
|
|
||||||
#[proxy(
|
|
||||||
default_service = "org.freedesktop.UPower",
|
|
||||||
interface = "org.freedesktop.UPower",
|
|
||||||
default_path = "/org/freedesktop/UPower"
|
|
||||||
)]
|
|
||||||
trait UPower {
|
|
||||||
/// EnumerateDevices method
|
|
||||||
fn enumerate_devices(&self) -> zbus::Result<Vec<zbus::zvariant::OwnedObjectPath>>;
|
|
||||||
|
|
||||||
/// GetCriticalAction method
|
|
||||||
fn get_critical_action(&self) -> zbus::Result<String>;
|
|
||||||
|
|
||||||
/// GetDisplayDevice method
|
|
||||||
fn get_display_device(&self) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;
|
|
||||||
|
|
||||||
/// DeviceAdded signal
|
|
||||||
#[zbus(signal)]
|
|
||||||
fn device_added(&self, device: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>;
|
|
||||||
|
|
||||||
/// DeviceRemoved signal
|
|
||||||
#[zbus(signal)]
|
|
||||||
fn device_removed(&self, device: zbus::zvariant::ObjectPath<'_>) -> zbus::Result<()>;
|
|
||||||
|
|
||||||
/// DaemonVersion property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn daemon_version(&self) -> zbus::Result<String>;
|
|
||||||
|
|
||||||
/// LidIsClosed property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn lid_is_closed(&self) -> zbus::Result<bool>;
|
|
||||||
|
|
||||||
/// LidIsPresent property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn lid_is_present(&self) -> zbus::Result<bool>;
|
|
||||||
|
|
||||||
/// OnBattery property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn on_battery(&self) -> zbus::Result<bool>;
|
|
||||||
}
|
|
||||||
|
|
@ -10,148 +10,8 @@ use cosmic::iced::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::{fmt::Debug, hash::Hash};
|
use std::{fmt::Debug, hash::Hash};
|
||||||
use zbus::proxy;
|
|
||||||
|
|
||||||
use crate::upower::UPowerProxy;
|
use upower_dbus::{BatteryType, DeviceProxy, UPowerProxy};
|
||||||
#[proxy(
|
|
||||||
default_service = "org.freedesktop.UPower",
|
|
||||||
interface = "org.freedesktop.UPower.Device"
|
|
||||||
)]
|
|
||||||
trait Device {
|
|
||||||
/// GetHistory method
|
|
||||||
fn get_history(
|
|
||||||
&self,
|
|
||||||
type_: &str,
|
|
||||||
timespan: u32,
|
|
||||||
resolution: u32,
|
|
||||||
) -> zbus::Result<Vec<(u32, f64, u32)>>;
|
|
||||||
|
|
||||||
/// GetStatistics method
|
|
||||||
fn get_statistics(&self, type_: &str) -> zbus::Result<Vec<(f64, f64)>>;
|
|
||||||
|
|
||||||
/// Refresh method
|
|
||||||
fn refresh(&self) -> zbus::Result<()>;
|
|
||||||
|
|
||||||
/// BatteryLevel property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn battery_level(&self) -> zbus::Result<u32>;
|
|
||||||
|
|
||||||
/// Capacity property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn capacity(&self) -> zbus::Result<f64>;
|
|
||||||
|
|
||||||
/// ChargeCycles property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn charge_cycles(&self) -> zbus::Result<i32>;
|
|
||||||
|
|
||||||
/// Energy property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn energy(&self) -> zbus::Result<f64>;
|
|
||||||
|
|
||||||
/// EnergyEmpty property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn energy_empty(&self) -> zbus::Result<f64>;
|
|
||||||
|
|
||||||
/// EnergyFull property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn energy_full(&self) -> zbus::Result<f64>;
|
|
||||||
|
|
||||||
/// EnergyFullDesign property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn energy_full_design(&self) -> zbus::Result<f64>;
|
|
||||||
|
|
||||||
/// EnergyRate property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn energy_rate(&self) -> zbus::Result<f64>;
|
|
||||||
|
|
||||||
/// HasHistory property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn has_history(&self) -> zbus::Result<bool>;
|
|
||||||
|
|
||||||
/// HasStatistics property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn has_statistics(&self) -> zbus::Result<bool>;
|
|
||||||
|
|
||||||
/// IconName property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn icon_name(&self) -> zbus::Result<String>;
|
|
||||||
|
|
||||||
/// IsPresent property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn is_present(&self) -> zbus::Result<bool>;
|
|
||||||
|
|
||||||
/// IsRechargeable property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn is_rechargeable(&self) -> zbus::Result<bool>;
|
|
||||||
|
|
||||||
/// Luminosity property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn luminosity(&self) -> zbus::Result<f64>;
|
|
||||||
|
|
||||||
/// Model property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn model(&self) -> zbus::Result<String>;
|
|
||||||
|
|
||||||
/// NativePath property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn native_path(&self) -> zbus::Result<String>;
|
|
||||||
|
|
||||||
/// Online property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn online(&self) -> zbus::Result<bool>;
|
|
||||||
|
|
||||||
/// Percentage property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn percentage(&self) -> zbus::Result<f64>;
|
|
||||||
|
|
||||||
/// PowerSupply property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn power_supply(&self) -> zbus::Result<bool>;
|
|
||||||
|
|
||||||
/// Serial property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn serial(&self) -> zbus::Result<String>;
|
|
||||||
|
|
||||||
/// State property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn state(&self) -> zbus::Result<u32>;
|
|
||||||
|
|
||||||
/// Technology property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn technology(&self) -> zbus::Result<u32>;
|
|
||||||
|
|
||||||
/// Temperature property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn temperature(&self) -> zbus::Result<f64>;
|
|
||||||
|
|
||||||
/// TimeToEmpty property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn time_to_empty(&self) -> zbus::Result<i64>;
|
|
||||||
|
|
||||||
/// TimeToFull property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn time_to_full(&self) -> zbus::Result<i64>;
|
|
||||||
|
|
||||||
/// Type property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn type_(&self) -> zbus::Result<u32>;
|
|
||||||
|
|
||||||
/// UpdateTime property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn update_time(&self) -> zbus::Result<u64>;
|
|
||||||
|
|
||||||
/// Vendor property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn vendor(&self) -> zbus::Result<String>;
|
|
||||||
|
|
||||||
/// Voltage property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn voltage(&self) -> zbus::Result<f64>;
|
|
||||||
|
|
||||||
/// WarningLevel property
|
|
||||||
#[zbus(property)]
|
|
||||||
fn warning_level(&self) -> zbus::Result<u32>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn device_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>(
|
pub fn device_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>(
|
||||||
id: I,
|
id: I,
|
||||||
|
|
@ -176,12 +36,7 @@ async fn display_device() -> zbus::Result<(UPowerProxy<'static>, DeviceProxy<'st
|
||||||
let connection = zbus::Connection::system().await?;
|
let connection = zbus::Connection::system().await?;
|
||||||
let upower: UPowerProxy<'_> = UPowerProxy::new(&connection).await?;
|
let upower: UPowerProxy<'_> = UPowerProxy::new(&connection).await?;
|
||||||
let device_path = upower.get_display_device().await?;
|
let device_path = upower.get_display_device().await?;
|
||||||
DeviceProxy::builder(&connection)
|
Ok((upower, device_path))
|
||||||
.path(device_path)?
|
|
||||||
.cache_properties(zbus::CacheProperties::Yes)
|
|
||||||
.build()
|
|
||||||
.await
|
|
||||||
.map(|dp| (upower, dp))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn start_listening(
|
async fn start_listening(
|
||||||
|
|
@ -201,7 +56,7 @@ async fn start_listening(
|
||||||
let Ok(d) = d.build().await else {
|
let Ok(d) = d.build().await else {
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
if d.type_().await.unwrap_or_default() == 2
|
if d.type_().await == Ok(BatteryType::Battery)
|
||||||
&& d.power_supply().await.unwrap_or_default()
|
&& d.power_supply().await.unwrap_or_default()
|
||||||
{
|
{
|
||||||
has_battery = true;
|
has_battery = true;
|
||||||
|
|
|
||||||
|
|
@ -6,31 +6,8 @@
|
||||||
use cosmic::iced::{self, futures::SinkExt, subscription};
|
use cosmic::iced::{self, futures::SinkExt, subscription};
|
||||||
use std::{fmt::Debug, hash::Hash};
|
use std::{fmt::Debug, hash::Hash};
|
||||||
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
|
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender};
|
||||||
use zbus::proxy;
|
|
||||||
|
|
||||||
#[proxy(
|
use upower_dbus::KbdBacklightProxy;
|
||||||
default_service = "org.freedesktop.UPower",
|
|
||||||
interface = "org.freedesktop.UPower.KbdBacklight",
|
|
||||||
default_path = "/org/freedesktop/UPower/KbdBacklight"
|
|
||||||
)]
|
|
||||||
trait KbdBacklight {
|
|
||||||
/// GetBrightness method
|
|
||||||
fn get_brightness(&self) -> zbus::Result<i32>;
|
|
||||||
|
|
||||||
/// GetMaxBrightness method
|
|
||||||
fn get_max_brightness(&self) -> zbus::Result<i32>;
|
|
||||||
|
|
||||||
/// SetBrightness method
|
|
||||||
fn set_brightness(&self, value: i32) -> zbus::Result<()>;
|
|
||||||
|
|
||||||
/// BrightnessChanged signal
|
|
||||||
#[zbus(signal)]
|
|
||||||
fn brightness_changed(&self, value: i32) -> zbus::Result<()>;
|
|
||||||
|
|
||||||
/// BrightnessChangedWithSource signal
|
|
||||||
#[zbus(signal)]
|
|
||||||
fn brightness_changed_with_source(&self, value: i32, source: &str) -> zbus::Result<()>;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn kbd_backlight_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>(
|
pub fn kbd_backlight_subscription<I: 'static + Hash + Copy + Send + Sync + Debug>(
|
||||||
id: I,
|
id: I,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue