Skip to content

Commit

Permalink
feat(check): check for convert on launch #6
Browse files Browse the repository at this point in the history
 - check if convert can run
 - suggest installtion instruction on error case
  • Loading branch information
sassman committed Oct 12, 2020
1 parent 036b6dc commit e4f255e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/any/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ pub fn screenshot_and_save(
) -> anyhow::Result<()> {
unimplemented!("there is only an impl for MacOS")
}

// references for winRT
// https://github.com/robmikh/wgc-rust-demo/blob/master/src/main.rs
14 changes: 13 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use anyhow::Context;
use anyhow::Result;
use std::borrow::Borrow;
use std::ffi::OsStr;
use std::process::{Command, ExitStatus};
use std::process::{Command, ExitStatus, Output};
use std::sync::mpsc::Receiver;
use std::sync::{mpsc, Arc, Mutex};
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -48,6 +48,8 @@ fn main() -> Result<()> {
}
};

check_for_imagemagick()?;

// the nice thing is the cleanup on drop
let tempdir = Arc::new(Mutex::new(
TempDir::new().context("Cannot create tempdir.")?,
Expand Down Expand Up @@ -149,6 +151,16 @@ fn current_win_id() -> Result<u32> {
}
}

///
/// checks for imagemagick
/// and suggests the installation command if there are issues
fn check_for_imagemagick() -> Result<Output> {
Command::new("convert")
.arg("--version")
.output()
.context("There is an issue with 'convert', make sure you have it installed: `brew install imagemagick`")
}

///
/// generating the final gif with help of convert
fn generate_gif_with_convert(time_codes: &[u128], tempdir: &TempDir) -> Result<()> {
Expand Down

0 comments on commit e4f255e

Please sign in to comment.