Skip to content

Commit

Permalink
make cli arg handling and split decisions simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
0xk1f0 committed Apr 27, 2023
1 parent e878457 commit ca16a1b
Showing 1 changed file with 21 additions and 37 deletions.
58 changes: 21 additions & 37 deletions src/splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Splitter {
let img = image::open(
&config.image_path
).map_err(
|err| err.to_string()
|_| "failed to open image"
)?;

// fetch monitors
Expand All @@ -51,21 +51,6 @@ impl Splitter {

// check if we need to generate wpaperd config
if config.with_wpaperd {
// check caches and config force bool
if
self.check_caches() &&
! config.force_resplit
{
// caches exist
// run wrapper if wpaperd is enabled
cmd_wrapper().map_err(
|err| err.to_string()
)?;

// exit
return Ok(())
}

// create new wpaperd instance
let wpaperd = WpaperdConfig::new(
format!(
Expand All @@ -75,37 +60,36 @@ impl Splitter {
self.hash.clone()
);

// check caches
let caches_present = self.check_caches();

//check wpaper config hash
if
self.check_caches() &&
! config.force_resplit
{
if let false = wpaperd.check_existing().map_err(
|err| err.to_string()
)? {
// we need to rebuild
self.result_papers = self.perform_split(
img,
config,
format!("{}/.cache/",var("HOME").unwrap())
).map_err(
|err| err.to_string()
)?;
let wpaperd_present = wpaperd.check_existing().map_err(
|err| err.to_string()
)?;

wpaperd.build(&self.result_papers).map_err(
|err| err.to_string()
)?;
}
} else {
// we need to rebuild
// do we need to resplit
if
config.force_resplit ||
! caches_present
{
// yes we need to resplit
self.result_papers = self.perform_split(
img,
config,
format!("{}/.cache/",var("HOME").unwrap())
).map_err(
|err| err.to_string()
)?;
}

// do we need to rebuild config
// also always rebuild when force resplit was set
if
config.force_resplit ||
! wpaperd_present
{
// yes we do
wpaperd.build(&self.result_papers).map_err(
|err| err.to_string()
)?;
Expand Down

0 comments on commit ca16a1b

Please sign in to comment.