diff --git a/docs/modules/Networkmanager.md b/docs/modules/Networkmanager.md deleted file mode 100644 index ec3a8fd..0000000 --- a/docs/modules/Networkmanager.md +++ /dev/null @@ -1,74 +0,0 @@ -Displays the current network connection state of NetworkManager. -Supports wired ethernet, wifi, cellular data and VPN connections among others. - -> [!NOTE] -> This module uses NetworkManager's so-called primary connection, and therefore inherits its limitation of only being able to display the "top-level" connection. -> For example, if we have a VPN connection over a wifi connection it will only display the former, until it is disconnected, at which point it will display the latter. -> A solution to this is currently in the works. - -## Configuration - -> Type: `networkmanager` - -| Name | Type | Default | Description | -|-------------|-----------|---------|-------------------------| -| `icon_size` | `integer` | `24` | Size to render icon at. | - -
- JSON - - ```json - { - "end": [ - { - "type": "networkmanager", - "icon_size": 32 - } - ] - } - ``` -
- -
- TOML - - ```toml - [[end]] - type = "networkmanager" - icon_size = 32 - ``` -
- -
- YAML - - ```yaml - end: - - type: "networkmanager" - icon_size: 32 - ``` -
- -
- Corn - - ```corn - { - end = [ - { - type = "networkmanager" - icon_size = 32 - } - ] - } - ``` -
- -## Styling - -| Selector | Description | -|------------------------|----------------------------------| -| `.networkmanager` | NetworkManager widget container. | -| `.networkmanger .icon` | NetworkManager widget icon. | - -For more information on styling, please see the [styling guide](styling-guide). diff --git a/src/clients/mod.rs b/src/clients/mod.rs index d286bdb..b44f0df 100644 --- a/src/clients/mod.rs +++ b/src/clients/mod.rs @@ -12,8 +12,6 @@ pub mod compositor; pub mod lua; #[cfg(feature = "music")] pub mod music; -#[cfg(feature = "networkmanager")] -pub mod networkmanager; #[cfg(feature = "notifications")] pub mod swaync; #[cfg(feature = "tray")] @@ -37,8 +35,6 @@ pub struct Clients { lua: Option>, #[cfg(feature = "music")] music: std::collections::HashMap>, - #[cfg(feature = "networkmanager")] - networkmanager: Option>, #[cfg(feature = "notifications")] notifications: Option>, #[cfg(feature = "tray")] @@ -100,18 +96,6 @@ impl Clients { .clone() } - #[cfg(feature = "networkmanager")] - pub fn networkmanager(&mut self) -> ClientResult { - match &self.networkmanager { - Some(client) => Ok(client.clone()), - None => { - let client = networkmanager::create_client()?; - self.networkmanager = Some(client.clone()); - Ok(client) - } - } - } - #[cfg(feature = "notifications")] pub fn notifications(&mut self) -> ClientResult { let client = match &self.notifications { diff --git a/src/clients/networkmanager.rs b/src/clients/networkmanager.rs deleted file mode 100644 index a1b760f..0000000 --- a/src/clients/networkmanager.rs +++ /dev/null @@ -1,148 +0,0 @@ -use std::sync::Arc; - -use color_eyre::Result; -use futures_signals::signal::{Mutable, MutableSignalCloned}; -use tracing::error; -use zbus::{ - blocking::{fdo::PropertiesProxy, Connection}, - names::InterfaceName, - zvariant::{Error as ZVariantError, ObjectPath, Str}, - Error as ZBusError, -}; - -use crate::{register_fallible_client, spawn_blocking}; - -static DBUS_BUS: &str = "org.freedesktop.NetworkManager"; -static DBUS_PATH: &str = "/org/freedesktop/NetworkManager"; -static DBUS_INTERFACE: &str = "org.freedesktop.NetworkManager"; - -#[derive(Debug)] -pub struct Client { - client_state: Mutable, - interface_name: InterfaceName<'static>, - props_proxy: PropertiesProxy<'static>, -} - -#[derive(Clone, Debug)] -pub enum ClientState { - WiredConnected, - WifiConnected, - CellularConnected, - VpnConnected, - WifiDisconnected, - Offline, - Unknown, -} - -impl Client { - fn new() -> Result { - let client_state = Mutable::new(ClientState::Unknown); - let dbus_connection = Connection::system()?; - let props_proxy = PropertiesProxy::builder(&dbus_connection) - .destination(DBUS_BUS)? - .path(DBUS_PATH)? - .build()?; - let interface_name = InterfaceName::from_static_str(DBUS_INTERFACE)?; - - Ok(Self { - client_state, - interface_name, - props_proxy, - }) - } - - fn run(&self) -> Result<()> { - let props = self.props_proxy.get_all(self.interface_name.clone())?; - let mut primary_connection = props["PrimaryConnection"] - .downcast_ref::() - .ok_or(ZBusError::Variant(ZVariantError::IncorrectType))? - .to_string(); - let mut primary_connection_type = props["PrimaryConnectionType"] - .downcast_ref::() - .ok_or(ZBusError::Variant(ZVariantError::IncorrectType))? - .to_string(); - let mut wireless_enabled = *props["WirelessEnabled"] - .downcast_ref::() - .ok_or(ZBusError::Variant(ZVariantError::IncorrectType))?; - self.client_state.set(determine_state( - &primary_connection, - &primary_connection_type, - wireless_enabled, - )); - - let changed_props_stream = self.props_proxy.receive_properties_changed()?; - for signal in changed_props_stream { - let args = signal.args()?; - if args.interface_name != self.interface_name { - continue; - } - let changed_props = args.changed_properties; - if let Some(new_primary_connection) = changed_props.get("PrimaryConnection") { - let new_primary_connection = new_primary_connection - .downcast_ref::() - .ok_or(ZBusError::Variant(ZVariantError::IncorrectType))?; - primary_connection = new_primary_connection.to_string(); - } - if let Some(new_primary_connection_type) = changed_props.get("PrimaryConnectionType") { - let new_primary_connection_type = new_primary_connection_type - .downcast_ref::() - .ok_or(ZBusError::Variant(ZVariantError::IncorrectType))?; - primary_connection_type = new_primary_connection_type.to_string(); - } - if let Some(new_wireless_enabled) = changed_props.get("WirelessEnabled") { - let new_wireless_enabled = new_wireless_enabled - .downcast_ref::() - .ok_or(ZBusError::Variant(ZVariantError::IncorrectType))?; - wireless_enabled = *new_wireless_enabled; - } - self.client_state.set(determine_state( - &primary_connection, - &primary_connection_type, - wireless_enabled, - )); - } - - Ok(()) - } - - pub fn subscribe(&self) -> MutableSignalCloned { - self.client_state.signal_cloned() - } -} - -pub fn create_client() -> Result> { - let client = Arc::new(Client::new()?); - { - let client = client.clone(); - spawn_blocking(move || { - if let Err(error) = client.run() { - error!("{}", error); - }; - }); - } - Ok(client) -} - -fn determine_state( - primary_connection: &str, - primary_connection_type: &str, - wireless_enabled: bool, -) -> ClientState { - if primary_connection == "/" { - if wireless_enabled { - ClientState::WifiDisconnected - } else { - ClientState::Offline - } - } else { - match primary_connection_type { - "802-3-ethernet" | "adsl" | "pppoe" => ClientState::WiredConnected, - "802-11-olpc-mesh" | "802-11-wireless" | "wifi-p2p" => ClientState::WifiConnected, - "cdma" | "gsm" | "wimax" => ClientState::CellularConnected, - "vpn" | "wireguard" => ClientState::VpnConnected, - _ => ClientState::Unknown, - } - } -} - -register_fallible_client!(Client, networkmanager); diff --git a/src/config/mod.rs b/src/config/mod.rs index 12b7164..e277bac 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -16,8 +16,6 @@ use crate::modules::label::LabelModule; use crate::modules::launcher::LauncherModule; #[cfg(feature = "music")] use crate::modules::music::MusicModule; -#[cfg(feature = "networkmanager")] -use crate::modules::networkmanager::NetworkManagerModule; #[cfg(feature = "notifications")] use crate::modules::notifications::NotificationsModule; use crate::modules::script::ScriptModule; @@ -62,8 +60,6 @@ pub enum ModuleConfig { Launcher(Box), #[cfg(feature = "music")] Music(Box), - #[cfg(feature = "networkmanager")] - NetworkManager(Box), #[cfg(feature = "notifications")] Notifications(Box), Script(Box), @@ -107,8 +103,6 @@ impl ModuleConfig { Self::Launcher(module) => create!(module), #[cfg(feature = "music")] Self::Music(module) => create!(module), - #[cfg(feature = "networkmanager")] - Self::NetworkManager(module) => create!(module), #[cfg(feature = "notifications")] Self::Notifications(module) => create!(module), Self::Script(module) => create!(module), diff --git a/src/modules/mod.rs b/src/modules/mod.rs index 98e272d..2a15252 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -36,8 +36,6 @@ pub mod label; pub mod launcher; #[cfg(feature = "music")] pub mod music; -#[cfg(feature = "networkmanager")] -pub mod networkmanager; #[cfg(feature = "notifications")] pub mod notifications; pub mod script; diff --git a/src/modules/networkmanager.rs b/src/modules/networkmanager.rs deleted file mode 100644 index 972fccb..0000000 --- a/src/modules/networkmanager.rs +++ /dev/null @@ -1,87 +0,0 @@ -use color_eyre::Result; -use futures_lite::StreamExt; -use futures_signals::signal::SignalExt; -use gtk::prelude::ContainerExt; -use gtk::{Box, Image, Orientation}; -use serde::Deserialize; -use tokio::sync::mpsc::Receiver; - -use crate::clients::networkmanager::{Client, ClientState}; -use crate::config::CommonConfig; -use crate::gtk_helpers::IronbarGtkExt; -use crate::image::ImageProvider; -use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext}; -use crate::{glib_recv, module_impl, send_async, spawn}; - -#[derive(Debug, Deserialize, Clone)] -pub struct NetworkManagerModule { - #[serde(default = "default_icon_size")] - icon_size: i32, - - #[serde(flatten)] - pub common: Option, -} - -const fn default_icon_size() -> i32 { - 24 -} - -impl Module for NetworkManagerModule { - type SendMessage = ClientState; - type ReceiveMessage = (); - - fn spawn_controller( - &self, - _: &ModuleInfo, - context: &WidgetContext, - _: Receiver<()>, - ) -> Result<()> { - let client = context.try_client::()?; - let mut client_signal = client.subscribe().to_stream(); - let widget_transmitter = context.tx.clone(); - - spawn(async move { - while let Some(state) = client_signal.next().await { - send_async!(widget_transmitter, ModuleUpdateEvent::Update(state)); - } - }); - - Ok(()) - } - - fn into_widget( - self, - context: WidgetContext, - info: &ModuleInfo, - ) -> Result> { - let container = Box::new(Orientation::Horizontal, 0); - let icon = Image::new(); - icon.add_class("icon"); - container.add(&icon); - - let icon_theme = info.icon_theme.clone(); - - let initial_icon_name = "content-loading-symbolic"; - ImageProvider::parse(initial_icon_name, &icon_theme, false, self.icon_size) - .map(|provider| provider.load_into_image(icon.clone())); - - let widget_receiver = context.subscribe(); - glib_recv!(widget_receiver, state => { - let icon_name = match state { - ClientState::WiredConnected => "network-wired-symbolic", - ClientState::WifiConnected => "network-wireless-symbolic", - ClientState::CellularConnected => "network-cellular-symbolic", - ClientState::VpnConnected => "network-vpn-symbolic", - ClientState::WifiDisconnected => "network-wireless-acquiring-symbolic", - ClientState::Offline => "network-wireless-disabled-symbolic", - ClientState::Unknown => "dialog-question-symbolic", - }; - ImageProvider::parse(icon_name, &icon_theme, false, self.icon_size) - .map(|provider| provider.load_into_image(icon.clone())); - }); - - Ok(ModuleParts::new(container, None)) - } - - module_impl!("networkmanager"); -}