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

refactor: macros to reduce repeated code

This commit is contained in:
Jake Stanger 2022-12-11 22:45:52 +00:00
parent 9d5049dde0
commit 5e21cbcca6
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
18 changed files with 225 additions and 248 deletions

View file

@ -1,5 +1,5 @@
use crate::error;
use crate::script::{OutputStream, Script};
use crate::{lock, send};
use gtk::prelude::*;
use indexmap::IndexMap;
use std::sync::{Arc, Mutex};
@ -66,10 +66,7 @@ impl DynamicString {
for (i, segment) in segments.into_iter().enumerate() {
match segment {
DynamicStringSegment::Static(str) => {
label_parts
.lock()
.expect(error::ERR_MUTEX_LOCK)
.insert(i, str);
lock!(label_parts).insert(i, str);
}
DynamicStringSegment::Dynamic(script) => {
let tx = tx.clone();
@ -79,20 +76,16 @@ impl DynamicString {
script
.run(|(out, _)| {
if let OutputStream::Stdout(out) = out {
let mut label_parts =
label_parts.lock().expect(error::ERR_MUTEX_LOCK);
let mut label_parts = lock!(label_parts);
label_parts
// .lock()
// .expect("Failed to get lock on label parts")
.insert(i, out);
label_parts.insert(i, out);
let string = label_parts
.iter()
.map(|(_, part)| part.as_str())
.collect::<String>();
tx.send(string).expect(error::ERR_CHANNEL_SEND);
send!(tx, string);
}
})
.await;
@ -103,14 +96,12 @@ impl DynamicString {
// initialize
{
let label_parts = label_parts
.lock()
.expect(error::ERR_MUTEX_LOCK)
let label_parts = lock!(label_parts)
.iter()
.map(|(_, part)| part.as_str())
.collect::<String>();
tx.send(label_parts).expect(error::ERR_CHANNEL_SEND);
send!(tx, label_parts);
}
rx.attach(None, f);