refactor: improve and fix subscriptions and async logic

This commit is contained in:
Michael Aaron Murphy 2025-04-10 13:03:53 +02:00 committed by Ashley Wulber
parent 2d2543094e
commit 0600931abf
9 changed files with 290 additions and 269 deletions

View file

@ -1,12 +1,12 @@
use cosmic::iced::{
futures::{channel::mpsc, SinkExt, StreamExt},
Subscription,
futures::{SinkExt, StreamExt, channel::mpsc},
};
use logind_zbus::{
manager::{InhibitType, ManagerProxy},
session::SessionProxy,
};
use std::{any::TypeId, error::Error, os::fd::OwnedFd, sync::Arc};
use std::{any::TypeId, error::Error, os::fd::OwnedFd, sync::Arc, time::Duration};
use zbus::Connection;
use crate::locker::Message;
@ -78,6 +78,9 @@ pub async fn handler(msg_tx: &mut mpsc::Sender<Message>) -> Result<(), Box<dyn E
let mut prepare_for_sleep = manager.receive_prepare_for_sleep().await?;
let mut lock = session.receive_lock().await?;
let mut unlock = session.receive_unlock().await?;
let mut interval = tokio::time::interval(Duration::from_secs(1));
loop {
// Waits until a signal has been received
tokio::select!(
@ -114,5 +117,7 @@ pub async fn handler(msg_tx: &mut mpsc::Sender<Message>) -> Result<(), Box<dyn E
log::info!("logind unlock");
msg_tx.send(Message::Unlock).await?;
});
interval.tick().await;
}
}