mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-08-17 14:51:04 +02:00
refactor: recv_glib
dependency arrays
Adds a dependency array system to `recv_glib` which internally clones the passed deps and then passes by reference to the callback. This cleans up a lot of the big `{}` blocks full of `widget.clone()` and removes a lot of boilerplate. Yay!
This commit is contained in:
parent
beab26a37e
commit
9d18ce52f5
31 changed files with 539 additions and 517 deletions
|
@ -1,6 +1,6 @@
|
|||
#[cfg(feature = "ipc")]
|
||||
use crate::Ironbar;
|
||||
use crate::channels::{AsyncSenderExt, MpscReceiverExt};
|
||||
use crate::channels::{AsyncSenderExt, Dependency, MpscReceiverExt};
|
||||
use crate::script::Script;
|
||||
use crate::spawn;
|
||||
use cfg_if::cfg_if;
|
||||
|
@ -19,9 +19,11 @@ pub enum DynamicBool {
|
|||
}
|
||||
|
||||
impl DynamicBool {
|
||||
pub fn subscribe<F>(self, f: F)
|
||||
pub fn subscribe<D, F>(self, deps: D, f: F)
|
||||
where
|
||||
F: FnMut(bool) + 'static,
|
||||
D: Dependency,
|
||||
D::Target: Clone + 'static,
|
||||
F: FnMut(&D::Target, bool) + 'static,
|
||||
{
|
||||
let value = match self {
|
||||
Self::Unknown(input) => {
|
||||
|
@ -43,7 +45,7 @@ impl DynamicBool {
|
|||
|
||||
let (tx, rx) = mpsc::channel(32);
|
||||
|
||||
rx.recv_glib(f);
|
||||
rx.recv_glib(deps, f);
|
||||
|
||||
spawn(async move {
|
||||
match value {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#[cfg(feature = "ipc")]
|
||||
use crate::Ironbar;
|
||||
use crate::channels::{AsyncSenderExt, MpscReceiverExt};
|
||||
use crate::channels::{AsyncSenderExt, Dependency, MpscReceiverExt};
|
||||
use crate::script::{OutputStream, Script};
|
||||
use crate::{arc_mut, lock, spawn};
|
||||
use tokio::sync::mpsc;
|
||||
|
@ -26,9 +26,11 @@ enum DynamicStringSegment {
|
|||
/// label.set_label_escaped(&string);
|
||||
/// });
|
||||
/// ```
|
||||
pub fn dynamic_string<F>(input: &str, f: F)
|
||||
pub fn dynamic_string<D, F>(input: &str, deps: D, f: F)
|
||||
where
|
||||
F: FnMut(String) + 'static,
|
||||
D: Dependency,
|
||||
D::Target: Clone + 'static,
|
||||
F: FnMut(&D::Target, String) + 'static,
|
||||
{
|
||||
let (tokens, is_static) = parse_input(input);
|
||||
|
||||
|
@ -89,7 +91,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
rx.recv_glib(f);
|
||||
rx.recv_glib(deps, f);
|
||||
|
||||
// initialize
|
||||
if is_static {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue