mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-04-19 11:24:24 +02:00
fix: revert inclusion of networkmanager module
This commit is contained in:
parent
9ea49202b3
commit
4788031f5f
6 changed files with 0 additions and 333 deletions
|
@ -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. |
|
||||
|
||||
<details>
|
||||
<summary>JSON</summary>
|
||||
|
||||
```json
|
||||
{
|
||||
"end": [
|
||||
{
|
||||
"type": "networkmanager",
|
||||
"icon_size": 32
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>TOML</summary>
|
||||
|
||||
```toml
|
||||
[[end]]
|
||||
type = "networkmanager"
|
||||
icon_size = 32
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>YAML</summary>
|
||||
|
||||
```yaml
|
||||
end:
|
||||
- type: "networkmanager"
|
||||
icon_size: 32
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary>Corn</summary>
|
||||
|
||||
```corn
|
||||
{
|
||||
end = [
|
||||
{
|
||||
type = "networkmanager"
|
||||
icon_size = 32
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
## Styling
|
||||
|
||||
| Selector | Description |
|
||||
|------------------------|----------------------------------|
|
||||
| `.networkmanager` | NetworkManager widget container. |
|
||||
| `.networkmanger .icon` | NetworkManager widget icon. |
|
||||
|
||||
For more information on styling, please see the [styling guide](styling-guide).
|
|
@ -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<Rc<lua::LuaEngine>>,
|
||||
#[cfg(feature = "music")]
|
||||
music: std::collections::HashMap<music::ClientType, Arc<dyn music::MusicClient>>,
|
||||
#[cfg(feature = "networkmanager")]
|
||||
networkmanager: Option<Arc<networkmanager::Client>>,
|
||||
#[cfg(feature = "notifications")]
|
||||
notifications: Option<Arc<swaync::Client>>,
|
||||
#[cfg(feature = "tray")]
|
||||
|
@ -100,18 +96,6 @@ impl Clients {
|
|||
.clone()
|
||||
}
|
||||
|
||||
#[cfg(feature = "networkmanager")]
|
||||
pub fn networkmanager(&mut self) -> ClientResult<networkmanager::Client> {
|
||||
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<swaync::Client> {
|
||||
let client = match &self.notifications {
|
||||
|
|
|
@ -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<ClientState>,
|
||||
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<Self> {
|
||||
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::<ObjectPath>()
|
||||
.ok_or(ZBusError::Variant(ZVariantError::IncorrectType))?
|
||||
.to_string();
|
||||
let mut primary_connection_type = props["PrimaryConnectionType"]
|
||||
.downcast_ref::<Str>()
|
||||
.ok_or(ZBusError::Variant(ZVariantError::IncorrectType))?
|
||||
.to_string();
|
||||
let mut wireless_enabled = *props["WirelessEnabled"]
|
||||
.downcast_ref::<bool>()
|
||||
.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::<ObjectPath>()
|
||||
.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::<Str>()
|
||||
.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::<bool>()
|
||||
.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<ClientState> {
|
||||
self.client_state.signal_cloned()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_client() -> Result<Arc<Client>> {
|
||||
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);
|
|
@ -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<LauncherModule>),
|
||||
#[cfg(feature = "music")]
|
||||
Music(Box<MusicModule>),
|
||||
#[cfg(feature = "networkmanager")]
|
||||
NetworkManager(Box<NetworkManagerModule>),
|
||||
#[cfg(feature = "notifications")]
|
||||
Notifications(Box<NotificationsModule>),
|
||||
Script(Box<ScriptModule>),
|
||||
|
@ -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),
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<CommonConfig>,
|
||||
}
|
||||
|
||||
const fn default_icon_size() -> i32 {
|
||||
24
|
||||
}
|
||||
|
||||
impl Module<Box> for NetworkManagerModule {
|
||||
type SendMessage = ClientState;
|
||||
type ReceiveMessage = ();
|
||||
|
||||
fn spawn_controller(
|
||||
&self,
|
||||
_: &ModuleInfo,
|
||||
context: &WidgetContext<ClientState, ()>,
|
||||
_: Receiver<()>,
|
||||
) -> Result<()> {
|
||||
let client = context.try_client::<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<ClientState, ()>,
|
||||
info: &ModuleInfo,
|
||||
) -> Result<ModuleParts<Box>> {
|
||||
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");
|
||||
}
|
Loading…
Add table
Reference in a new issue