Skip to content

Commit

Permalink
feat(config): Ditch reload_apps; add a prototype for better wallpap…
Browse files Browse the repository at this point in the history
…er configuration
  • Loading branch information
ys5g committed Oct 18, 2024
1 parent 324eee3 commit 2f9af44
Show file tree
Hide file tree
Showing 8 changed files with 173 additions and 192 deletions.
10 changes: 10 additions & 0 deletions idea.throwAway
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
`nix
config.wallpaper = {
set = true;
command = "swww";
arguments = [
"{{image}}"
"--transition-type" "center"
];
}
`
23 changes: 8 additions & 15 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,21 @@ pub fn set_wallpaper(source: &Source, config: &Config) -> Result<(), Report> {
#[cfg(feature = "web-image")]
Source::WebImage { .. } => return Ok(()),
};
#[cfg(any(target_os = "linux", target_os = "netbsd"))]
let wallpaper_tool = match &config.wallpaper_tool {
Some(wallpaper_tool) => wallpaper_tool,
None => {
if cfg!(windows) {
return Ok(());
}
return Ok(warn!(
"<d>Wallpaper tool not set, not setting wallpaper...</>"
));
}
};
if config.wallpaper.is_none() {
return Ok(warn!(
"<d>Wallpaper setting disabled, not setting wallpaper...</>"
));
}
#[cfg(target_os = "windows")]
wallpaper::windows::set(path)?;
#[cfg(target_os = "macos")]
wallpaper::macos::set(&path)?;
#[cfg(any(target_os = "linux", target_os = "netbsd"))]
wallpaper::unix::set(
path,
wallpaper_tool,
&config.feh_options,
&config.swww_options,
&(config.wallpaper).clone().unwrap().command,
&(config.wallpaper).clone().unwrap().pre_hook,
&(config.wallpaper).clone().unwrap().arguments
)?;
Ok(())
}
9 changes: 2 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extern crate pretty_env_logger;
extern crate paris_log;

mod helpers;
mod reload;
// mod reload;
pub mod template;
mod util;
mod wallpaper;
Expand Down Expand Up @@ -77,12 +77,7 @@ fn main() -> Result<(), Report> {
config_path,
)?;

if config.config.reload_apps == Some(true) {
#[cfg(any(target_os = "linux", target_os = "netbsd"))]
reload::unix::reload(&args, &config)?;
}

if config.config.set_wallpaper == Some(true) {
if config.config.wallpaper.is_some() {
set_wallpaper(&args.source, &config.config)?;
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/reload/mod.rs

This file was deleted.

73 changes: 0 additions & 73 deletions src/reload/unix.rs

This file was deleted.

24 changes: 13 additions & 11 deletions src/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,27 @@ use serde::{Deserialize, Serialize};

use super::arguments::Cli;
use crate::Template;
use crate::wallpaper::Wallpaper;

#[derive(Serialize, Deserialize, Debug)]
pub enum WallpaperTool {
Swaybg,
Swww,
Nitrogen,
Feh,
}
// #[derive(Serialize, Deserialize, Debug)]
// pub enum WallpaperTool {
// Swaybg,
// Swww,
// Nitrogen,
// Feh,
// }

#[derive(Serialize, Deserialize, Debug)]
pub struct Config {
pub reload_apps: Option<bool>,
pub version_check: Option<bool>,
pub reload_apps_list: Option<Apps>,
pub set_wallpaper: Option<bool>,
pub wallpaper_tool: Option<WallpaperTool>,
// TODO: Add a `Command` struct
pub swww_options: Option<Vec<String>>,
pub wallpaper: Option<Wallpaper>,
// pub set_wallpaper: Option<bool>,
// pub wallpaper_tool: Option<WallpaperTool>,
// pub swww_options: Option<Vec<String>>,
pub feh_options: Option<Vec<String>>,
// TODO: Add a `Command` struct
pub prefix: Option<String>,
pub custom_keywords: Option<HashMap<String, String>>,
pub custom_colors: Option<HashMap<String, matugen::color::color::OwnCustomColor>>,
Expand Down
13 changes: 13 additions & 0 deletions src/wallpaper/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Wallpaper {
pub set: bool,
/// Useful for, for example, killing the wallpaper daemon
pub pre_hook: Option<String>,
pub command: String,
/// The last argument will be the image path
pub arguments: Option<Vec<String>>,
}


#[cfg(any(target_os = "linux", target_os = "netbsd"))]
pub mod unix;

Expand Down
Loading

0 comments on commit 2f9af44

Please sign in to comment.