From 892bfc53eb7a90aae5bf12b8dac4bd0a3c8bb688 Mon Sep 17 00:00:00 2001 From: Daniel Rainer Date: Thu, 7 Nov 2024 23:01:31 +0100 Subject: [PATCH 1/4] Allow configuring block in external file This allows including the same block config in multiple configuration files, similar to the way themes and icons are handled. Additional options specified for a block in the main config file are silently ignored at the moment. --- src/blocks.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/blocks.rs b/src/blocks.rs index f00a294547..be265016b5 100644 --- a/src/blocks.rs +++ b/src/blocks.rs @@ -35,6 +35,7 @@ use serde::de::{self, Deserialize}; use tokio::sync::{mpsc, Notify}; use std::borrow::Cow; +use std::path::PathBuf; use std::sync::Arc; use std::time::Duration; @@ -43,6 +44,8 @@ use crate::errors::*; use crate::widget::Widget; use crate::{BoxedFuture, Request, RequestCmd}; +use crate::util; + macro_rules! define_blocks { { $( @@ -135,7 +138,17 @@ macro_rules! define_blocks { ))), )? )* - other => Err(D::Error::custom(format!("unknown block '{other}'"))) + other => { + match util::find_file(other, Some("blocks"), Some("toml")) { + Some(file) => match util::deserialize_toml_file::(file) { + Ok(config) => Ok(config), + Err(err) => Err(D::Error::custom(format!("error in block file '{other}': {err}"))) + } + None => { + Err(D::Error::custom(format!("unknown block '{other}'"))) + } + } + } } } } From c47f7191225f1ab8b94e90d1a34da057205b74c5 Mon Sep 17 00:00:00 2001 From: Daniel Rainer Date: Thu, 7 Nov 2024 23:53:18 +0100 Subject: [PATCH 2/4] Warn about using ignored config options --- src/blocks.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/blocks.rs b/src/blocks.rs index be265016b5..ed797b1e54 100644 --- a/src/blocks.rs +++ b/src/blocks.rs @@ -141,7 +141,13 @@ macro_rules! define_blocks { other => { match util::find_file(other, Some("blocks"), Some("toml")) { Some(file) => match util::deserialize_toml_file::(file) { - Ok(config) => Ok(config), + Ok(config) => { + if table.is_empty() { + Ok(config) + } else { + Err(D::Error::custom(format!("specifying additional options for {other} at location of inclusion is unsupported"))) + } + }, Err(err) => Err(D::Error::custom(format!("error in block file '{other}': {err}"))) } None => { From 472aeb56a7f98cff75d4c26f0d856456d5d3d68d Mon Sep 17 00:00:00 2001 From: Daniel Rainer Date: Thu, 7 Nov 2024 23:55:43 +0100 Subject: [PATCH 3/4] Fix "the the" typos --- src/blocks.rs | 6 +++--- src/blocks/hueshift.rs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/blocks.rs b/src/blocks.rs index ed797b1e54..752d954849 100644 --- a/src/blocks.rs +++ b/src/blocks.rs @@ -165,7 +165,7 @@ define_blocks!( amd_gpu, #[deprecated( since = "0.33.0", - note = "The block has been deprecated in favor of the the packages block" + note = "The block has been deprecated in favor of the packages block" )] apt, backlight, @@ -178,7 +178,7 @@ define_blocks!( disk_space, #[deprecated( since = "0.33.0", - note = "The block has been deprecated in favor of the the packages block" + note = "The block has been deprecated in favor of the packages block" )] dnf, docker, @@ -201,7 +201,7 @@ define_blocks!( packages, #[deprecated( since = "0.33.0", - note = "The block has been deprecated in favor of the the packages block" + note = "The block has been deprecated in favor of the packages block" )] pacman, pomodoro, diff --git a/src/blocks/hueshift.rs b/src/blocks/hueshift.rs index 9740016bff..9d3bd89b43 100644 --- a/src/blocks/hueshift.rs +++ b/src/blocks/hueshift.rs @@ -316,7 +316,7 @@ impl HueShiftDriver for Wlsunset { // night temp: 4000K // latitude/longitude: NaN // ^ results in sun_condition == POLAR_NIGHT at time of testing - // With these defaults, this results in the the color temperature + // With these defaults, this results in the color temperature // getting set to 4000K. spawn_process("pkill", &["wlsunset"]) .error("Failed to set new color temperature using wlsunset.") From 7a22f6d0c2a884ac29d4a0c361a3819ae81ce9ea Mon Sep 17 00:00:00 2001 From: Daniel Rainer Date: Fri, 8 Nov 2024 00:13:24 +0100 Subject: [PATCH 4/4] Make type annotation implicit --- src/blocks.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/blocks.rs b/src/blocks.rs index 752d954849..4cbc9df0f7 100644 --- a/src/blocks.rs +++ b/src/blocks.rs @@ -35,7 +35,6 @@ use serde::de::{self, Deserialize}; use tokio::sync::{mpsc, Notify}; use std::borrow::Cow; -use std::path::PathBuf; use std::sync::Arc; use std::time::Duration; @@ -140,7 +139,7 @@ macro_rules! define_blocks { )* other => { match util::find_file(other, Some("blocks"), Some("toml")) { - Some(file) => match util::deserialize_toml_file::(file) { + Some(file) => match util::deserialize_toml_file::(file) { Ok(config) => { if table.is_empty() { Ok(config)