1786892485
This commit is contained in:
@@ -1,20 +1,25 @@
|
|||||||
use slint::Weak;
|
use std::{thread::sleep, time::Duration};
|
||||||
|
|
||||||
use tokio::sync::mpsc::UnboundedSender;
|
use tokio::sync::mpsc::UnboundedSender;
|
||||||
|
|
||||||
use crate::{error::AppError, messages::EventMessage, ui::AppWindow};
|
use crate::{error::AppError, messages::EventMessage};
|
||||||
|
|
||||||
pub async fn battery_listener(
|
pub async fn battery_listener(s2c_tx: UnboundedSender<EventMessage>) -> Result<(), AppError> {
|
||||||
app_weak: Weak<AppWindow>,
|
|
||||||
mut s2c_tx: UnboundedSender<EventMessage>,
|
|
||||||
) -> Result<(), AppError> {
|
|
||||||
let manager = ::battery::Manager::new()?;
|
let manager = ::battery::Manager::new()?;
|
||||||
|
|
||||||
let battery = manager
|
let mut battery = manager
|
||||||
.batteries()?
|
.batteries()?
|
||||||
.next()
|
.next()
|
||||||
.ok_or_else(|| AppError::NoBattery)??;
|
.ok_or_else(|| AppError::NoBattery)??;
|
||||||
|
|
||||||
dbg!(battery);
|
loop {
|
||||||
|
println!("huh?");
|
||||||
|
battery.refresh()?;
|
||||||
|
|
||||||
Ok(())
|
s2c_tx
|
||||||
|
.send(EventMessage::BatteryPercentage(battery.state_of_charge()))
|
||||||
|
.ok();
|
||||||
|
|
||||||
|
sleep(Duration::from_secs(30));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ async fn main() -> Result<(), AppError> {
|
|||||||
|
|
||||||
tokio::spawn({
|
tokio::spawn({
|
||||||
let s2c_tx = s2c_tx.clone();
|
let s2c_tx = s2c_tx.clone();
|
||||||
battery::battery_listener(app.as_weak(), s2c_tx)
|
async move {
|
||||||
|
battery::battery_listener(s2c_tx).await.unwrap();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// listen for data
|
// listen for data
|
||||||
|
|||||||
Reference in New Issue
Block a user