Skip to content

Commit

Permalink
feat(config): Completely remove reload_apps; get config.wallpaper
Browse files Browse the repository at this point in the history
… to work
  • Loading branch information
ys5g committed Oct 18, 2024
1 parent 2f9af44 commit 059c989
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 163 deletions.
10 changes: 0 additions & 10 deletions idea.throwAway

This file was deleted.

12 changes: 5 additions & 7 deletions src/helpers.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -56,28 +56,26 @@ 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!(
"<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,
&(config.wallpaper).clone().unwrap().command,
&(config.wallpaper).clone().unwrap().pre_hook,
&(config.wallpaper).clone().unwrap().arguments
wallpaper_cfg
)?;
Ok(())
}
5 changes: 2 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ extern crate pretty_env_logger;
extern crate paris_log;

mod helpers;
// mod reload;
pub mod template;
mod util;
mod wallpaper;
Expand Down Expand Up @@ -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)?;
}
}

Expand Down
23 changes: 0 additions & 23 deletions src/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>,
pub version_check: Option<bool>,
pub reload_apps_list: Option<Apps>,
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>>,
}

#[derive(Deserialize, Serialize, Debug)]
pub struct Apps {
pub kitty: Option<bool>,
pub waybar: Option<bool>,
pub gtk_theme: Option<bool>,
pub dunst: Option<bool>,
pub mako: Option<bool>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ConfigFile {
pub config: Config,
Expand Down
3 changes: 1 addition & 2 deletions src/wallpaper/mod.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -10,7 +10,6 @@ pub struct Wallpaper {
pub arguments: Option<Vec<String>>,
}


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

Expand Down
133 changes: 15 additions & 118 deletions src/wallpaper/unix.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,35 @@
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<String>,
arguments: &Option<Vec<String>>,
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);
}
cmd.arg(path);


match cmd.spawn() {
Ok(_) => info!("Successfully set the wallpaper with <blue>{wallpaper_cmd}</>"),
Ok(_) => info!("Successfully set the wallpaper with <blue>{command}</>"),
Err(e) => {
if let std::io::ErrorKind::NotFound = e.kind() {
error!("Failed to set wallpaper, the program <red>{wallpaper_cmd}</> was not found in PATH!")
error!("Failed to set wallpaper, the program <red>{command}</> was not found in PATH!")
} else {
error!("Some error(s) occured while setting wallpaper!");
}
Expand All @@ -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());

Expand All @@ -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 <blue>swaybg</>"),
// Err(e) => {
// if let std::io::ErrorKind::NotFound = e.kind() {
// error!("Failed to set wallpaper, the program <red>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<Vec<String>>) -> 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 <blue>swww</>"),
// Err(e) => {
// if let std::io::ErrorKind::NotFound = e.kind() {
// error!("Failed to set wallpaper, the program <red>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 <blue>nitrogen</>"),
// Err(e) => {
// if let std::io::ErrorKind::NotFound = e.kind() {
// error!(
// "Failed to set wallpaper, the program <red>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<Vec<String>>) -> 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 <blue>feh</>"),
// Err(e) => {
// if let std::io::ErrorKind::NotFound = e.kind() {
// error!("Failed to set wallpaper, the program <red>feh</> was not found in PATH!")
// } else {
// error!("Some error(s) occured while setting wallpaper!");
// }
// }
// };
// Ok(())
// }

0 comments on commit 059c989

Please sign in to comment.