2024-02-10 17:12:07 +01:00
|
|
|
use color_eyre::Result;
|
|
|
|
use futures_lite::StreamExt;
|
2024-08-04 19:04:15 +02:00
|
|
|
use gtk::prelude::{ContainerExt, WidgetExt};
|
2024-02-10 17:12:07 +01:00
|
|
|
use gtk::{Box as GtkBox, Image, Orientation};
|
|
|
|
use serde::Deserialize;
|
|
|
|
use tokio::sync::mpsc::Receiver;
|
|
|
|
|
2025-08-10 16:37:55 +02:00
|
|
|
use crate::channels::{AsyncSenderExt, BroadcastReceiverExt};
|
|
|
|
use crate::clients::networkmanager::Client;
|
2025-08-14 18:14:31 +02:00
|
|
|
use crate::clients::networkmanager::event::Event;
|
2024-02-10 17:12:07 +01:00
|
|
|
use crate::config::CommonConfig;
|
|
|
|
use crate::gtk_helpers::IronbarGtkExt;
|
|
|
|
use crate::modules::{Module, ModuleInfo, ModuleParts, ModuleUpdateEvent, WidgetContext};
|
2025-08-10 16:37:55 +02:00
|
|
|
use crate::{module_impl, spawn};
|
2024-02-10 17:12:07 +01:00
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Clone)]
|
|
|
|
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
|
|
|
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<GtkBox> for NetworkManagerModule {
|
2025-08-14 18:14:31 +02:00
|
|
|
type SendMessage = Event;
|
2024-02-10 17:12:07 +01:00
|
|
|
type ReceiveMessage = ();
|
|
|
|
|
|
|
|
module_impl!("network_manager");
|
|
|
|
|
|
|
|
fn spawn_controller(
|
|
|
|
&self,
|
2025-08-10 16:37:55 +02:00
|
|
|
_info: &ModuleInfo,
|
2025-08-14 18:14:31 +02:00
|
|
|
context: &WidgetContext<Event, ()>,
|
2025-08-10 16:37:55 +02:00
|
|
|
_rx: Receiver<()>,
|
2024-02-10 17:12:07 +01:00
|
|
|
) -> Result<()> {
|
|
|
|
let client = context.try_client::<Client>()?;
|
2025-08-14 18:14:31 +02:00
|
|
|
// let mut client_signal = client.subscribe().to_stream();
|
|
|
|
// let widget_transmitter = context.tx.clone();
|
2024-02-10 17:12:07 +01:00
|
|
|
|
2025-08-14 18:14:31 +02:00
|
|
|
// spawn(async move {
|
|
|
|
// while let Some(state) = client_signal.next().await {
|
|
|
|
// widget_transmitter
|
|
|
|
// .send_expect(ModuleUpdateEvent::Update(state))
|
|
|
|
// .await;
|
|
|
|
// }
|
|
|
|
// });
|
2024-02-10 17:12:07 +01:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn into_widget(
|
|
|
|
self,
|
2025-08-14 18:14:31 +02:00
|
|
|
context: WidgetContext<Event, ()>,
|
2025-08-10 16:37:55 +02:00
|
|
|
_info: &ModuleInfo,
|
2024-02-10 17:12:07 +01:00
|
|
|
) -> Result<ModuleParts<GtkBox>> {
|
|
|
|
let container = GtkBox::new(Orientation::Horizontal, 0);
|
2024-08-04 19:04:15 +02:00
|
|
|
|
|
|
|
// Wired icon
|
|
|
|
let wired_icon = Image::new();
|
|
|
|
wired_icon.add_class("icon");
|
|
|
|
wired_icon.add_class("wired-icon");
|
|
|
|
container.add(&wired_icon);
|
|
|
|
|
|
|
|
// Wifi icon
|
|
|
|
let wifi_icon = Image::new();
|
|
|
|
wifi_icon.add_class("icon");
|
|
|
|
wifi_icon.add_class("wifi-icon");
|
|
|
|
container.add(&wifi_icon);
|
|
|
|
|
|
|
|
// Cellular icon
|
|
|
|
let cellular_icon = Image::new();
|
|
|
|
cellular_icon.add_class("icon");
|
|
|
|
cellular_icon.add_class("cellular-icon");
|
|
|
|
container.add(&cellular_icon);
|
|
|
|
|
|
|
|
// VPN icon
|
|
|
|
let vpn_icon = Image::new();
|
|
|
|
vpn_icon.add_class("icon");
|
|
|
|
vpn_icon.add_class("vpn-icon");
|
|
|
|
container.add(&vpn_icon);
|
2024-02-10 17:12:07 +01:00
|
|
|
|
2025-08-14 18:14:31 +02:00
|
|
|
context
|
|
|
|
.subscribe()
|
|
|
|
.recv_glib_async((), move |(), event| async {});
|
2024-02-10 17:12:07 +01:00
|
|
|
|
|
|
|
Ok(ModuleParts::new(container, None))
|
|
|
|
}
|
|
|
|
}
|