mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-08-17 14:51:04 +02:00
refactor: replace channel macros with ext trait methods
This commit is contained in:
parent
d5744f597c
commit
f929aef2d9
50 changed files with 658 additions and 476 deletions
|
@ -1,7 +1,8 @@
|
|||
use crate::script::Script;
|
||||
#[cfg(feature = "ipc")]
|
||||
use crate::{Ironbar, send_async};
|
||||
use crate::{glib_recv_mpsc, spawn, try_send};
|
||||
use crate::Ironbar;
|
||||
use crate::channels::{AsyncSenderExt, MpscReceiverExt};
|
||||
use crate::script::Script;
|
||||
use crate::spawn;
|
||||
use cfg_if::cfg_if;
|
||||
use serde::Deserialize;
|
||||
use tokio::sync::mpsc;
|
||||
|
@ -18,7 +19,7 @@ pub enum DynamicBool {
|
|||
}
|
||||
|
||||
impl DynamicBool {
|
||||
pub fn subscribe<F>(self, mut f: F)
|
||||
pub fn subscribe<F>(self, f: F)
|
||||
where
|
||||
F: FnMut(bool) + 'static,
|
||||
{
|
||||
|
@ -42,14 +43,14 @@ impl DynamicBool {
|
|||
|
||||
let (tx, rx) = mpsc::channel(32);
|
||||
|
||||
glib_recv_mpsc!(rx, val => f(val));
|
||||
rx.recv_glib(f);
|
||||
|
||||
spawn(async move {
|
||||
match value {
|
||||
DynamicBool::Script(script) => {
|
||||
script
|
||||
.run(None, |_, success| {
|
||||
try_send!(tx, success);
|
||||
tx.send_spawn(success);
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
@ -62,7 +63,7 @@ impl DynamicBool {
|
|||
|
||||
while let Ok(value) = rx.recv().await {
|
||||
let has_value = value.is_some_and(|s| is_truthy(&s));
|
||||
send_async!(tx, has_value);
|
||||
tx.send_expect(has_value).await;
|
||||
}
|
||||
}
|
||||
DynamicBool::Unknown(_) => unreachable!(),
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
#[cfg(feature = "ipc")]
|
||||
use crate::Ironbar;
|
||||
use crate::channels::{AsyncSenderExt, MpscReceiverExt};
|
||||
use crate::script::{OutputStream, Script};
|
||||
use crate::{arc_mut, glib_recv_mpsc, lock, spawn, try_send};
|
||||
use crate::{arc_mut, lock, spawn};
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
/// A segment of a dynamic string,
|
||||
|
@ -25,7 +26,7 @@ enum DynamicStringSegment {
|
|||
/// label.set_label_escaped(&string);
|
||||
/// });
|
||||
/// ```
|
||||
pub fn dynamic_string<F>(input: &str, mut f: F)
|
||||
pub fn dynamic_string<F>(input: &str, f: F)
|
||||
where
|
||||
F: FnMut(String) + 'static,
|
||||
{
|
||||
|
@ -55,7 +56,7 @@ where
|
|||
let _: String = std::mem::replace(&mut label_parts[i], out);
|
||||
|
||||
let string = label_parts.join("");
|
||||
try_send!(tx, string);
|
||||
tx.send_spawn(string);
|
||||
}
|
||||
})
|
||||
.await;
|
||||
|
@ -80,7 +81,7 @@ where
|
|||
let _: String = std::mem::replace(&mut label_parts[i], value);
|
||||
|
||||
let string = label_parts.join("");
|
||||
try_send!(tx, string);
|
||||
tx.send_spawn(string);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -88,12 +89,12 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
glib_recv_mpsc!(rx , val => f(val));
|
||||
rx.recv_glib(f);
|
||||
|
||||
// initialize
|
||||
if is_static {
|
||||
let label_parts = lock!(label_parts).join("");
|
||||
try_send!(tx, label_parts);
|
||||
tx.send_spawn(label_parts);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue