refactor: use the cards widget and use peer to peer dbus
This commit is contained in:
parent
c8273f0b4d
commit
c8891c8af9
9 changed files with 357 additions and 269 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use crate::subscriptions::dbus_proxy::NotificationsProxy;
|
||||
use crate::subscriptions::freedesktop_proxy::NotificationsProxy;
|
||||
use cosmic::{
|
||||
iced::{
|
||||
futures::{self, SinkExt},
|
||||
|
|
@ -8,23 +8,25 @@ use cosmic::{
|
|||
};
|
||||
use tokio::sync::mpsc::{channel, Receiver, Sender};
|
||||
use tracing::{error, warn};
|
||||
use zbus::Connection;
|
||||
use zbus::{export::futures_util::StreamExt, Connection};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum State {
|
||||
Ready,
|
||||
WaitingForNotificationEvent(Connection, Receiver<Input>),
|
||||
WaitingForNotificationEvent(NotificationsProxy<'static>, Receiver<Input>),
|
||||
Finished,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum Input {
|
||||
Dismiss(u32),
|
||||
CloseEvent(u32),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Output {
|
||||
Ready(Sender<Input>),
|
||||
CloseEvent(u32),
|
||||
}
|
||||
|
||||
pub fn proxy() -> Subscription<Output> {
|
||||
|
|
@ -45,34 +47,54 @@ pub fn proxy() -> Subscription<Output> {
|
|||
state = State::Finished;
|
||||
continue;
|
||||
};
|
||||
if let Err(err) = output.send(Output::Ready(sender)).await {
|
||||
error!("Failed to send sender: {}", err);
|
||||
state = State::Finished;
|
||||
continue;
|
||||
}
|
||||
|
||||
state = State::WaitingForNotificationEvent(conn, receiver);
|
||||
}
|
||||
State::WaitingForNotificationEvent(conn, rx) => {
|
||||
let Ok(proxy) = NotificationsProxy::new(&conn).await else {
|
||||
error!("Failed to create proxy from session connection");
|
||||
state = State::Finished;
|
||||
continue;
|
||||
};
|
||||
|
||||
match rx.recv().await {
|
||||
Some(Input::Dismiss(id)) => {
|
||||
if let Err(err) = proxy.close_notification(id).await {
|
||||
error!("Failed to close notification: {}", err);
|
||||
}
|
||||
let tx = sender.clone();
|
||||
if let Err(err) = output.send(Output::Ready(sender)).await {
|
||||
error!("Failed to send sender: {}", err);
|
||||
state = State::Finished;
|
||||
continue;
|
||||
}
|
||||
state = match proxy.receive_notification_closed().await {
|
||||
Ok(mut s) => {
|
||||
tokio::spawn(async move {
|
||||
while let Some(msg) = s.next().await {
|
||||
let Ok(id) = msg.args().map(|args| args.id) else {
|
||||
continue;
|
||||
};
|
||||
_ = tx.send(Input::CloseEvent(id)).await;
|
||||
}
|
||||
});
|
||||
State::WaitingForNotificationEvent(proxy, receiver)
|
||||
}
|
||||
None => {
|
||||
warn!("Notification event channel closed");
|
||||
state = State::Finished;
|
||||
continue;
|
||||
Err(err) => {
|
||||
error!(
|
||||
"failed to get a stream of signals for notifications. {}",
|
||||
err
|
||||
);
|
||||
State::Finished
|
||||
}
|
||||
};
|
||||
}
|
||||
State::WaitingForNotificationEvent(proxy, rx) => match rx.recv().await {
|
||||
Some(Input::Dismiss(id)) => {
|
||||
if let Err(err) = proxy.close_notification(id).await {
|
||||
error!("Failed to close notification: {}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(Input::CloseEvent(id)) => {
|
||||
_ = output.send(Output::CloseEvent(id)).await;
|
||||
}
|
||||
None => {
|
||||
warn!("Notification event channel closed");
|
||||
state = State::Finished;
|
||||
continue;
|
||||
}
|
||||
},
|
||||
State::Finished => {
|
||||
let () = futures::future::pending().await;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue