1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-07-01 02:31:04 +02:00

refactor: standardise error messages

This commit is contained in:
Jake Stanger 2022-12-11 21:31:45 +00:00
parent fd2d7e5c7a
commit 9d5049dde0
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
19 changed files with 117 additions and 110 deletions

View file

@ -4,7 +4,7 @@ use crate::dynamic_string::DynamicString;
use crate::modules::{Module, ModuleInfo, ModuleLocation, ModuleUpdateEvent, WidgetContext}; use crate::modules::{Module, ModuleInfo, ModuleLocation, ModuleUpdateEvent, WidgetContext};
use crate::popup::Popup; use crate::popup::Popup;
use crate::script::{OutputStream, Script}; use crate::script::{OutputStream, Script};
use crate::{await_sync, Config}; use crate::{await_sync, error as err, Config};
use color_eyre::Result; use color_eyre::Result;
use gtk::gdk::Monitor; use gtk::gdk::Monitor;
use gtk::prelude::*; use gtk::prelude::*;
@ -253,7 +253,7 @@ where
fn register_popup_content(popup: &Arc<RwLock<Popup>>, id: usize, popup_content: gtk::Box) { fn register_popup_content(popup: &Arc<RwLock<Popup>>, id: usize, popup_content: gtk::Box) {
popup popup
.write() .write()
.expect("Failed to get write lock on popup") .expect(err::ERR_WRITE_LOCK)
.register_content(id, popup_content); .register_content(id, popup_content);
} }
@ -277,15 +277,14 @@ fn setup_receiver<TSend>(
match ev { match ev {
ModuleUpdateEvent::Update(update) => { ModuleUpdateEvent::Update(update) => {
if has_popup { if has_popup {
p_tx.send(update.clone()) p_tx.send(update.clone()).expect(err::ERR_CHANNEL_SEND);
.expect("Failed to send update to popup");
} }
w_tx.send(update).expect("Failed to send update to widget"); w_tx.send(update).expect(err::ERR_CHANNEL_SEND);
} }
ModuleUpdateEvent::TogglePopup(geometry) => { ModuleUpdateEvent::TogglePopup(geometry) => {
debug!("Toggling popup for {} [#{}]", name, id); debug!("Toggling popup for {} [#{}]", name, id);
let popup = popup.read().expect("Failed to get read lock on popup"); let popup = popup.read().expect(err::ERR_READ_LOCK);
if popup.is_visible() { if popup.is_visible() {
popup.hide(); popup.hide();
} else { } else {
@ -296,7 +295,7 @@ fn setup_receiver<TSend>(
ModuleUpdateEvent::OpenPopup(geometry) => { ModuleUpdateEvent::OpenPopup(geometry) => {
debug!("Opening popup for {} [#{}]", name, id); debug!("Opening popup for {} [#{}]", name, id);
let popup = popup.read().expect("Failed to get read lock on popup"); let popup = popup.read().expect(err::ERR_READ_LOCK);
popup.hide(); popup.hide();
popup.show_content(id); popup.show_content(id);
popup.show(geometry); popup.show(geometry);
@ -304,7 +303,7 @@ fn setup_receiver<TSend>(
ModuleUpdateEvent::ClosePopup => { ModuleUpdateEvent::ClosePopup => {
debug!("Closing popup for {} [#{}]", name, id); debug!("Closing popup for {} [#{}]", name, id);
let popup = popup.read().expect("Failed to get read lock on popup"); let popup = popup.read().expect(err::ERR_READ_LOCK);
popup.hide(); popup.hide();
} }
} }
@ -334,8 +333,7 @@ fn setup_module_common_options(container: EventBox, common: CommonConfig) {
spawn(async move { spawn(async move {
script script
.run(|(_, success)| { .run(|(_, success)| {
tx.send(success) tx.send(success).expect(err::ERR_CHANNEL_SEND);
.expect("Failed to send widget visibility toggle message");
}) })
.await; .await;
}); });

View file

@ -1,3 +1,4 @@
use crate::error;
use tokio::spawn; use tokio::spawn;
use tokio::sync::mpsc; use tokio::sync::mpsc;
@ -21,7 +22,7 @@ impl<T: Send + 'static> BridgeChannel<T> {
spawn(async move { spawn(async move {
while let Some(val) = async_rx.recv().await { while let Some(val) = async_rx.recv().await {
sync_tx.send(val).expect("Failed to send message"); sync_tx.send(val).expect(error::ERR_CHANNEL_SEND);
} }
}); });

View file

@ -18,6 +18,7 @@ use wayland_protocols::wlr::unstable::foreign_toplevel::v1::client::{
zwlr_foreign_toplevel_handle_v1::ZwlrForeignToplevelHandleV1, zwlr_foreign_toplevel_handle_v1::ZwlrForeignToplevelHandleV1,
zwlr_foreign_toplevel_manager_v1::ZwlrForeignToplevelManagerV1, zwlr_foreign_toplevel_manager_v1::ZwlrForeignToplevelManagerV1,
}; };
use crate::error as err;
pub struct WaylandClient { pub struct WaylandClient {
pub outputs: Vec<OutputInfo>, pub outputs: Vec<OutputInfo>,
@ -48,7 +49,7 @@ impl WaylandClient {
let outputs = Self::get_outputs(&env); let outputs = Self::get_outputs(&env);
output_tx output_tx
.send(outputs) .send(outputs)
.expect("Failed to send outputs out of task"); .expect(err::ERR_CHANNEL_SEND);
let seats = env.get_all_seats(); let seats = env.get_all_seats();
seat_tx seat_tx
@ -58,7 +59,7 @@ impl WaylandClient {
.map(|seat| seat.detach()) .map(|seat| seat.detach())
.collect::<Vec<WlSeat>>(), .collect::<Vec<WlSeat>>(),
) )
.expect("Failed to send seats out of task"); .expect(err::ERR_CHANNEL_SEND);
let _toplevel_manager = env.require_global::<ZwlrForeignToplevelManagerV1>(); let _toplevel_manager = env.require_global::<ZwlrForeignToplevelManagerV1>();
@ -68,18 +69,18 @@ impl WaylandClient {
if event.change == ToplevelChange::Close { if event.change == ToplevelChange::Close {
toplevels2 toplevels2
.write() .write()
.expect("Failed to get write lock on toplevels") .expect(err::ERR_WRITE_LOCK)
.remove(&event.toplevel.id); .remove(&event.toplevel.id);
} else { } else {
toplevels2 toplevels2
.write() .write()
.expect("Failed to get write lock on toplevels") .expect(err::ERR_WRITE_LOCK)
.insert(event.toplevel.id, (event.toplevel.clone(), handle)); .insert(event.toplevel.id, (event.toplevel.clone(), handle));
} }
toplevel_tx2 toplevel_tx2
.send(event) .send(event)
.expect("Failed to send toplevel event"); .expect(err::ERR_CHANNEL_SEND);
}); });
let mut event_loop = let mut event_loop =
@ -101,9 +102,9 @@ impl WaylandClient {
let outputs = output_rx let outputs = output_rx
.await .await
.expect("Failed to receive outputs from task"); .expect(err::ERR_CHANNEL_RECV);
let seats = seat_rx.await.expect("Failed to receive seats from task"); let seats = seat_rx.await.expect(err::ERR_CHANNEL_RECV);
Self { Self {
outputs, outputs,

View file

@ -4,6 +4,7 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use tracing::trace; use tracing::trace;
use wayland_client::{DispatchData, Main}; use wayland_client::{DispatchData, Main};
use wayland_protocols::wlr::unstable::foreign_toplevel::v1::client::zwlr_foreign_toplevel_handle_v1::{Event, ZwlrForeignToplevelHandleV1}; use wayland_protocols::wlr::unstable::foreign_toplevel::v1::client::zwlr_foreign_toplevel_handle_v1::{Event, ZwlrForeignToplevelHandleV1};
use crate::error;
const STATE_ACTIVE: u32 = 2; const STATE_ACTIVE: u32 = 2;
const STATE_FULLSCREEN: u32 = 3; const STATE_FULLSCREEN: u32 = 3;
@ -144,7 +145,7 @@ impl Toplevel {
handle.quick_assign(move |_handle, event, ddata| { handle.quick_assign(move |_handle, event, ddata| {
let mut inner = inner let mut inner = inner
.write() .write()
.expect("Failed to get write lock on toplevel inner state"); .expect(error::ERR_WRITE_LOCK);
toplevel_implem(event, &mut inner, &mut callback, ddata); toplevel_implem(event, &mut inner, &mut callback, ddata);
}); });

View file

@ -63,6 +63,8 @@ impl Default for BarPosition {
} }
impl BarPosition { impl BarPosition {
/// Gets the orientation the bar and widgets should use
/// based on this position.
pub fn get_orientation(self) -> Orientation { pub fn get_orientation(self) -> Orientation {
if self == Self::Top || self == Self::Bottom { if self == Self::Top || self == Self::Bottom {
Orientation::Horizontal Orientation::Horizontal
@ -71,6 +73,8 @@ impl BarPosition {
} }
} }
/// Gets the angle that label text should be displayed at
/// based on this position.
pub const fn get_angle(self) -> f64 { pub const fn get_angle(self) -> f64 {
match self { match self {
Self::Top | Self::Bottom => 0.0, Self::Top | Self::Bottom => 0.0,

View file

@ -1,3 +1,4 @@
use crate::error;
use crate::script::{OutputStream, Script}; use crate::script::{OutputStream, Script};
use gtk::prelude::*; use gtk::prelude::*;
use indexmap::IndexMap; use indexmap::IndexMap;
@ -10,9 +11,7 @@ enum DynamicStringSegment {
Dynamic(Script), Dynamic(Script),
} }
pub struct DynamicString { pub struct DynamicString;
// pub label: gtk::Label,
}
impl DynamicString { impl DynamicString {
pub fn new<F>(input: &str, f: F) -> Self pub fn new<F>(input: &str, f: F) -> Self
@ -69,7 +68,7 @@ impl DynamicString {
DynamicStringSegment::Static(str) => { DynamicStringSegment::Static(str) => {
label_parts label_parts
.lock() .lock()
.expect("Failed to get lock on label parts") .expect(error::ERR_MUTEX_LOCK)
.insert(i, str); .insert(i, str);
} }
DynamicStringSegment::Dynamic(script) => { DynamicStringSegment::Dynamic(script) => {
@ -80,9 +79,8 @@ impl DynamicString {
script script
.run(|(out, _)| { .run(|(out, _)| {
if let OutputStream::Stdout(out) = out { if let OutputStream::Stdout(out) = out {
let mut label_parts = label_parts let mut label_parts =
.lock() label_parts.lock().expect(error::ERR_MUTEX_LOCK);
.expect("Failed to get lock on label parts");
label_parts label_parts
// .lock() // .lock()
@ -94,7 +92,7 @@ impl DynamicString {
.map(|(_, part)| part.as_str()) .map(|(_, part)| part.as_str())
.collect::<String>(); .collect::<String>();
tx.send(string).expect("Failed to send update"); tx.send(string).expect(error::ERR_CHANNEL_SEND);
} }
}) })
.await; .await;
@ -107,18 +105,17 @@ impl DynamicString {
{ {
let label_parts = label_parts let label_parts = label_parts
.lock() .lock()
.expect("Failed to get lock on label parts") .expect(error::ERR_MUTEX_LOCK)
.iter() .iter()
.map(|(_, part)| part.as_str()) .map(|(_, part)| part.as_str())
.collect::<String>(); .collect::<String>();
tx.send(label_parts).expect("Failed to send update"); tx.send(label_parts).expect(error::ERR_CHANNEL_SEND);
} }
rx.attach(None, f); rx.attach(None, f);
// Self { label } Self
Self {}
} }
} }

13
src/error.rs Normal file
View file

@ -0,0 +1,13 @@
#[repr(i32)]
pub enum ExitCode {
GtkDisplay = 1,
CreateBars = 2,
Config = 3,
}
pub const ERR_OUTPUTS: &str = "GTK and Sway are reporting a different set of outputs - this is a severe bug and should never happen";
pub const ERR_MUTEX_LOCK: &str = "Failed to get lock on Mutex";
pub const ERR_READ_LOCK: &str = "Failed to get read lock";
pub const ERR_WRITE_LOCK: &str = "Failed to get write lock";
pub const ERR_CHANNEL_SEND: &str = "Failed to send message to channel";
pub const ERR_CHANNEL_RECV: &str = "Failed to receive message from channel";

View file

@ -3,6 +3,7 @@ mod bridge_channel;
mod clients; mod clients;
mod config; mod config;
mod dynamic_string; mod dynamic_string;
mod error;
mod icon; mod icon;
mod logging; mod logging;
mod modules; mod modules;
@ -30,6 +31,7 @@ use crate::error::ExitCode;
use clients::wayland::{self, WaylandClient}; use clients::wayland::{self, WaylandClient};
use tracing::{debug, error, info}; use tracing::{debug, error, info};
const GTK_APP_ID: &str = "dev.jstanger.ironbar";
const VERSION: &str = env!("CARGO_PKG_VERSION"); const VERSION: &str = env!("CARGO_PKG_VERSION");
#[tokio::main] #[tokio::main]
@ -41,9 +43,7 @@ async fn main() -> Result<()> {
let wayland_client = wayland::get_client().await; let wayland_client = wayland::get_client().await;
let app = Application::builder() let app = Application::builder().application_id(GTK_APP_ID).build();
.application_id("dev.jstanger.ironbar")
.build();
app.connect_activate(move |app| { app.connect_activate(move |app| {
let display = Display::default().map_or_else( let display = Display::default().map_or_else(
@ -112,8 +112,12 @@ fn create_bars(
let num_monitors = display.n_monitors(); let num_monitors = display.n_monitors();
for i in 0..num_monitors { for i in 0..num_monitors {
let monitor = display.monitor(i).ok_or_else(|| Report::msg("GTK and Sway are reporting a different set of outputs - this is a severe bug and should never happen"))?; let monitor = display
let output = outputs.get(i as usize).ok_or_else(|| Report::msg("GTK and Sway are reporting a different set of outputs - this is a severe bug and should never happen"))?; .monitor(i)
.ok_or_else(|| Report::msg(error::ERR_OUTPUTS))?;
let output = outputs
.get(i as usize)
.ok_or_else(|| Report::msg(error::ERR_OUTPUTS))?;
let monitor_name = &output.name; let monitor_name = &output.name;
// TODO: Could we use an Arc<Config> or `Cow<Config>` here to avoid cloning? // TODO: Could we use an Arc<Config> or `Cow<Config>` here to avoid cloning?

View file

@ -1,4 +1,5 @@
use crate::config::CommonConfig; use crate::config::CommonConfig;
use crate::error;
use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext}; use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext};
use crate::popup::Popup; use crate::popup::Popup;
use chrono::{DateTime, Local}; use chrono::{DateTime, Local};
@ -48,7 +49,7 @@ impl Module<Button> for ClockModule {
let date = Local::now(); let date = Local::now();
tx.send(ModuleUpdateEvent::Update(date)) tx.send(ModuleUpdateEvent::Update(date))
.await .await
.expect("Failed to send date"); .expect(error::ERR_CHANNEL_SEND);
sleep(tokio::time::Duration::from_millis(500)).await; sleep(tokio::time::Duration::from_millis(500)).await;
} }
}); });
@ -74,7 +75,7 @@ impl Module<Button> for ClockModule {
button, button,
orientation, orientation,
))) )))
.expect("Failed to toggle popup"); .expect(error::ERR_CHANNEL_SEND);
}); });
let format = self.format.clone(); let format = self.format.clone();

View file

@ -1,5 +1,6 @@
use crate::config::CommonConfig; use crate::config::CommonConfig;
use crate::dynamic_string::DynamicString; use crate::dynamic_string::DynamicString;
use crate::error as err;
use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext}; use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext};
use crate::popup::{ButtonGeometry, Popup}; use crate::popup::{ButtonGeometry, Popup};
use crate::script::Script; use crate::script::Script;
@ -119,8 +120,6 @@ impl Widget {
} }
label label
// DynamicString::new(label, &text)
} }
/// Creates a `gtk::Button` from this widget /// Creates a `gtk::Button` from this widget
@ -150,7 +149,7 @@ impl Widget {
cmd: exec.clone(), cmd: exec.clone(),
geometry: Popup::button_pos(button, bar_orientation), geometry: Popup::button_pos(button, bar_orientation),
}) })
.expect("Failed to send exec message"); .expect(err::ERR_CHANNEL_SEND);
}); });
} }
@ -191,15 +190,15 @@ impl Module<gtk::Box> for CustomModule {
} else if event.cmd == "popup:toggle" { } else if event.cmd == "popup:toggle" {
tx.send(ModuleUpdateEvent::TogglePopup(event.geometry)) tx.send(ModuleUpdateEvent::TogglePopup(event.geometry))
.await .await
.expect("Failed to send open popup event"); .expect(err::ERR_CHANNEL_SEND);
} else if event.cmd == "popup:open" { } else if event.cmd == "popup:open" {
tx.send(ModuleUpdateEvent::OpenPopup(event.geometry)) tx.send(ModuleUpdateEvent::OpenPopup(event.geometry))
.await .await
.expect("Failed to send open popup event"); .expect(err::ERR_CHANNEL_SEND);
} else if event.cmd == "popup:close" { } else if event.cmd == "popup:close" {
tx.send(ModuleUpdateEvent::ClosePopup) tx.send(ModuleUpdateEvent::ClosePopup)
.await .await
.expect("Failed to send open popup event"); .expect(err::ERR_CHANNEL_SEND);
} else { } else {
error!("Received invalid command: '{}'", event.cmd); error!("Received invalid command: '{}'", event.cmd);
} }

View file

@ -1,7 +1,7 @@
use crate::clients::wayland::{self, ToplevelChange}; use crate::clients::wayland::{self, ToplevelChange};
use crate::config::CommonConfig; use crate::config::CommonConfig;
use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext}; use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext};
use crate::{await_sync, icon}; use crate::{await_sync, error, icon};
use color_eyre::Result; use color_eyre::Result;
use glib::Continue; use glib::Continue;
use gtk::prelude::*; use gtk::prelude::*;
@ -49,11 +49,7 @@ impl Module<gtk::Box> for FocusedModule {
) -> Result<()> { ) -> Result<()> {
let focused = await_sync(async { let focused = await_sync(async {
let wl = wayland::get_client().await; let wl = wayland::get_client().await;
let toplevels = wl let toplevels = wl.toplevels.read().expect(error::ERR_READ_LOCK).clone();
.toplevels
.read()
.expect("Failed to get read lock on toplevels")
.clone();
toplevels.into_iter().find(|(_, (top, _))| top.active) toplevels.into_iter().find(|(_, (top, _))| top.active)
}); });
@ -81,7 +77,7 @@ impl Module<gtk::Box> for FocusedModule {
event.toplevel.app_id, event.toplevel.app_id,
))) )))
.await .await
.expect("Failed to send focus update"); .expect(error::ERR_CHANNEL_SEND);
} }
} }
}); });

View file

@ -1,5 +1,6 @@
use super::open_state::OpenState; use super::open_state::OpenState;
use crate::clients::wayland::ToplevelInfo; use crate::clients::wayland::ToplevelInfo;
use crate::error;
use crate::icon::get_icon; use crate::icon::get_icon;
use crate::modules::launcher::{ItemEvent, LauncherUpdate}; use crate::modules::launcher::{ItemEvent, LauncherUpdate};
use crate::modules::ModuleUpdateEvent; use crate::modules::ModuleUpdateEvent;
@ -181,10 +182,10 @@ impl ItemButton {
let style_context = button.style_context(); let style_context = button.style_context();
if style_context.has_class("open") { if style_context.has_class("open") {
tx.try_send(ItemEvent::FocusItem(app_id.clone())) tx.try_send(ItemEvent::FocusItem(app_id.clone()))
.expect("Failed to send item focus event"); .expect(error::ERR_CHANNEL_SEND);
} else { } else {
tx.try_send(ItemEvent::OpenItem(app_id.clone())) tx.try_send(ItemEvent::OpenItem(app_id.clone()))
.expect("Failed to send item open event"); .expect(error::ERR_CHANNEL_SEND);
} }
}); });
} }
@ -199,24 +200,22 @@ impl ItemButton {
let menu_state = menu_state.clone(); let menu_state = menu_state.clone();
button.connect_enter_notify_event(move |button, _| { button.connect_enter_notify_event(move |button, _| {
let menu_state = menu_state let menu_state = menu_state.read().expect(error::ERR_READ_LOCK);
.read()
.expect("Failed to get read lock on item menu state");
if menu_state.num_windows > 1 { if menu_state.num_windows > 1 {
tx.try_send(ModuleUpdateEvent::Update(LauncherUpdate::Hover( tx.try_send(ModuleUpdateEvent::Update(LauncherUpdate::Hover(
app_id.clone(), app_id.clone(),
))) )))
.expect("Failed to send item open popup event"); .expect(error::ERR_CHANNEL_SEND);
tx.try_send(ModuleUpdateEvent::OpenPopup(Popup::button_pos( tx.try_send(ModuleUpdateEvent::OpenPopup(Popup::button_pos(
button, button,
orientation, orientation,
))) )))
.expect("Failed to send item open popup event"); .expect(error::ERR_CHANNEL_SEND);
} else { } else {
tx.try_send(ModuleUpdateEvent::ClosePopup) tx.try_send(ModuleUpdateEvent::ClosePopup)
.expect("Failed to send item close popup event"); .expect(error::ERR_CHANNEL_SEND);
} }
Inhibit(false) Inhibit(false)

View file

@ -5,6 +5,7 @@ use self::item::{Item, ItemButton, Window};
use self::open_state::OpenState; use self::open_state::OpenState;
use crate::clients::wayland::{self, ToplevelChange}; use crate::clients::wayland::{self, ToplevelChange};
use crate::config::CommonConfig; use crate::config::CommonConfig;
use crate::error as err;
use crate::icon::find_desktop_file; use crate::icon::find_desktop_file;
use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext}; use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext};
use color_eyre::{Help, Report}; use color_eyre::{Help, Report};
@ -110,12 +111,9 @@ impl Module<gtk::Box> for LauncherModule {
let tx = tx.clone(); let tx = tx.clone();
spawn(async move { spawn(async move {
let wl = wayland::get_client().await; let wl = wayland::get_client().await;
let open_windows = wl let open_windows = wl.toplevels.read().expect(err::ERR_READ_LOCK);
.toplevels
.read()
.expect("Failed to get read lock on toplevels");
let mut items = items.lock().expect("Failed to get lock on items"); let mut items = items.lock().expect(err::ERR_MUTEX_LOCK);
for (_, (window, _)) in open_windows.clone() { for (_, (window, _)) in open_windows.clone() {
let item = items.get_mut(&window.app_id); let item = items.get_mut(&window.app_id);
@ -157,7 +155,7 @@ impl Module<gtk::Box> for LauncherModule {
let window = event.toplevel; let window = event.toplevel;
let app_id = window.app_id.clone(); let app_id = window.app_id.clone();
let items = || items.lock().expect("Failed to get lock on items"); let items = || items.lock().expect(err::ERR_MUTEX_LOCK);
match event.change { match event.change {
ToplevelChange::New => { ToplevelChange::New => {
@ -218,6 +216,7 @@ impl Module<gtk::Box> for LauncherModule {
}; };
} }
ToplevelChange::Focus(focused) => { ToplevelChange::Focus(focused) => {
// TODO: Flatten this
let update_title = if focused { let update_title = if focused {
if let Some(item) = items().get_mut(&app_id) { if let Some(item) = items().get_mut(&app_id) {
item.set_window_focused(window.id, true); item.set_window_focused(window.id, true);
@ -269,6 +268,7 @@ impl Module<gtk::Box> for LauncherModule {
if let Err(err) = Command::new("gtk-launch") if let Err(err) = Command::new("gtk-launch")
.arg( .arg(
file.file_name() file.file_name()
// TODO: Don't panic for this
.expect("File segment missing from path to desktop file"), .expect("File segment missing from path to desktop file"),
) )
.stdout(Stdio::null()) .stdout(Stdio::null())
@ -286,7 +286,7 @@ impl Module<gtk::Box> for LauncherModule {
); );
} else { } else {
let wl = wayland::get_client().await; let wl = wayland::get_client().await;
let items = items.lock().expect("Failed to get lock on items"); let items = items.lock().expect(err::ERR_MUTEX_LOCK);
let id = match event { let id = match event {
ItemEvent::FocusItem(app_id) => items ItemEvent::FocusItem(app_id) => items
@ -297,10 +297,7 @@ impl Module<gtk::Box> for LauncherModule {
}; };
if let Some(id) = id { if let Some(id) = id {
let toplevels = wl let toplevels = wl.toplevels.read().expect(err::ERR_READ_LOCK);
.toplevels
.read()
.expect("Failed to get read lock on toplevels");
let seat = wl.seats.first().expect("Failed to get Wayland seat"); let seat = wl.seats.first().expect("Failed to get Wayland seat");
if let Some((_top, handle)) = toplevels.get(&id) { if let Some((_top, handle)) = toplevels.get(&id) {
handle.activate(seat); handle.activate(seat);
@ -363,10 +360,8 @@ impl Module<gtk::Box> for LauncherModule {
if let Some(button) = buttons.get(&app_id) { if let Some(button) = buttons.get(&app_id) {
button.set_open(true); button.set_open(true);
let mut menu_state = button let mut menu_state =
.menu_state button.menu_state.write().expect(err::ERR_WRITE_LOCK);
.write()
.expect("Failed to get write lock on item menu state");
menu_state.num_windows += 1; menu_state.num_windows += 1;
} }
} }
@ -387,10 +382,8 @@ impl Module<gtk::Box> for LauncherModule {
} }
LauncherUpdate::RemoveWindow(app_id, _) => { LauncherUpdate::RemoveWindow(app_id, _) => {
if let Some(button) = buttons.get(&app_id) { if let Some(button) = buttons.get(&app_id) {
let mut menu_state = button let mut menu_state =
.menu_state button.menu_state.write().expect(err::ERR_WRITE_LOCK);
.write()
.expect("Failed to get write lock on item menu state");
menu_state.num_windows -= 1; menu_state.num_windows -= 1;
} }
} }
@ -464,7 +457,7 @@ impl Module<gtk::Box> for LauncherModule {
let tx = controller_tx.clone(); let tx = controller_tx.clone();
button.connect_clicked(move |button| { button.connect_clicked(move |button| {
tx.try_send(ItemEvent::FocusWindow(win.id)) tx.try_send(ItemEvent::FocusWindow(win.id))
.expect("Failed to send window click event"); .expect(err::ERR_CHANNEL_SEND);
if let Some(win) = button.window() { if let Some(win) = button.window() {
win.hide(); win.hide();
@ -494,7 +487,7 @@ impl Module<gtk::Box> for LauncherModule {
let tx = controller_tx.clone(); let tx = controller_tx.clone();
button.connect_clicked(move |button| { button.connect_clicked(move |button| {
tx.try_send(ItemEvent::FocusWindow(win.id)) tx.try_send(ItemEvent::FocusWindow(win.id))
.expect("Failed to send window click event"); .expect(err::ERR_CHANNEL_SEND);
if let Some(win) = button.window() { if let Some(win) = button.window() {
win.hide(); win.hide();

View file

@ -1,5 +1,6 @@
use crate::clients::mpd::{get_client, get_duration, get_elapsed, MpdConnectionError}; use crate::clients::mpd::{get_client, get_duration, get_elapsed, MpdConnectionError};
use crate::config::CommonConfig; use crate::config::CommonConfig;
use crate::error as err;
use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext}; use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext};
use crate::popup::Popup; use crate::popup::Popup;
use color_eyre::Result; use color_eyre::Result;
@ -229,7 +230,7 @@ impl Module<Button> for MpdModule {
button, button,
orientation, orientation,
))) )))
.expect("Failed to send MPD popup open event"); .expect(err::ERR_CHANNEL_SEND);
}); });
} }
@ -244,7 +245,7 @@ impl Module<Button> for MpdModule {
} else { } else {
button.hide(); button.hide();
tx.try_send(ModuleUpdateEvent::ClosePopup) tx.try_send(ModuleUpdateEvent::ClosePopup)
.expect("Failed to send close popup message"); .expect(err::ERR_CHANNEL_SEND);
} }
Continue(true) Continue(true)
@ -324,28 +325,28 @@ impl Module<Button> for MpdModule {
btn_prev.connect_clicked(move |_| { btn_prev.connect_clicked(move |_| {
tx_prev tx_prev
.try_send(PlayerCommand::Previous) .try_send(PlayerCommand::Previous)
.expect("Failed to send prev track message"); .expect(err::ERR_CHANNEL_SEND);
}); });
let tx_toggle = tx.clone(); let tx_toggle = tx.clone();
btn_play_pause.connect_clicked(move |_| { btn_play_pause.connect_clicked(move |_| {
tx_toggle tx_toggle
.try_send(PlayerCommand::Toggle) .try_send(PlayerCommand::Toggle)
.expect("Failed to send play/pause track message"); .expect(err::ERR_CHANNEL_SEND);
}); });
let tx_next = tx.clone(); let tx_next = tx.clone();
btn_next.connect_clicked(move |_| { btn_next.connect_clicked(move |_| {
tx_next tx_next
.try_send(PlayerCommand::Next) .try_send(PlayerCommand::Next)
.expect("Failed to send next track message"); .expect(err::ERR_CHANNEL_SEND);
}); });
let tx_vol = tx; let tx_vol = tx;
volume_slider.connect_change_value(move |_, _, val| { volume_slider.connect_change_value(move |_, _, val| {
tx_vol tx_vol
.try_send(PlayerCommand::Volume(val as u8)) .try_send(PlayerCommand::Volume(val as u8))
.expect("Failed to send volume message"); .expect(err::ERR_CHANNEL_SEND);
Inhibit(false) Inhibit(false)
}); });

View file

@ -1,4 +1,5 @@
use crate::config::CommonConfig; use crate::config::CommonConfig;
use crate::error;
use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext}; use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext};
use color_eyre::Result; use color_eyre::Result;
use gtk::prelude::*; use gtk::prelude::*;
@ -146,7 +147,7 @@ impl Module<gtk::Box> for SysInfoModule {
loop { loop {
tx.send(RefreshType::Memory) tx.send(RefreshType::Memory)
.await .await
.expect("Failed to send memory refresh"); .expect(error::ERR_CHANNEL_SEND);
sleep(Duration::from_secs(interval.memory())).await; sleep(Duration::from_secs(interval.memory())).await;
} }
}); });
@ -159,7 +160,7 @@ impl Module<gtk::Box> for SysInfoModule {
loop { loop {
tx.send(RefreshType::Cpu) tx.send(RefreshType::Cpu)
.await .await
.expect("Failed to send cpu refresh"); .expect(error::ERR_CHANNEL_SEND);
sleep(Duration::from_secs(interval.cpu())).await; sleep(Duration::from_secs(interval.cpu())).await;
} }
}); });
@ -172,7 +173,7 @@ impl Module<gtk::Box> for SysInfoModule {
loop { loop {
tx.send(RefreshType::Temps) tx.send(RefreshType::Temps)
.await .await
.expect("Failed to send temperature refresh"); .expect(error::ERR_CHANNEL_SEND);
sleep(Duration::from_secs(interval.temps())).await; sleep(Duration::from_secs(interval.temps())).await;
} }
}); });
@ -185,7 +186,7 @@ impl Module<gtk::Box> for SysInfoModule {
loop { loop {
tx.send(RefreshType::Disks) tx.send(RefreshType::Disks)
.await .await
.expect("Failed to send disk refresh"); .expect(error::ERR_CHANNEL_SEND);
sleep(Duration::from_secs(interval.disks())).await; sleep(Duration::from_secs(interval.disks())).await;
} }
}); });
@ -198,7 +199,7 @@ impl Module<gtk::Box> for SysInfoModule {
loop { loop {
tx.send(RefreshType::Network) tx.send(RefreshType::Network)
.await .await
.expect("Failed to send network refresh"); .expect(error::ERR_CHANNEL_SEND);
sleep(Duration::from_secs(interval.networks())).await; sleep(Duration::from_secs(interval.networks())).await;
} }
}); });
@ -211,7 +212,7 @@ impl Module<gtk::Box> for SysInfoModule {
loop { loop {
tx.send(RefreshType::System) tx.send(RefreshType::System)
.await .await
.expect("Failed to send system refresh"); .expect(error::ERR_CHANNEL_SEND);
sleep(Duration::from_secs(interval.system())).await; sleep(Duration::from_secs(interval.system())).await;
} }
}); });
@ -234,7 +235,7 @@ impl Module<gtk::Box> for SysInfoModule {
tx.send(ModuleUpdateEvent::Update(format_info.clone())) tx.send(ModuleUpdateEvent::Update(format_info.clone()))
.await .await
.expect("Failed to send system info map"); .expect(error::ERR_CHANNEL_SEND);
} }
}); });

View file

@ -1,7 +1,7 @@
use crate::await_sync;
use crate::clients::system_tray::get_tray_event_client; use crate::clients::system_tray::get_tray_event_client;
use crate::config::CommonConfig; use crate::config::CommonConfig;
use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext}; use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext};
use crate::{await_sync, error};
use color_eyre::Result; use color_eyre::Result;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::{IconLookupFlags, IconTheme, Image, Menu, MenuBar, MenuItem, SeparatorMenuItem}; use gtk::{IconLookupFlags, IconTheme, Image, Menu, MenuBar, MenuItem, SeparatorMenuItem};
@ -75,7 +75,7 @@ fn get_menu_items(
menu_path: path.clone(), menu_path: path.clone(),
notifier_address: id.clone(), notifier_address: id.clone(),
}) })
.expect("Failed to send menu item clicked event"); .expect(error::ERR_CHANNEL_SEND);
}); });
} }

View file

@ -1,7 +1,7 @@
use crate::await_sync;
use crate::clients::sway::{get_client, get_sub_client}; use crate::clients::sway::{get_client, get_sub_client};
use crate::config::CommonConfig; use crate::config::CommonConfig;
use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext}; use crate::modules::{Module, ModuleInfo, ModuleUpdateEvent, ModuleWidget, WidgetContext};
use crate::{await_sync, error};
use color_eyre::{Report, Result}; use color_eyre::{Report, Result};
use gtk::prelude::*; use gtk::prelude::*;
use gtk::Button; use gtk::Button;
@ -53,8 +53,7 @@ fn create_button(
let tx = tx.clone(); let tx = tx.clone();
let name = name.to_string(); let name = name.to_string();
button.connect_clicked(move |_item| { button.connect_clicked(move |_item| {
tx.try_send(name.clone()) tx.try_send(name.clone()).expect(error::ERR_CHANNEL_SEND);
.expect("Failed to send workspace click event");
}); });
} }
@ -95,7 +94,7 @@ impl Module<gtk::Box> for WorkspacesModule {
}; };
tx.try_send(ModuleUpdateEvent::Update(WorkspaceUpdate::Init(workspaces))) tx.try_send(ModuleUpdateEvent::Update(WorkspaceUpdate::Init(workspaces)))
.expect("Failed to send initial workspace list"); .expect(error::ERR_CHANNEL_SEND);
// Subscribe & send events // Subscribe & send events
spawn(async move { spawn(async move {
@ -109,7 +108,7 @@ impl Module<gtk::Box> for WorkspacesModule {
while let Ok(payload) = srx.recv().await { while let Ok(payload) = srx.recv().await {
tx.send(ModuleUpdateEvent::Update(WorkspaceUpdate::Update(payload))) tx.send(ModuleUpdateEvent::Update(WorkspaceUpdate::Update(payload)))
.await .await
.expect("Failed to send workspace update"); .expect(error::ERR_CHANNEL_SEND);
} }
}); });

View file

@ -1,3 +1,4 @@
use crate::error as err;
use color_eyre::eyre::WrapErr; use color_eyre::eyre::WrapErr;
use color_eyre::{Report, Result}; use color_eyre::{Report, Result};
use serde::Deserialize; use serde::Deserialize;
@ -129,12 +130,10 @@ impl From<&str> for Script {
.iter() .iter()
.take_while(|c| c.is_ascii_digit()) .take_while(|c| c.is_ascii_digit())
.collect::<String>(); .collect::<String>();
(
ScriptInputToken::Interval( // TODO: Handle this better than panicking
interval_str.parse::<u64>().expect("Invalid interval"), let interval = interval_str.parse::<u64>().expect("Invalid interval");
), (ScriptInputToken::Interval(interval), interval_str.len())
interval_str.len(),
)
} }
// watching or polling // watching or polling
'w' | 'p' => { 'w' | 'p' => {
@ -262,10 +261,10 @@ impl Script {
select! { select! {
_ = handle.wait() => break, _ = handle.wait() => break,
Ok(Some(line)) = stdout_lines.next_line() => { Ok(Some(line)) = stdout_lines.next_line() => {
tx.send(OutputStream::Stdout(line)).await.expect("Failed to send stdout"); tx.send(OutputStream::Stdout(line)).await.expect(err::ERR_CHANNEL_SEND);
} }
Ok(Some(line)) = stderr_lines.next_line() => { Ok(Some(line)) = stderr_lines.next_line() => {
tx.send(OutputStream::Stderr(line)).await.expect("Failed to send stderr"); tx.send(OutputStream::Stderr(line)).await.expect(err::ERR_CHANNEL_SEND);
} }
} }
} }

View file

@ -1,3 +1,4 @@
use crate::error as err;
use color_eyre::{Help, Report}; use color_eyre::{Help, Report};
use glib::Continue; use glib::Continue;
use gtk::prelude::CssProviderExt; use gtk::prelude::CssProviderExt;
@ -37,8 +38,7 @@ pub fn load_css(style_path: PathBuf) {
Ok(event) if event.kind == EventKind::Modify(ModifyKind::Data(DataChange::Any)) => { Ok(event) if event.kind == EventKind::Modify(ModifyKind::Data(DataChange::Any)) => {
debug!("{event:?}"); debug!("{event:?}");
if let Some(path) = event.paths.first() { if let Some(path) = event.paths.first() {
tx.send(path.clone()) tx.send(path.clone()).expect(err::ERR_CHANNEL_SEND);
.expect("Failed to send style changed message");
} }
} }
Err(e) => error!("Error occurred when watching stylesheet: {:?}", e), Err(e) => error!("Error occurred when watching stylesheet: {:?}", e),