feat(bar): add more logging around error paths

This commit is contained in:
LGUG2Z
2024-10-09 15:06:48 -07:00
parent c57759242a
commit bc00f54c90
2 changed files with 102 additions and 86 deletions

View File

@@ -5,6 +5,7 @@ use crate::widget::BarWidget;
use crate::MAX_LABEL_WIDTH; use crate::MAX_LABEL_WIDTH;
use crate::WIDGET_SPACING; use crate::WIDGET_SPACING;
use crossbeam_channel::Receiver; use crossbeam_channel::Receiver;
use crossbeam_channel::TryRecvError;
use eframe::egui::text::LayoutJob; use eframe::egui::text::LayoutJob;
use eframe::egui::Color32; use eframe::egui::Color32;
use eframe::egui::ColorImage; use eframe::egui::ColorImage;
@@ -437,93 +438,105 @@ impl KomorebiNotificationState {
rx_gui: Receiver<komorebi_client::Notification>, rx_gui: Receiver<komorebi_client::Notification>,
bg_color: Rc<RefCell<Color32>>, bg_color: Rc<RefCell<Color32>>,
) { ) {
if let Ok(notification) = rx_gui.try_recv() { match rx_gui.try_recv() {
if let NotificationEvent::Socket(SocketMessage::ReloadStaticConfiguration(path)) = Err(error) => match error {
notification.event TryRecvError::Empty => {}
{ TryRecvError::Disconnected => {
if let Ok(config) = komorebi_client::StaticConfig::read(&path) { tracing::error!(
if let Some(theme) = config.theme { "failed to receive komorebi notification on gui thread: {error}"
apply_theme(ctx, KomobarTheme::from(theme), bg_color); );
tracing::info!("applied theme from updated komorebi.json"); }
},
Ok(notification) => {
if let NotificationEvent::Socket(SocketMessage::ReloadStaticConfiguration(path)) =
notification.event
{
if let Ok(config) = komorebi_client::StaticConfig::read(&path) {
if let Some(theme) = config.theme {
apply_theme(ctx, KomobarTheme::from(theme), bg_color);
tracing::info!("applied theme from updated komorebi.json");
}
} }
} }
}
self.mouse_follows_focus = notification.state.mouse_follows_focus; self.mouse_follows_focus = notification.state.mouse_follows_focus;
let monitor = &notification.state.monitors.elements()[monitor_index]; let monitor = &notification.state.monitors.elements()[monitor_index];
self.work_area_offset = self.work_area_offset =
notification.state.monitors.elements()[monitor_index].work_area_offset(); notification.state.monitors.elements()[monitor_index].work_area_offset();
let focused_workspace_idx = monitor.focused_workspace_idx(); let focused_workspace_idx = monitor.focused_workspace_idx();
let mut workspaces = vec![]; let mut workspaces = vec![];
self.selected_workspace = monitor.workspaces()[focused_workspace_idx] self.selected_workspace = monitor.workspaces()[focused_workspace_idx]
.name() .name()
.to_owned() .to_owned()
.unwrap_or_else(|| format!("{}", focused_workspace_idx + 1)); .unwrap_or_else(|| format!("{}", focused_workspace_idx + 1));
for (i, ws) in monitor.workspaces().iter().enumerate() { for (i, ws) in monitor.workspaces().iter().enumerate() {
let should_add = if self.hide_empty_workspaces { let should_add = if self.hide_empty_workspaces {
focused_workspace_idx == i || !ws.containers().is_empty() focused_workspace_idx == i || !ws.containers().is_empty()
} else { } else {
true true
};
if should_add {
workspaces
.push(ws.name().to_owned().unwrap_or_else(|| format!("{}", i + 1)));
}
}
self.workspaces = workspaces;
self.layout = match monitor.workspaces()[focused_workspace_idx].layout() {
komorebi_client::Layout::Default(layout) => KomorebiLayout::Default(*layout),
komorebi_client::Layout::Custom(_) => KomorebiLayout::Custom,
}; };
if should_add { if !*monitor.workspaces()[focused_workspace_idx].tile() {
workspaces.push(ws.name().to_owned().unwrap_or_else(|| format!("{}", i + 1))); self.layout = KomorebiLayout::Floating;
} }
}
self.workspaces = workspaces; if notification.state.is_paused {
self.layout = match monitor.workspaces()[focused_workspace_idx].layout() { self.layout = KomorebiLayout::Paused;
komorebi_client::Layout::Default(layout) => KomorebiLayout::Default(*layout), }
komorebi_client::Layout::Custom(_) => KomorebiLayout::Custom,
};
if !*monitor.workspaces()[focused_workspace_idx].tile() { if let Some(container) =
self.layout = KomorebiLayout::Floating; monitor.workspaces()[focused_workspace_idx].monocle_container()
} {
self.focused_container_information = (
if notification.state.is_paused { container
self.layout = KomorebiLayout::Paused; .windows()
} .iter()
.map(|w| w.title().unwrap_or_default())
if let Some(container) = monitor.workspaces()[focused_workspace_idx].monocle_container() .collect::<Vec<_>>(),
{ container
self.focused_container_information = ( .windows()
container .iter()
.windows() .map(|w| windows_icons::get_icon_by_process_id(w.process_id()))
.iter() .collect::<Vec<_>>(),
.map(|w| w.title().unwrap_or_default()) container.focused_window_idx(),
.collect::<Vec<_>>(), );
container } else if let Some(container) =
.windows() monitor.workspaces()[focused_workspace_idx].focused_container()
.iter() {
.map(|w| windows_icons::get_icon_by_process_id(w.process_id())) self.focused_container_information = (
.collect::<Vec<_>>(), container
container.focused_window_idx(), .windows()
); .iter()
} else if let Some(container) = .map(|w| w.title().unwrap_or_default())
monitor.workspaces()[focused_workspace_idx].focused_container() .collect::<Vec<_>>(),
{ container
self.focused_container_information = ( .windows()
container .iter()
.windows() .map(|w| windows_icons::get_icon_by_process_id(w.process_id()))
.iter() .collect::<Vec<_>>(),
.map(|w| w.title().unwrap_or_default()) container.focused_window_idx(),
.collect::<Vec<_>>(), );
container } else {
.windows() self.focused_container_information.0.clear();
.iter() self.focused_container_information.1.clear();
.map(|w| windows_icons::get_icon_by_process_id(w.process_id())) self.focused_container_information.2 = 0;
.collect::<Vec<_>>(), }
container.focused_window_idx(),
);
} else {
self.focused_container_information.0.clear();
self.focused_container_information.1.clear();
self.focused_container_information.2 = 0;
} }
} }
} }

View File

@@ -1,7 +1,7 @@
mod bar; mod bar;
mod cpu;
mod battery; mod battery;
mod config; mod config;
mod cpu;
mod date; mod date;
mod komorebi; mod komorebi;
mod media; mod media;
@@ -370,18 +370,21 @@ fn main() -> color_eyre::Result<()> {
match String::from_utf8(buffer) { match String::from_utf8(buffer) {
Ok(notification_string) => { Ok(notification_string) => {
if let Ok(notification) = match serde_json::from_str::<komorebi_client::Notification>(
serde_json::from_str::<komorebi_client::Notification>( &notification_string,
&notification_string, ) {
) Ok(notification) => {
{ tracing::debug!("received notification from komorebi");
tracing::debug!("received notification from komorebi");
if let Err(error) = tx_gui.send(notification) { if let Err(error) = tx_gui.send(notification) {
tracing::error!("could not send komorebi notification update to gui: {error}") tracing::error!("could not send komorebi notification update to gui thread: {error}")
}
ctx_komorebi.request_repaint();
}
Err(error) => {
tracing::error!("could not deserialize komorebi notification: {error}");
} }
ctx_komorebi.request_repaint();
} }
} }
Err(error) => { Err(error) => {