mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-07-01 10:41:03 +02:00
refactor: change NetworkManager module and state capitalisation
This commit is contained in:
parent
20a120727a
commit
68ca8da302
2 changed files with 31 additions and 31 deletions
|
@ -15,7 +15,7 @@ use crate::modules::launcher::LauncherModule;
|
||||||
#[cfg(feature = "music")]
|
#[cfg(feature = "music")]
|
||||||
use crate::modules::music::MusicModule;
|
use crate::modules::music::MusicModule;
|
||||||
#[cfg(feature = "networkmanager")]
|
#[cfg(feature = "networkmanager")]
|
||||||
use crate::modules::networkmanager::NetworkmanagerModule;
|
use crate::modules::networkmanager::NetworkManagerModule;
|
||||||
#[cfg(feature = "notifications")]
|
#[cfg(feature = "notifications")]
|
||||||
use crate::modules::notifications::NotificationsModule;
|
use crate::modules::notifications::NotificationsModule;
|
||||||
use crate::modules::script::ScriptModule;
|
use crate::modules::script::ScriptModule;
|
||||||
|
@ -52,7 +52,7 @@ pub enum ModuleConfig {
|
||||||
#[cfg(feature = "music")]
|
#[cfg(feature = "music")]
|
||||||
Music(Box<MusicModule>),
|
Music(Box<MusicModule>),
|
||||||
#[cfg(feature = "networkmanager")]
|
#[cfg(feature = "networkmanager")]
|
||||||
Networkmanager(Box<NetworkmanagerModule>),
|
Networkmanager(Box<NetworkManagerModule>),
|
||||||
#[cfg(feature = "notifications")]
|
#[cfg(feature = "notifications")]
|
||||||
Notifications(Box<NotificationsModule>),
|
Notifications(Box<NotificationsModule>),
|
||||||
Script(Box<ScriptModule>),
|
Script(Box<ScriptModule>),
|
||||||
|
|
|
@ -15,7 +15,7 @@ use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetC
|
||||||
use crate::{glib_recv, send_async, spawn};
|
use crate::{glib_recv, send_async, spawn};
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Clone)]
|
#[derive(Debug, Deserialize, Clone)]
|
||||||
pub struct NetworkmanagerModule {
|
pub struct NetworkManagerModule {
|
||||||
#[serde(default = "default_icon_size")]
|
#[serde(default = "default_icon_size")]
|
||||||
icon_size: i32,
|
icon_size: i32,
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ const fn default_icon_size() -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum NetworkmanagerState {
|
pub enum NetworkManagerState {
|
||||||
Cellular,
|
Cellular,
|
||||||
Offline,
|
Offline,
|
||||||
Unknown,
|
Unknown,
|
||||||
|
@ -38,8 +38,8 @@ pub enum NetworkmanagerState {
|
||||||
WirelessDisconnected,
|
WirelessDisconnected,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Module<gtk::Box> for NetworkmanagerModule {
|
impl Module<gtk::Box> for NetworkManagerModule {
|
||||||
type SendMessage = NetworkmanagerState;
|
type SendMessage = NetworkManagerState;
|
||||||
type ReceiveMessage = ();
|
type ReceiveMessage = ();
|
||||||
|
|
||||||
fn name() -> &'static str {
|
fn name() -> &'static str {
|
||||||
|
@ -49,7 +49,7 @@ impl Module<gtk::Box> for NetworkmanagerModule {
|
||||||
fn spawn_controller(
|
fn spawn_controller(
|
||||||
&self,
|
&self,
|
||||||
_: &ModuleInfo,
|
_: &ModuleInfo,
|
||||||
context: &WidgetContext<NetworkmanagerState, ()>,
|
context: &WidgetContext<NetworkManagerState, ()>,
|
||||||
_: Receiver<()>,
|
_: Receiver<()>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let tx = context.tx.clone();
|
let tx = context.tx.clone();
|
||||||
|
@ -92,7 +92,7 @@ impl Module<gtk::Box> for NetworkmanagerModule {
|
||||||
|
|
||||||
fn into_widget(
|
fn into_widget(
|
||||||
self,
|
self,
|
||||||
context: WidgetContext<NetworkmanagerState, ()>,
|
context: WidgetContext<NetworkManagerState, ()>,
|
||||||
info: &ModuleInfo,
|
info: &ModuleInfo,
|
||||||
) -> Result<ModuleParts<gtk::Box>> {
|
) -> Result<ModuleParts<gtk::Box>> {
|
||||||
let container = gtk::Box::new(Orientation::Horizontal, 0);
|
let container = gtk::Box::new(Orientation::Horizontal, 0);
|
||||||
|
@ -109,13 +109,13 @@ impl Module<gtk::Box> for NetworkmanagerModule {
|
||||||
let rx = context.subscribe();
|
let rx = context.subscribe();
|
||||||
glib_recv!(rx, state => {
|
glib_recv!(rx, state => {
|
||||||
let icon_name = match state {
|
let icon_name = match state {
|
||||||
NetworkmanagerState::Cellular => "network-cellular-symbolic",
|
NetworkManagerState::Cellular => "network-cellular-symbolic",
|
||||||
NetworkmanagerState::Offline => "network-wireless-disabled-symbolic",
|
NetworkManagerState::Offline => "network-wireless-disabled-symbolic",
|
||||||
NetworkmanagerState::Unknown => "dialog-question-symbolic",
|
NetworkManagerState::Unknown => "dialog-question-symbolic",
|
||||||
NetworkmanagerState::Vpn => "network-vpn-symbolic",
|
NetworkManagerState::Vpn => "network-vpn-symbolic",
|
||||||
NetworkmanagerState::Wired => "network-wired-symbolic",
|
NetworkManagerState::Wired => "network-wired-symbolic",
|
||||||
NetworkmanagerState::Wireless => "network-wireless-symbolic",
|
NetworkManagerState::Wireless => "network-wireless-symbolic",
|
||||||
NetworkmanagerState::WirelessDisconnected => "network-wireless-acquiring-symbolic",
|
NetworkManagerState::WirelessDisconnected => "network-wireless-acquiring-symbolic",
|
||||||
};
|
};
|
||||||
ImageProvider::parse(icon_name, &icon_theme, false, self.icon_size)
|
ImageProvider::parse(icon_name, &icon_theme, false, self.icon_size)
|
||||||
.map(|provider| provider.load_into_image(icon.clone()));
|
.map(|provider| provider.load_into_image(icon.clone()));
|
||||||
|
@ -128,7 +128,7 @@ impl Module<gtk::Box> for NetworkmanagerModule {
|
||||||
async fn get_network_state(
|
async fn get_network_state(
|
||||||
nm_proxy: &PropertiesProxy<'_>,
|
nm_proxy: &PropertiesProxy<'_>,
|
||||||
device_interface_name: &InterfaceName<'_>,
|
device_interface_name: &InterfaceName<'_>,
|
||||||
) -> Result<NetworkmanagerState> {
|
) -> Result<NetworkManagerState> {
|
||||||
let properties = nm_proxy.get_all(device_interface_name.clone()).await?;
|
let properties = nm_proxy.get_all(device_interface_name.clone()).await?;
|
||||||
|
|
||||||
let primary_connection_path = properties["PrimaryConnection"]
|
let primary_connection_path = properties["PrimaryConnection"]
|
||||||
|
@ -142,28 +142,28 @@ async fn get_network_state(
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
match primary_connection_type.as_str() {
|
match primary_connection_type.as_str() {
|
||||||
"802-11-olpc-mesh" => Ok(NetworkmanagerState::Wireless),
|
"802-11-olpc-mesh" => Ok(NetworkManagerState::Wireless),
|
||||||
"802-11-wireless" => Ok(NetworkmanagerState::Wireless),
|
"802-11-wireless" => Ok(NetworkManagerState::Wireless),
|
||||||
"802-3-ethernet" => Ok(NetworkmanagerState::Wired),
|
"802-3-ethernet" => Ok(NetworkManagerState::Wired),
|
||||||
"adsl" => Ok(NetworkmanagerState::Wired),
|
"adsl" => Ok(NetworkManagerState::Wired),
|
||||||
"cdma" => Ok(NetworkmanagerState::Cellular),
|
"cdma" => Ok(NetworkManagerState::Cellular),
|
||||||
"gsm" => Ok(NetworkmanagerState::Cellular),
|
"gsm" => Ok(NetworkManagerState::Cellular),
|
||||||
"pppoe" => Ok(NetworkmanagerState::Wired),
|
"pppoe" => Ok(NetworkManagerState::Wired),
|
||||||
"vpn" => Ok(NetworkmanagerState::Vpn),
|
"vpn" => Ok(NetworkManagerState::Vpn),
|
||||||
"wifi-p2p" => Ok(NetworkmanagerState::Wireless),
|
"wifi-p2p" => Ok(NetworkManagerState::Wireless),
|
||||||
"wimax" => Ok(NetworkmanagerState::Cellular),
|
"wimax" => Ok(NetworkManagerState::Cellular),
|
||||||
"wireguard" => Ok(NetworkmanagerState::Vpn),
|
"wireguard" => Ok(NetworkManagerState::Vpn),
|
||||||
"wpan" => Ok(NetworkmanagerState::Wireless),
|
"wpan" => Ok(NetworkManagerState::Wireless),
|
||||||
_ => Ok(NetworkmanagerState::Unknown),
|
_ => Ok(NetworkManagerState::Unknown),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let wireless_enabled = *properties["WirelessEnabled"]
|
let wireless_enabled = *properties["WirelessEnabled"]
|
||||||
.downcast_ref::<bool>()
|
.downcast_ref::<bool>()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
if wireless_enabled {
|
if wireless_enabled {
|
||||||
Ok(NetworkmanagerState::WirelessDisconnected)
|
Ok(NetworkManagerState::WirelessDisconnected)
|
||||||
} else {
|
} else {
|
||||||
Ok(NetworkmanagerState::Offline)
|
Ok(NetworkManagerState::Offline)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue