mirror of
				https://github.com/Zedfrigg/ironbar.git
				synced 2025-11-03 23:11:54 +01:00 
			
		
		
		
	refactor: major client code changes
This does away with `lazy_static` singletons for all the clients, instead putting them all inside a `Clients` struct on the `Ironbar` struct. Client code has been refactored in places to accommodate this, and module code has been updated to get the clients the new way. The Wayland client has been re-written from the ground up to remove a lot of the needless complications, provide a nicer interface and reduce some duplicate data. The MPD music client has been overhauled to use the `mpd_utils` crate, which simplifies the code within Ironbar and should offer more robustness and better recovery when connection is lost to the server. The launcher module in particular has been affected by the refactor.
This commit is contained in:
		
					parent
					
						
							
								57b57ed002
							
						
					
				
			
			
				commit
				
					
						c702f6fffa
					
				
			
		
					 33 changed files with 1081 additions and 1063 deletions
				
			
		| 
						 | 
				
			
			@ -1,6 +1,7 @@
 | 
			
		|||
use std::cell::RefCell;
 | 
			
		||||
use std::fmt::Debug;
 | 
			
		||||
use std::rc::Rc;
 | 
			
		||||
use std::sync::Arc;
 | 
			
		||||
 | 
			
		||||
use color_eyre::Result;
 | 
			
		||||
use glib::IsA;
 | 
			
		||||
| 
						 | 
				
			
			@ -10,10 +11,11 @@ use gtk::{Application, Button, EventBox, IconTheme, Orientation, Revealer, Widge
 | 
			
		|||
use tokio::sync::{broadcast, mpsc};
 | 
			
		||||
use tracing::debug;
 | 
			
		||||
 | 
			
		||||
use crate::clients::ProvidesClient;
 | 
			
		||||
use crate::config::{BarPosition, CommonConfig, TransitionType};
 | 
			
		||||
use crate::gtk_helpers::{IronbarGtkExt, WidgetGeometry};
 | 
			
		||||
use crate::popup::Popup;
 | 
			
		||||
use crate::{glib_recv_mpsc, send};
 | 
			
		||||
use crate::{glib_recv_mpsc, send, Ironbar};
 | 
			
		||||
 | 
			
		||||
#[cfg(feature = "clipboard")]
 | 
			
		||||
pub mod clipboard;
 | 
			
		||||
| 
						 | 
				
			
			@ -76,6 +78,7 @@ where
 | 
			
		|||
    TSend: Clone,
 | 
			
		||||
{
 | 
			
		||||
    pub id: usize,
 | 
			
		||||
    pub ironbar: Rc<Ironbar>,
 | 
			
		||||
    pub tx: mpsc::Sender<ModuleUpdateEvent<TSend>>,
 | 
			
		||||
    pub update_tx: broadcast::Sender<TSend>,
 | 
			
		||||
    pub controller_tx: mpsc::Sender<TReceive>,
 | 
			
		||||
| 
						 | 
				
			
			@ -87,6 +90,18 @@ impl<TSend, TReceive> WidgetContext<TSend, TReceive>
 | 
			
		|||
where
 | 
			
		||||
    TSend: Clone,
 | 
			
		||||
{
 | 
			
		||||
    /// Gets client `T` from the context.
 | 
			
		||||
    ///
 | 
			
		||||
    /// This is a shorthand to avoid needing to go through
 | 
			
		||||
    /// `context.ironbar.clients`.
 | 
			
		||||
    pub fn client<T: ?Sized>(&self) -> Arc<T>
 | 
			
		||||
    where
 | 
			
		||||
        WidgetContext<TSend, TReceive>: ProvidesClient<T>,
 | 
			
		||||
    {
 | 
			
		||||
        ProvidesClient::provide(self)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /// Subscribes to events sent from this widget.
 | 
			
		||||
    pub fn subscribe(&self) -> broadcast::Receiver<TSend> {
 | 
			
		||||
        self.update_tx.subscribe()
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -194,6 +209,7 @@ where
 | 
			
		|||
pub fn create_module<TModule, TWidget, TSend, TRec>(
 | 
			
		||||
    module: TModule,
 | 
			
		||||
    id: usize,
 | 
			
		||||
    ironbar: Rc<Ironbar>,
 | 
			
		||||
    name: Option<String>,
 | 
			
		||||
    info: &ModuleInfo,
 | 
			
		||||
    popup: &Rc<RefCell<Popup>>,
 | 
			
		||||
| 
						 | 
				
			
			@ -210,6 +226,7 @@ where
 | 
			
		|||
 | 
			
		||||
    let context = WidgetContext {
 | 
			
		||||
        id,
 | 
			
		||||
        ironbar,
 | 
			
		||||
        tx: ui_tx,
 | 
			
		||||
        update_tx: tx.clone(),
 | 
			
		||||
        controller_tx,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue