From 324eee37e77bcf6941f788d0853b3be597ddeb0d Mon Sep 17 00:00:00 2001 From: TanX-009 Date: Sun, 13 Oct 2024 08:38:10 +0530 Subject: [PATCH 1/3] feat: custom expr and block prefix, postfix fix: revert keywords to custom_keywords --- src/template.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/template.rs b/src/template.rs index 0bb64c4..f3ffaf4 100644 --- a/src/template.rs +++ b/src/template.rs @@ -39,6 +39,10 @@ pub struct Template { pub compare_to: Option, pub pre_hook: Option, pub post_hook: Option, + pub expr_prefix: Option, + pub expr_postfix: Option, + pub block_prefix: Option, + pub block_postfix: Option, } #[allow(clippy::manual_strip)] @@ -78,11 +82,6 @@ impl Template { ) -> Result<(), Report> { info!("Loaded {} templates.", &templates.len()); - let syntax = Syntax::builder().expr("{{", "}}").block("<*", "*>").build(); - let mut engine = Engine::with_syntax(syntax); - - add_engine_filters(&mut engine); - let image = match &source { Source::Image { path } => Some(path), #[cfg(feature = "web-image")] @@ -99,6 +98,19 @@ impl Template { )?; for (i, (name, template)) in templates.iter().enumerate() { + let expr_prefix = template.expr_prefix.as_deref().unwrap_or("{{"); + let expr_postfix = template.expr_postfix.as_deref().unwrap_or("}}"); + let block_prefix = template.block_prefix.as_deref().unwrap_or("<*"); + let block_postfix = template.block_postfix.as_deref().unwrap_or("*>"); + + let syntax = Syntax::builder() + .expr(expr_prefix, expr_postfix) + .block(block_prefix, block_postfix) + .build(); + let mut engine = Engine::with_syntax(syntax); + + add_engine_filters(&mut engine); + let (input_path_absolute, output_path_absolute) = get_absolute_paths(&config_path, template)?; From 2f9af444aa1256ae2d77c714dad804001627be82 Mon Sep 17 00:00:00 2001 From: YS5G Date: Thu, 10 Oct 2024 15:01:38 -0400 Subject: [PATCH 2/3] feat(config): Ditch `reload_apps`; add a prototype for better wallpaper configuration --- idea.throwAway | 10 ++ src/helpers.rs | 23 ++--- src/main.rs | 9 +- src/reload/mod.rs | 2 - src/reload/unix.rs | 73 --------------- src/util/config.rs | 24 ++--- src/wallpaper/mod.rs | 13 +++ src/wallpaper/unix.rs | 211 +++++++++++++++++++++++++----------------- 8 files changed, 173 insertions(+), 192 deletions(-) create mode 100644 idea.throwAway delete mode 100644 src/reload/mod.rs delete mode 100644 src/reload/unix.rs diff --git a/idea.throwAway b/idea.throwAway new file mode 100644 index 0000000..91c9257 --- /dev/null +++ b/idea.throwAway @@ -0,0 +1,10 @@ +`nix + config.wallpaper = { + set = true; + command = "swww"; + arguments = [ + "{{image}}" + "--transition-type" "center" + ]; + } +` diff --git a/src/helpers.rs b/src/helpers.rs index 4372abd..e0e438e 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -63,18 +63,11 @@ 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!( - "Wallpaper tool not set, not setting wallpaper..." - )); - } - }; + if config.wallpaper.is_none() { + return Ok(warn!( + "Wallpaper setting disabled, not setting wallpaper..." + )); + } #[cfg(target_os = "windows")] wallpaper::windows::set(path)?; #[cfg(target_os = "macos")] @@ -82,9 +75,9 @@ pub fn set_wallpaper(source: &Source, config: &Config) -> Result<(), Report> { #[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(()) } diff --git a/src/main.rs b/src/main.rs index 5772d11..87de4bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; @@ -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)?; } } diff --git a/src/reload/mod.rs b/src/reload/mod.rs deleted file mode 100644 index 824b010..0000000 --- a/src/reload/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -#[cfg(any(target_os = "linux", target_os = "netbsd"))] -pub mod unix; diff --git a/src/reload/unix.rs b/src/reload/unix.rs deleted file mode 100644 index 85543c0..0000000 --- a/src/reload/unix.rs +++ /dev/null @@ -1,73 +0,0 @@ -use crate::util::{arguments::Cli, config::ConfigFile}; -use color_eyre::{eyre::Result, Report}; - -use std::process::Command; - -use crate::SchemesEnum; - -#[cfg(any(target_os = "linux", target_os = "netbsd"))] -pub fn reload(args: &Cli, config: &ConfigFile) -> Result<(), Report> { - if config.config.reload_apps_list.is_none() { - warn!("The option config.reload_apps is set to TRUE, but config.reload_apps_list is EMPTY. Not restarting any apps..."); - return Ok(()); - } - - let reload_apps_list = &config.config.reload_apps_list.as_ref().unwrap(); - - if reload_apps_list.waybar == Some(true) || reload_apps_list.waybar.is_none() { - reload_app("waybar", "SIGUSR2")?; - } - - if reload_apps_list.kitty == Some(true) || reload_apps_list.waybar.is_none() { - reload_app("kitty", "SIGUSR1")?; - } - - if reload_apps_list.dunst == Some(true) || reload_apps_list.waybar.is_none() { - reload_app("dunst", "SIGUSR2")?; - } - - if reload_apps_list.gtk_theme == Some(true) || reload_apps_list.waybar.is_none() { - reload_gtk_theme(args)?; - } - - if reload_apps_list.mako == Some(true) || reload_apps_list.waybar.is_none() { - reload_app("mako", "SIGUSR2")?; - } - - Ok(()) -} - -#[cfg(any(target_os = "linux", target_os = "netbsd"))] -pub fn reload_app(name: &str, signal: &str) -> Result<(), Report> { - info!("Restarting {}", name); - let mut kill = Command::new("pkill"); - kill.arg(format!("-{}", signal)); - kill.arg(name); - - kill.spawn()?; - Ok(()) -} - -#[cfg(any(target_os = "linux", target_os = "netbsd"))] -fn reload_gtk_theme(args: &Cli) -> Result<(), Report> { - let mode = match args.mode { - Some(SchemesEnum::Light) => "light", - Some(SchemesEnum::Dark) => "dark", - None => "dark", - }; - - info!("Setting gtk theme to adw-gtk3-{}", mode); - - set_theme("")?; - set_theme(format!("adw-gtk3-{}", mode).as_str())?; - Ok(()) -} - -#[cfg(any(target_os = "linux", target_os = "netbsd"))] -fn set_theme(theme: &str) -> Result<(), Report> { - Command::new("gsettings") - .args(["set", "org.gnome.desktop.interface", "gtk-theme", theme]) - .spawn()?; - - Ok(()) -} diff --git a/src/util/config.rs b/src/util/config.rs index 82d2602..7087274 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -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, pub version_check: Option, pub reload_apps_list: Option, - pub set_wallpaper: Option, - pub wallpaper_tool: Option, - // TODO: Add a `Command` struct - pub swww_options: Option>, + pub wallpaper: Option, + // pub set_wallpaper: Option, + // pub wallpaper_tool: Option, + // pub swww_options: Option>, pub feh_options: Option>, + // TODO: Add a `Command` struct pub prefix: Option, pub custom_keywords: Option>, pub custom_colors: Option>, diff --git a/src/wallpaper/mod.rs b/src/wallpaper/mod.rs index 9bc53c6..6b46bf2 100644 --- a/src/wallpaper/mod.rs +++ b/src/wallpaper/mod.rs @@ -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, + pub command: String, + /// The last argument will be the image path + pub arguments: Option>, +} + + #[cfg(any(target_os = "linux", target_os = "netbsd"))] pub mod unix; diff --git a/src/wallpaper/unix.rs b/src/wallpaper/unix.rs index 793ac9f..291ace7 100644 --- a/src/wallpaper/unix.rs +++ b/src/wallpaper/unix.rs @@ -2,40 +2,41 @@ use color_eyre::Report; use std::process::Command; use std::process::Stdio; -use crate::reload::unix::reload_app; -use crate::util::config::WallpaperTool; +// use crate::reload::unix::reload_app; + +use execute::Execute; #[cfg(any(target_os = "linux", target_os = "netbsd"))] pub fn set( path: &String, - wallpaper_tool: &WallpaperTool, - feh_options: &Option>, - swww_options: &Option>, + wallpaper_cmd: &String, + pre_hook: &Option, + arguments: &Option>, ) -> Result<(), Report> { - info!("Setting wallpaper..."); - - match &wallpaper_tool { - WallpaperTool::Swaybg => set_wallaper_swaybg(path), - WallpaperTool::Swww => set_wallaper_swww(path, swww_options), - WallpaperTool::Nitrogen => set_wallaper_nitrogen(path), - WallpaperTool::Feh => set_wallaper_feh(path, feh_options), + if let Some(hook) = pre_hook { + spawn_hook(&hook)?//.unwrap(); } -} - -#[cfg(any(target_os = "linux", target_os = "netbsd"))] -fn set_wallaper_swaybg(path: &String) -> Result<(), Report> { - reload_app("swaybg", "SIGUSR1")?; + info!("Setting wallpaper..."); - let mut binding = Command::new("swaybg"); + // match &wallpaper_tool { + // WallpaperTool::Swaybg => set_wallaper_swaybg(path), + // WallpaperTool::Swww => set_wallaper_swww(path, swww_options), + // WallpaperTool::Nitrogen => set_wallaper_nitrogen(path), + // WallpaperTool::Feh => set_wallaper_feh(path, feh_options), + // } + let mut binding = Command::new(wallpaper_cmd); let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); - cmd.arg("-i"); + if let Some(args) = arguments { + cmd.args(args); + } cmd.arg(path); + match cmd.spawn() { - Ok(_) => info!("Successfully set the wallpaper with swaybg"), + Ok(_) => info!("Successfully set the wallpaper with {wallpaper_cmd}"), Err(e) => { if let std::io::ErrorKind::NotFound = e.kind() { - error!("Failed to set wallpaper, the program swaybg was not found in PATH!") + error!("Failed to set wallpaper, the program {wallpaper_cmd} was not found in PATH!") } else { error!("Some error(s) occured while setting wallpaper!"); } @@ -44,77 +45,119 @@ fn set_wallaper_swaybg(path: &String) -> Result<(), Report> { Ok(()) } -#[cfg(any(target_os = "linux", target_os = "netbsd"))] -fn set_wallaper_swww(path: &String, swww_options: &Option>) -> Result<(), Report> { - let mut binding = Command::new("swww"); - let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); - cmd.arg("img"); - cmd.arg(path); - if let Some(options) = &swww_options { - if !options[0].is_empty() { - cmd.args(options); - } - } - - match cmd.spawn() { - Ok(_) => info!("Successfully set the wallpaper with swww"), - Err(e) => { - if let std::io::ErrorKind::NotFound = e.kind() { - error!("Failed to set wallpaper, the program swww was not found in PATH!") - } else { - error!("Some error(s) occured while setting wallpaper!"); - } - } - }; - Ok(()) -} #[cfg(any(target_os = "linux", target_os = "netbsd"))] -fn set_wallaper_nitrogen(path: &String) -> Result<(), Report> { - let mut binding = Command::new("nitrogen"); - let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); - cmd.arg(path); +fn spawn_hook(hook: &String) -> Result<(), Report> { + let mut command = execute::shell(hook); - match cmd.spawn() { - Ok(_) => info!("Successfully set the wallpaper with nitrogen"), - Err(e) => { - if let std::io::ErrorKind::NotFound = e.kind() { - error!( - "Failed to set wallpaper, the program nitrogen was not found in PATH!" - ) - } else { - error!("Some error(s) occured while setting wallpaper!"); - } - } - }; - Ok(()) -} + command.stdout(Stdio::inherit()); -#[cfg(any(target_os = "linux", target_os = "netbsd"))] -fn set_wallaper_feh(path: &String, feh_options: &Option>) -> Result<(), Report> { - let mut binding = Command::new("feh"); - let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); + let output = command.execute_output()?; - if let Some(options) = &feh_options { - if !options[0].is_empty() { - cmd.args(options); - } else { - cmd.arg("--bg-scale"); + if let Some(exit_code) = output.status.code() { + if exit_code != 0 { + error!("Failed executing command: {:?}", hook) } + } else { + eprintln!("Interrupted!"); } - cmd.arg(path); - - match cmd.spawn() { - Ok(_) => info!("Successfully set the wallpaper with feh"), - Err(e) => { - if let std::io::ErrorKind::NotFound = e.kind() { - error!("Failed to set wallpaper, the program feh was not found in PATH!") - } else { - error!("Some error(s) occured while setting wallpaper!"); - } - } - }; Ok(()) } +// #[cfg(any(target_os = "linux", target_os = "netbsd"))] +// fn set_wallaper_swaybg(path: &String) -> Result<(), Report> { +// reload_app("swaybg", "SIGUSR1")?; +// +// let mut binding = Command::new("swaybg"); +// let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); +// cmd.arg("-i"); +// cmd.arg(path); +// +// match cmd.spawn() { +// Ok(_) => info!("Successfully set the wallpaper with swaybg"), +// Err(e) => { +// if let std::io::ErrorKind::NotFound = e.kind() { +// error!("Failed to set wallpaper, the program swaybg was not found in PATH!") +// } else { +// error!("Some error(s) occured while setting wallpaper!"); +// } +// } +// }; +// Ok(()) +// } +// +// #[cfg(any(target_os = "linux", target_os = "netbsd"))] +// fn set_wallaper_swww(path: &String, swww_options: &Option>) -> Result<(), Report> { +// let mut binding = Command::new("swww"); +// let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); +// cmd.arg("img"); +// cmd.arg(path); +// +// if let Some(options) = &swww_options { +// if !options[0].is_empty() { +// cmd.args(options); +// } +// } +// +// match cmd.spawn() { +// Ok(_) => info!("Successfully set the wallpaper with swww"), +// Err(e) => { +// if let std::io::ErrorKind::NotFound = e.kind() { +// error!("Failed to set wallpaper, the program swww was not found in PATH!") +// } else { +// error!("Some error(s) occured while setting wallpaper!"); +// } +// } +// }; +// Ok(()) +// } +// +// #[cfg(any(target_os = "linux", target_os = "netbsd"))] +// fn set_wallaper_nitrogen(path: &String) -> Result<(), Report> { +// let mut binding = Command::new("nitrogen"); +// let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); +// cmd.arg(path); +// +// match cmd.spawn() { +// Ok(_) => info!("Successfully set the wallpaper with nitrogen"), +// Err(e) => { +// if let std::io::ErrorKind::NotFound = e.kind() { +// error!( +// "Failed to set wallpaper, the program nitrogen was not found in PATH!" +// ) +// } else { +// error!("Some error(s) occured while setting wallpaper!"); +// } +// } +// }; +// Ok(()) +// } +// +// #[cfg(any(target_os = "linux", target_os = "netbsd"))] +// fn set_wallaper_feh(path: &String, feh_options: &Option>) -> Result<(), Report> { +// let mut binding = Command::new("feh"); +// let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); +// +// if let Some(options) = &feh_options { +// if !options[0].is_empty() { +// cmd.args(options); +// } else { +// cmd.arg("--bg-scale"); +// } +// } +// +// cmd.arg(path); +// +// match cmd.spawn() { +// Ok(_) => info!("Successfully set the wallpaper with feh"), +// Err(e) => { +// if let std::io::ErrorKind::NotFound = e.kind() { +// error!("Failed to set wallpaper, the program feh was not found in PATH!") +// } else { +// error!("Some error(s) occured while setting wallpaper!"); +// } +// } +// }; +// Ok(()) +// } From 059c989c639942fe05af568bc8cac27e641fecd5 Mon Sep 17 00:00:00 2001 From: YS5G Date: Thu, 17 Oct 2024 15:27:44 -0400 Subject: [PATCH 3/3] feat(config): Completely remove `reload_apps`; get `config.wallpaper` to work --- idea.throwAway | 10 ---- src/helpers.rs | 12 ++-- src/main.rs | 5 +- src/util/config.rs | 23 -------- src/wallpaper/mod.rs | 3 +- src/wallpaper/unix.rs | 133 +++++------------------------------------- 6 files changed, 23 insertions(+), 163 deletions(-) delete mode 100644 idea.throwAway diff --git a/idea.throwAway b/idea.throwAway deleted file mode 100644 index 91c9257..0000000 --- a/idea.throwAway +++ /dev/null @@ -1,10 +0,0 @@ -`nix - config.wallpaper = { - set = true; - command = "swww"; - arguments = [ - "{{image}}" - "--transition-type" "center" - ]; - } -` diff --git a/src/helpers.rs b/src/helpers.rs index e0e438e..73b5ef8 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -1,4 +1,4 @@ -use crate::{util::config::Config, wallpaper}; +use crate::wallpaper; use color_eyre::{eyre::Result, Report}; use log::LevelFilter; use matugen::color::color::Source; @@ -56,18 +56,18 @@ pub fn setup_logging(args: &Cli) -> Result<(), Report> { Ok(()) } -pub fn set_wallpaper(source: &Source, config: &Config) -> Result<(), Report> { +pub fn set_wallpaper(source: &Source, wallpaper_cfg: wallpaper::Wallpaper) -> Result<(), Report> { let path = match &source { Source::Image { path } => path, Source::Color { .. } => return Ok(()), #[cfg(feature = "web-image")] Source::WebImage { .. } => return Ok(()), }; - if config.wallpaper.is_none() { + if !wallpaper_cfg.set { return Ok(warn!( "Wallpaper setting disabled, not setting wallpaper..." )); - } + }; #[cfg(target_os = "windows")] wallpaper::windows::set(path)?; #[cfg(target_os = "macos")] @@ -75,9 +75,7 @@ pub fn set_wallpaper(source: &Source, config: &Config) -> Result<(), Report> { #[cfg(any(target_os = "linux", target_os = "netbsd"))] wallpaper::unix::set( path, - &(config.wallpaper).clone().unwrap().command, - &(config.wallpaper).clone().unwrap().pre_hook, - &(config.wallpaper).clone().unwrap().arguments + wallpaper_cfg )?; Ok(()) } diff --git a/src/main.rs b/src/main.rs index 87de4bf..dbee85d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,6 @@ extern crate pretty_env_logger; extern crate paris_log; mod helpers; -// mod reload; pub mod template; mod util; mod wallpaper; @@ -77,8 +76,8 @@ fn main() -> Result<(), Report> { config_path, )?; - if config.config.wallpaper.is_some() { - set_wallpaper(&args.source, &config.config)?; + if let Some(wallpaper_cfg) = config.config.wallpaper { + set_wallpaper(&args.source, wallpaper_cfg)?; } } diff --git a/src/util/config.rs b/src/util/config.rs index 7087274..4f1655c 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -11,39 +11,16 @@ 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 struct Config { - pub reload_apps: Option, pub version_check: Option, - pub reload_apps_list: Option, pub wallpaper: Option, - // pub set_wallpaper: Option, - // pub wallpaper_tool: Option, - // pub swww_options: Option>, - pub feh_options: Option>, // TODO: Add a `Command` struct pub prefix: Option, pub custom_keywords: Option>, pub custom_colors: Option>, } -#[derive(Deserialize, Serialize, Debug)] -pub struct Apps { - pub kitty: Option, - pub waybar: Option, - pub gtk_theme: Option, - pub dunst: Option, - pub mako: Option, -} - #[derive(Serialize, Deserialize, Debug)] pub struct ConfigFile { pub config: Config, diff --git a/src/wallpaper/mod.rs b/src/wallpaper/mod.rs index 6b46bf2..a261724 100644 --- a/src/wallpaper/mod.rs +++ b/src/wallpaper/mod.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize, Debug, Clone)] +#[derive(Clone, Debug, Deserialize, Serialize)] pub struct Wallpaper { pub set: bool, /// Useful for, for example, killing the wallpaper daemon @@ -10,7 +10,6 @@ pub struct Wallpaper { pub arguments: Option>, } - #[cfg(any(target_os = "linux", target_os = "netbsd"))] pub mod unix; diff --git a/src/wallpaper/unix.rs b/src/wallpaper/unix.rs index 291ace7..084dd7f 100644 --- a/src/wallpaper/unix.rs +++ b/src/wallpaper/unix.rs @@ -1,31 +1,24 @@ use color_eyre::Report; -use std::process::Command; -use std::process::Stdio; - -// use crate::reload::unix::reload_app; - +use std::process::{Command, Stdio}; +use crate::wallpaper::Wallpaper; use execute::Execute; #[cfg(any(target_os = "linux", target_os = "netbsd"))] pub fn set( path: &String, - wallpaper_cmd: &String, - pre_hook: &Option, - arguments: &Option>, + Wallpaper { pre_hook, command, arguments, .. }: Wallpaper, ) -> Result<(), Report> { + info!("Setting wallpaper..."); + if let Some(hook) = pre_hook { - spawn_hook(&hook)?//.unwrap(); + spawn_hook(hook)? } - info!("Setting wallpaper..."); - // match &wallpaper_tool { - // WallpaperTool::Swaybg => set_wallaper_swaybg(path), - // WallpaperTool::Swww => set_wallaper_swww(path, swww_options), - // WallpaperTool::Nitrogen => set_wallaper_nitrogen(path), - // WallpaperTool::Feh => set_wallaper_feh(path, feh_options), - // } - let mut binding = Command::new(wallpaper_cmd); - let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); + let mut binding = Command::new(&command); + let cmd = binding + .stdout(Stdio::null()) + .stderr(Stdio::null()); + if let Some(args) = arguments { cmd.args(args); } @@ -33,10 +26,10 @@ pub fn set( match cmd.spawn() { - Ok(_) => info!("Successfully set the wallpaper with {wallpaper_cmd}"), + Ok(_) => info!("Successfully set the wallpaper with {command}"), Err(e) => { if let std::io::ErrorKind::NotFound = e.kind() { - error!("Failed to set wallpaper, the program {wallpaper_cmd} was not found in PATH!") + error!("Failed to set wallpaper, the program {command} was not found in PATH!") } else { error!("Some error(s) occured while setting wallpaper!"); } @@ -48,8 +41,8 @@ pub fn set( #[cfg(any(target_os = "linux", target_os = "netbsd"))] -fn spawn_hook(hook: &String) -> Result<(), Report> { - let mut command = execute::shell(hook); +fn spawn_hook(hook: String) -> Result<(), Report> { + let mut command = execute::shell(&hook); command.stdout(Stdio::inherit()); @@ -65,99 +58,3 @@ fn spawn_hook(hook: &String) -> Result<(), Report> { Ok(()) } -// #[cfg(any(target_os = "linux", target_os = "netbsd"))] -// fn set_wallaper_swaybg(path: &String) -> Result<(), Report> { -// reload_app("swaybg", "SIGUSR1")?; -// -// let mut binding = Command::new("swaybg"); -// let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); -// cmd.arg("-i"); -// cmd.arg(path); -// -// match cmd.spawn() { -// Ok(_) => info!("Successfully set the wallpaper with swaybg"), -// Err(e) => { -// if let std::io::ErrorKind::NotFound = e.kind() { -// error!("Failed to set wallpaper, the program swaybg was not found in PATH!") -// } else { -// error!("Some error(s) occured while setting wallpaper!"); -// } -// } -// }; -// Ok(()) -// } -// -// #[cfg(any(target_os = "linux", target_os = "netbsd"))] -// fn set_wallaper_swww(path: &String, swww_options: &Option>) -> Result<(), Report> { -// let mut binding = Command::new("swww"); -// let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); -// cmd.arg("img"); -// cmd.arg(path); -// -// if let Some(options) = &swww_options { -// if !options[0].is_empty() { -// cmd.args(options); -// } -// } -// -// match cmd.spawn() { -// Ok(_) => info!("Successfully set the wallpaper with swww"), -// Err(e) => { -// if let std::io::ErrorKind::NotFound = e.kind() { -// error!("Failed to set wallpaper, the program swww was not found in PATH!") -// } else { -// error!("Some error(s) occured while setting wallpaper!"); -// } -// } -// }; -// Ok(()) -// } -// -// #[cfg(any(target_os = "linux", target_os = "netbsd"))] -// fn set_wallaper_nitrogen(path: &String) -> Result<(), Report> { -// let mut binding = Command::new("nitrogen"); -// let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); -// cmd.arg(path); -// -// match cmd.spawn() { -// Ok(_) => info!("Successfully set the wallpaper with nitrogen"), -// Err(e) => { -// if let std::io::ErrorKind::NotFound = e.kind() { -// error!( -// "Failed to set wallpaper, the program nitrogen was not found in PATH!" -// ) -// } else { -// error!("Some error(s) occured while setting wallpaper!"); -// } -// } -// }; -// Ok(()) -// } -// -// #[cfg(any(target_os = "linux", target_os = "netbsd"))] -// fn set_wallaper_feh(path: &String, feh_options: &Option>) -> Result<(), Report> { -// let mut binding = Command::new("feh"); -// let cmd = binding.stdout(Stdio::null()).stderr(Stdio::null()); -// -// if let Some(options) = &feh_options { -// if !options[0].is_empty() { -// cmd.args(options); -// } else { -// cmd.arg("--bg-scale"); -// } -// } -// -// cmd.arg(path); -// -// match cmd.spawn() { -// Ok(_) => info!("Successfully set the wallpaper with feh"), -// Err(e) => { -// if let std::io::ErrorKind::NotFound = e.kind() { -// error!("Failed to set wallpaper, the program feh was not found in PATH!") -// } else { -// error!("Some error(s) occured while setting wallpaper!"); -// } -// } -// }; -// Ok(()) -// }