Iced port of status area applet
This is based on the GTK version of the status area applet that was previously in this repository. This exposes app indicators found over dbus. As used in applications like nm-applet and steam.
This commit is contained in:
parent
29a2dea760
commit
6a64486163
16 changed files with 1313 additions and 1 deletions
|
|
@ -0,0 +1,58 @@
|
|||
// TODO: Both this and server proxy could emit same events, have way to generate stream from either?
|
||||
|
||||
use cosmic::iced;
|
||||
use futures::StreamExt;
|
||||
|
||||
use crate::subscriptions::status_notifier_item::StatusNotifierItem;
|
||||
|
||||
mod client;
|
||||
mod server;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Event {
|
||||
Connected(zbus::Connection),
|
||||
Registered(StatusNotifierItem),
|
||||
Unregistered(String),
|
||||
Error(String), // XXX
|
||||
}
|
||||
|
||||
enum State {
|
||||
NotConnected,
|
||||
Connected(client::EventStream),
|
||||
Failed,
|
||||
}
|
||||
|
||||
pub fn subscription() -> iced::Subscription<Event> {
|
||||
iced::subscription::unfold(
|
||||
"status-notifier-watcher",
|
||||
State::NotConnected,
|
||||
|state| async move {
|
||||
match state {
|
||||
State::NotConnected => match connect().await {
|
||||
Ok((connection, stream)) => {
|
||||
(Event::Connected(connection), State::Connected(stream))
|
||||
}
|
||||
Err(err) => (Event::Error(err.to_string()), State::Failed),
|
||||
},
|
||||
State::Connected(mut stream) => match stream.next().await {
|
||||
Some(event) => (event, State::Connected(stream)),
|
||||
None => iced::futures::future::pending().await,
|
||||
},
|
||||
State::Failed => iced::futures::future::pending().await,
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
async fn connect() -> zbus::Result<(zbus::Connection, client::EventStream)> {
|
||||
// Connect to session dbus socket
|
||||
let connection = zbus::Connection::session().await?;
|
||||
|
||||
// Start `StatusNotifierWatcher` service, if there isn't one running already
|
||||
server::create_service(&connection).await?;
|
||||
|
||||
// Connect client and listen for registered/unregistered
|
||||
let stream = client::watch(&connection).await?;
|
||||
|
||||
Ok((connection, stream))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue