Skip to content

Commit

Permalink
Improve argument names and help.
Browse files Browse the repository at this point in the history
  • Loading branch information
fyodordev committed May 9, 2023
1 parent 168ab5b commit 646174b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ struct Args {
#[arg(short, long)]
image: String,

/// Cache Path
/// Set custom save path for image fragments.
#[arg(short, long)]
cache_path: Option<String>,
output_path: Option<String>,

/// Force Resplit even if cache exists
#[arg(short, long)]
Expand All @@ -23,19 +23,19 @@ struct Args {
#[arg(short, long)]
no_downscale: bool,

/// Don't downscale base image, even if it's bigger than needed
/// Do not set wallpaper immediately.
#[arg(short, long)]
dont_set: bool,

/// Don't downscale base image, even if it's bigger than needed
/// Do not put config lines.
#[arg(short, long)]
silent: bool,
}

#[derive(Clone, Hash)]
pub struct AppConfig {
pub image_path: PathBuf,
pub cache_path: PathBuf,
pub output_path: PathBuf,
pub force_resplit: bool,
pub no_downscale: bool,
pub dont_set: bool,
Expand All @@ -57,8 +57,8 @@ impl AppConfig {

let home_dir = var("HOME").map_err(|_| "HOME env variable not set")?;
let default_cache_path = format!("{home_dir}/.cache/");
let cache_path_string = args.cache_path.unwrap_or(default_cache_path);
let cache_path = AppConfig::check_path(Path::new(&cache_path_string));
let output_path_string = args.output_path.unwrap_or(default_cache_path);
let output_path = AppConfig::check_path(Path::new(&output_path_string));

// construct
Ok(Self {
Expand All @@ -67,13 +67,13 @@ impl AppConfig {
no_downscale: args.no_downscale,
dont_set: args.dont_set,
silent: args.silent,
cache_path,
output_path,
})
}

pub fn resolve_cached_fragment_path(&self, monitor_name: &str, hash: &str) -> String {
// TODO: Work with path properly.
let base_path = self.cache_path.display();
let base_path = self.output_path.display();
format!("{base_path}swaybg_spread_{hash}_{monitor_name}.png")
}

Expand Down
7 changes: 7 additions & 0 deletions src/splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ impl Splitter {
// return either from cache or split.
if let Ok(result_fragments) = self.load_from_cache(image_hash.as_str()) {
// Return from cache.
println!("Returing from cache");
return Ok(result_fragments);
} else {
// Calculate fragments and save to file.
println!("Calculating fragments");
return self.perform_split(image, image_hash.as_str());
}
}
Expand Down Expand Up @@ -141,6 +143,11 @@ impl Splitter {
}

fn load_from_cache(&self, hash: &str) -> Result<Vec<ImageFragment>, String> {
if self.app_config.force_resplit {
println!("Force resplit");
return Err("Force resplit".to_string())
}

let mut result_fragments = Vec::new();

// check for every monitor
Expand Down

0 comments on commit 646174b

Please sign in to comment.