Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using block definitions from separate files #2099

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ use crate::errors::*;
use crate::widget::Widget;
use crate::{BoxedFuture, Request, RequestCmd};

use crate::util;

macro_rules! define_blocks {
{
$(
Expand Down Expand Up @@ -135,7 +137,23 @@ 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::<BlockConfig, _>(file) {
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 => {
Err(D::Error::custom(format!("unknown block '{other}'")))
}
}
}
}
}
}
Expand All @@ -146,7 +164,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,
Expand All @@ -159,7 +177,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,
Expand All @@ -182,7 +200,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,
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/hueshift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down