mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-09-15 19:26:58 +02:00
refactor(networkmanager): remove unnecessary async & unused fields
This commit is contained in:
parent
8bb95e2e3f
commit
e6f610687c
5 changed files with 8 additions and 18 deletions
|
@ -190,7 +190,7 @@ impl Clients {
|
|||
if let Some(client) = &self.network_manager {
|
||||
Ok(client.clone())
|
||||
} else {
|
||||
let client = await_sync(async move { networkmanager::create_client().await })?;
|
||||
let client = networkmanager::create_client()?;
|
||||
self.network_manager = Some(client.clone());
|
||||
Ok(client)
|
||||
}
|
||||
|
|
|
@ -8,14 +8,8 @@ use zbus::zvariant::{ObjectPath, OwnedValue, Str};
|
|||
default_path = "/org/freedesktop/NetworkManager"
|
||||
)]
|
||||
pub(super) trait Dbus {
|
||||
#[zbus(property)]
|
||||
fn active_connections(&self) -> Result<Vec<ObjectPath<'_>>>;
|
||||
|
||||
#[zbus(property)]
|
||||
fn all_devices(&self) -> Result<Vec<ObjectPath<'_>>>;
|
||||
|
||||
#[zbus(property)]
|
||||
fn devices(&self) -> Result<Vec<ObjectPath<'_>>>;
|
||||
}
|
||||
|
||||
#[proxy(
|
||||
|
|
|
@ -4,7 +4,6 @@ use crate::clients::networkmanager::dbus::{DeviceState, DeviceType};
|
|||
pub enum Event {
|
||||
DeviceAdded {
|
||||
interface: String,
|
||||
r#type: DeviceType,
|
||||
},
|
||||
DeviceStateChanged {
|
||||
interface: String,
|
||||
|
|
|
@ -7,6 +7,7 @@ use tokio::sync::broadcast;
|
|||
use zbus::Connection;
|
||||
use zbus::zvariant::{ObjectPath, Str};
|
||||
|
||||
use crate::clients::ClientResult;
|
||||
use crate::clients::networkmanager::dbus::{DbusProxy, DeviceDbusProxy};
|
||||
use crate::clients::networkmanager::event::Event;
|
||||
use crate::{register_fallible_client, spawn};
|
||||
|
@ -20,14 +21,12 @@ pub struct Client {
|
|||
}
|
||||
|
||||
impl Client {
|
||||
async fn new() -> Result<Client> {
|
||||
fn new() -> Result<Client> {
|
||||
let (tx, _) = broadcast::channel(64);
|
||||
Ok(Client { tx })
|
||||
}
|
||||
|
||||
async fn run(&self) -> Result<()> {
|
||||
// TODO: Use glib::clone!()
|
||||
|
||||
fn run(&self) -> Result<()> {
|
||||
let tx = self.tx.clone();
|
||||
spawn(async move {
|
||||
let dbus_connection = Connection::system().await?;
|
||||
|
@ -58,14 +57,13 @@ impl Client {
|
|||
}
|
||||
|
||||
pub fn subscribe(&self) -> broadcast::Receiver<Event> {
|
||||
// Maybe we should pass a direct receiver so that the UI module also gets the events from before it was started
|
||||
self.tx.subscribe()
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn create_client() -> Result<Arc<Client>> {
|
||||
let client = Arc::new(Client::new().await?);
|
||||
client.run().await?;
|
||||
pub fn create_client() -> ClientResult<Client> {
|
||||
let client = Arc::new(Client::new()?);
|
||||
client.run()?;
|
||||
Ok(client)
|
||||
}
|
||||
|
||||
|
@ -74,10 +72,8 @@ async fn watch_device(device_path: ObjectPath<'_>, tx: broadcast::Sender<Event>)
|
|||
let device = DeviceDbusProxy::new(&dbus_connection, device_path.to_owned()).await?;
|
||||
|
||||
let interface = device.interface().await?;
|
||||
let device_type = device.device_type().await?;
|
||||
tx.send(Event::DeviceAdded {
|
||||
interface: interface.to_string(),
|
||||
r#type: device_type,
|
||||
})?;
|
||||
|
||||
spawn(watch_device_state(
|
||||
|
|
|
@ -101,6 +101,7 @@ async fn handle_update_events(
|
|||
let icon = icons
|
||||
.get(&interface)
|
||||
.expect("the icon for the interface to be present");
|
||||
// TODO: Make this configurable at runtime
|
||||
let icon_name = get_icon_for_device_state(&r#type, &state);
|
||||
match icon_name {
|
||||
Some(icon_name) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue