diff --git a/src/main.rs b/src/main.rs index 8bddb5c..48368c8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ use iced::font::Weight; use iced::futures::SinkExt; use iced::stream; use iced::widget::image::Handle; -use iced::widget::{container, horizontal_space, image, row, svg, text}; +use iced::widget::{button, container, horizontal_space, image, row, svg, text}; use iced::{ time, Background, Border, Color, Element, Event, Font, Length, Shadow, Subscription, Task, Vector, @@ -92,7 +92,7 @@ struct Panel { } #[to_layer_message] -#[derive(Debug, Clone)] +#[derive(Debug)] enum Message { Launch(usize), Time(DateTime), @@ -100,6 +100,8 @@ enum Message { WorkspaceChange(Vec), ActiveWorkspaceChange(event_listener::WorkspaceEventData), ActiveWindowChange((String, String)), + AddSystemTray(SystemTray), + None, } impl Panel { @@ -143,9 +145,9 @@ impl Panel { system_tray: None, }; - // let sys_task = Task::perform(app.add_sys_tray(), |app| app = app ); + let sys_task = Task::perform(add_sys_tray(), |m| m); - (app, Task::none()) + (app, sys_task) } fn namespace(&self) -> String { String::from("panel") @@ -204,7 +206,9 @@ impl Panel { } Message::ActiveWindowChange(w) => { debug!(?w); - self.active_window = w.0; + self.active_window = + w.0.trim_start_matches("\u{180e}\u{200b}\u{200c}") + .to_string(); let class; if &w.1 == "lw" { class = "LibreWolf"; @@ -225,6 +229,11 @@ impl Panel { debug!(?svg); self.active_window_icon_svg = svg; } + Message::AddSystemTray(system_tray) => { + debug!(?system_tray); + self.system_tray = Some(system_tray); + } + Message::None => {} _ => unreachable!(), } Task::none() @@ -404,10 +413,15 @@ impl Panel { ) .color(Color::parse("#ff6ac1").unwrap()); + let spacer = text!(" | "); + + // let sys_tray = vec![button()] + let row = row!( container(row!(workspaces, icon, window, horizontal_space()).spacing(10)), container(clock), - container(row!(horizontal_space(), disk, cpu, mem, battery).spacing(5)) + container(row!(horizontal_space(), disk, cpu, mem, battery).spacing(5)), + spacer, ) .spacing(5) .padding([0, 20]); @@ -444,18 +458,16 @@ impl Panel { text_color: theme.palette().text, } } +} - async fn add_sys_tray(mut self) -> Self { - let sys_tray = SystemTray::new().await; - match sys_tray { - Ok(s) => { - self.system_tray = Some(s); - } - Err(e) => { - error!(?e, "Sys tray couldn't be initialized") - } +async fn add_sys_tray() -> Message { + let sys_tray = SystemTray::new().await; + match sys_tray { + Ok(s) => Message::AddSystemTray(s), + Err(e) => { + error!(?e, "Sys tray couldn't be initialized"); + Message::None } - self } }