mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-08-17 23:01:04 +02:00
refactor: better error handling for client initialization
This commit is contained in:
parent
1b35354272
commit
9245188af7
10 changed files with 97 additions and 49 deletions
|
@ -13,7 +13,6 @@ use gtk::prelude::*;
|
|||
use gtk::{Button, EventBox, Image, Label, Orientation, RadioButton, Widget};
|
||||
use serde::Deserialize;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::{broadcast, mpsc};
|
||||
use tracing::{debug, error};
|
||||
|
||||
|
@ -76,7 +75,7 @@ impl Module<Button> for ClipboardModule {
|
|||
let max_items = self.max_items;
|
||||
|
||||
let tx = context.tx.clone();
|
||||
let client: Arc<clipboard::Client> = context.client();
|
||||
let client = context.client::<clipboard::Client>();
|
||||
|
||||
// listen to clipboard events
|
||||
spawn(async move {
|
||||
|
|
|
@ -10,7 +10,7 @@ use gtk::{Application, Button, EventBox, IconTheme, Orientation, Revealer, Widge
|
|||
use tokio::sync::{broadcast, mpsc};
|
||||
use tracing::debug;
|
||||
|
||||
use crate::clients::ProvidesClient;
|
||||
use crate::clients::{ClientResult, ProvidesClient, ProvidesFallibleClient};
|
||||
use crate::config::{BarPosition, CommonConfig, TransitionType};
|
||||
use crate::gtk_helpers::{IronbarGtkExt, WidgetGeometry};
|
||||
use crate::popup::Popup;
|
||||
|
@ -115,6 +115,13 @@ where
|
|||
ProvidesClient::provide(self)
|
||||
}
|
||||
|
||||
pub fn try_client<T: ?Sized>(&self) -> ClientResult<T>
|
||||
where
|
||||
WidgetContext<TSend, TReceive>: ProvidesFallibleClient<T>,
|
||||
{
|
||||
ProvidesFallibleClient::try_provide(self)
|
||||
}
|
||||
|
||||
/// Subscribes to events sent from this widget.
|
||||
pub fn subscribe(&self) -> broadcast::Receiver<TSend> {
|
||||
self.update_tx.subscribe()
|
||||
|
|
|
@ -108,7 +108,7 @@ impl Module<Overlay> for NotificationsModule {
|
|||
where
|
||||
<Self as Module<Overlay>>::SendMessage: Clone,
|
||||
{
|
||||
let client = context.client::<swaync::Client>();
|
||||
let client = context.try_client::<swaync::Client>()?;
|
||||
|
||||
{
|
||||
let client = client.clone();
|
||||
|
|
|
@ -67,7 +67,7 @@ impl Module<MenuBar> for TrayModule {
|
|||
) -> Result<()> {
|
||||
let tx = context.tx.clone();
|
||||
|
||||
let client = context.client::<tray::Client>();
|
||||
let client = context.try_client::<tray::Client>()?;
|
||||
let mut tray_rx = client.subscribe();
|
||||
|
||||
let initial_items = lock!(client.items()).clone();
|
||||
|
|
|
@ -153,7 +153,7 @@ impl Module<gtk::Box> for WorkspacesModule {
|
|||
mut rx: Receiver<Self::ReceiveMessage>,
|
||||
) -> Result<()> {
|
||||
let tx = context.tx.clone();
|
||||
let client = context.ironbar.clients.borrow_mut().workspaces();
|
||||
let client = context.ironbar.clients.borrow_mut().workspaces()?;
|
||||
// Subscribe & send events
|
||||
spawn(async move {
|
||||
let mut srx = client.subscribe_workspace_change();
|
||||
|
@ -166,7 +166,7 @@ impl Module<gtk::Box> for WorkspacesModule {
|
|||
}
|
||||
});
|
||||
|
||||
let client = context.client::<dyn WorkspaceClient>();
|
||||
let client = context.try_client::<dyn WorkspaceClient>()?;
|
||||
|
||||
// Change workspace focus
|
||||
spawn(async move {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue