diff --git a/.circleci/deploy/deploy.js b/.circleci/deploy/deploy.js index 766bf05..d1bb385 100644 --- a/.circleci/deploy/deploy.js +++ b/.circleci/deploy/deploy.js @@ -44,6 +44,11 @@ let currentVersion = cargoToml.filter(l => l.includes('version = '))[0].split(' console.log('Creating new release!'); + const clogStr = fs.readFileSync('CHANGELOG.md', 'utf8').toString(); + const clogLines = clogStr.split('\n#')[0].split('\n'); + clogLines.shift(); + const changelog = clogLines.join('\n'); + let newReleaseRes = await (await fetch(`${gh.url}repos/${gh.user}/${gh.repo}/releases`, { headers: gh.headers, method: 'POST', @@ -51,7 +56,8 @@ let currentVersion = cargoToml.filter(l => l.includes('version = '))[0].split(' tag_name: currentVersion, target_commitish: gh.branch, name: `Release v${currentVersion}`, - body: '', + // body: 'Please see the [changelog](CHANGELOG.md) for details!', + body: changelog, draft: false, prerelease: false }) diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..8ffda04 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# 0.1.2 +* Automatic update checks +* No longer creates a folder for downloaded library unless the format specifies it +* No longer overwrites output files +* Code refactoring diff --git a/Cargo.lock b/Cargo.lock index 1a8195a..4216d6a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,6 +81,11 @@ dependencies = [ "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "base64" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "bitflags" version = "1.2.1" @@ -204,7 +209,7 @@ dependencies = [ "idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "publicsuffix 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -616,17 +621,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "library-loader" -version = "0.1.1" +version = "0.1.2" dependencies = [ - "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "notify 5.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.9.22 (registry+https://github.com/rust-lang/crates.io-index)", "rpassword 4.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "zip 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1133,7 +1138,7 @@ dependencies = [ "mime 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "mime_guess 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1240,7 +1245,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.101" +version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "serde_derive 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1263,7 +1268,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1273,7 +1278,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1490,10 +1495,10 @@ dependencies = [ [[package]] name = "toml" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1694,6 +1699,7 @@ dependencies = [ "checksum backtrace 0.3.40 (registry+https://github.com/rust-lang/crates.io-index)" = "924c76597f0d9ca25d762c25a4d369d51267536465dc5064bdf0eb073ed477ea" "checksum backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6575f128516de27e3ce99689419835fce9643a9b215a14d2b5b685be018491" "checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" +"checksum base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" "checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" "checksum blake2b_simd 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)" = "5850aeee1552f495dd0250014cf64b82b7c8879a89d83b33bbdace2cc4f63182" "checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" @@ -1821,7 +1827,7 @@ dependencies = [ "checksum security-framework-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9636f8989cbf61385ae4824b98c1aaa54c994d7d8b41f11c601ed799f0549a56" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum serde 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)" = "9796c9b7ba2ffe7a9ce53c2287dfc48080f4b2b362fcc245a259b3a7201119dd" +"checksum serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4b39bd9b0b087684013a792c59e3e07a46a01d2322518d8a1104641a0b1be0" "checksum serde_derive 1.0.101 (registry+https://github.com/rust-lang/crates.io-index)" = "4b133a43a1ecd55d4086bd5b4dc6c1751c68b1bfbeba7a5040442022c7e7c02e" "checksum serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)" = "2f72eb2a68a7dc3f9a691bfda9305a1c017a6215e5a4545c258500d2099a37c2" "checksum serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "642dd69105886af2efd227f75a520ec9b44a820d65bc133a9131f7d229fd165a" @@ -1846,7 +1852,7 @@ dependencies = [ "checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119" "checksum tokio-threadpool 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "2bd2c6a3885302581f4401c82af70d792bb9df1700e7437b0aeb4ada94d5388c" "checksum tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f2106812d500ed25a4f38235b9cae8f78a09edf43203e16e59c3b769a342a60e" -"checksum toml 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c7aabe75941d914b72bf3e5d3932ed92ce0664d49d8432305a8b547c37227724" +"checksum toml 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c04dffffeac90885436d23c692517bb5b8b3f8863e4afc15023628d067d667b7" "checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" "checksum try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "283d3b89e1368717881a9d51dad843cc435380d8109c9e47d38780a324698d8b" "checksum unicase 2.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2e2e6bd1e59e56598518beb94fd6db628ded570326f0a98c679a304bd9f00150" diff --git a/Cargo.toml b/Cargo.toml index e2595d8..e60ef3c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,18 +1,18 @@ [package] name = "library-loader" -version = "0.1.1" -authors = ["Edwin Svensson "] +version = "0.1.2" +authors = ["Edwin Svensson "] edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] reqwest = "0.9.22" -base64 = "0.10.1" +base64 = "0.11.0" clap = { version = "2.33.0", features = ["yaml"] } -serde = "1.0.101" +serde = "1.0.102" dirs = "2.0.2" -toml = "0.5.3" +toml = "0.5.4" rpassword = "4.0.1" zip = "0.5.3" crossbeam-channel = "0.3.9" diff --git a/TODO.md b/TODO.md index e2f123b..f211040 100644 --- a/TODO.md +++ b/TODO.md @@ -9,7 +9,7 @@ * [x] [Feature] Auto unzip folder and copy lib to libs folder * [x] [Code] New struct for CLI-only options * [x] [Feature] When using `-g`, treat input as output path -* [ ] [Code] Split extractor from format +* [x] [Code] Split extractor from format * [ ] [Docs] Proper documentation * [ ] [Code] Document the code... * [ ] [Feature] Show Desktop Notification? diff --git a/src/check_updates.rs b/src/check_updates.rs new file mode 100644 index 0000000..0f48d00 --- /dev/null +++ b/src/check_updates.rs @@ -0,0 +1,44 @@ +use reqwest; +use toml; +use serde::Deserialize; +use super::error::LLResult; +use super::consts::REMOTE_CARGO_TOML; + +pub struct UpdateInfo { + pub local: String, + pub remote: String +} + +#[derive(Deserialize)] +struct CargoToml { + package: Package +} + +#[derive(Deserialize)] +struct Package { + version: String +} + +pub fn check() -> LLResult> { + + let remote_toml_str = reqwest::get(REMOTE_CARGO_TOML)?.text()?; + let local_toml_str = std::include_str!("../Cargo.toml"); + + + let remote_toml: CargoToml = toml::from_str(remote_toml_str.as_str())?; + let local_toml: CargoToml = toml::from_str(local_toml_str)?; + + if remote_toml.package.version != local_toml.package.version { + + Ok(Some(UpdateInfo { + local: local_toml.package.version, + remote: remote_toml.package.version + })) + + } else { + + Ok(None) + + } + +} diff --git a/src/config.rs b/src/config.rs index 7ccdb85..af6d039 100644 --- a/src/config.rs +++ b/src/config.rs @@ -241,7 +241,7 @@ impl Default for Config { settings: Settings { output_path: String::from("download"), watch_path: None, - format: Format::ZIP + format: Format::from("zip") }, profile: profile, cli: Cli { diff --git a/src/consts.rs b/src/consts.rs index ce4b048..c01baa1 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -3,3 +3,7 @@ pub const COMPONENT_SEARCH_ENGINE_URL: &str = "http://componentsearchengine.com/ // Main config file to look for in working dir pub const LL_CONFIG: &str = "LibraryLoader.toml"; + +// Github urls +pub const DOWNLOAD_URL: &str = "https://github.com/olback/library-loader/releases/latest"; +pub const REMOTE_CARGO_TOML: &str = "https://raw.githubusercontent.com/olback/library-loader/master/Cargo.toml"; diff --git a/src/cse.rs b/src/cse.rs index e310ba6..7ef3922 100644 --- a/src/cse.rs +++ b/src/cse.rs @@ -1,5 +1,5 @@ use super::config::Config; -use super::format::{self, Extractor, Format, Files}; +use super::format::{Files, ECAD}; use super::epw::Epw; use super::error::{LLResult, LLError}; use super::cse_result::CSEResult; @@ -79,7 +79,7 @@ impl CSE { println!("-- End debug info from {file}#{line} --", file = std::file!(), line = std::line!()); } - if &self.config.settings.format == &Format::ZIP { + if &self.config.settings.format.ecad == &ECAD::ZIP { let mut files: Files = HashMap::new(); files.insert(filename, body); @@ -113,17 +113,14 @@ impl CSE { let mut item = archive.by_index(i)?; let filename = String::from(item.name()); - match &self.config.settings.format { - Format::EAGLE => format::eagle::Extractor::extract(&mut files, filename, &mut item)?, - Format::EASYEDA => format::easyeda::Extractor::extract(&mut files, filename, &mut item)?, - Format::KICAD => format::kicad::Extractor::extract(&mut files, filename, &mut item)?, - Format::ZIP => return Err(LLError::new("This should be unreachable!")) - // ! NOTE: DO NOT ADD A _ => {} CATCHER HERE! - }; + &self.config.settings.format.extract(&mut files, filename, &mut item)?; } - let path = PathBuf::from(&self.config.settings.output_path).join(lib_name); + let path = match &self.config.settings.format.create_folder { + true => PathBuf::from(&self.config.settings.output_path).join(lib_name), + false => PathBuf::from(&self.config.settings.output_path) + }; Ok(CSEResult { output_path: path.to_string_lossy().to_string(), diff --git a/src/cse_result.rs b/src/cse_result.rs index ff2c09e..7a59696 100644 --- a/src/cse_result.rs +++ b/src/cse_result.rs @@ -46,8 +46,14 @@ impl CSEResult { fn write(path: PathBuf, data: Vec) -> LLResult { + let p = path.to_str().unwrap().to_string(); + + if path.exists() { + return Err(LLError::new(format!("{}#{}: {} already exists!", std::file!(), std::line!(), p))); + } + match fs::write(&path, &data) { - Ok(_) => Ok(path.to_str().unwrap().to_string()), + Ok(_) => Ok(p), Err(e) => Err(LLError::new(format!("{}#{}: {}", std::file!(), std::line!(), e))) } diff --git a/src/format/eagle.rs b/src/format/eagle.rs deleted file mode 100644 index 70b4da6..0000000 --- a/src/format/eagle.rs +++ /dev/null @@ -1,14 +0,0 @@ -use super::extractor_prelude::*; - -pub struct Extractor; - -impl ExtractorTrait for Extractor { - - fn extract>(files: &mut Files, file_path: S, item: &mut ZipFile) -> LLResult<()> { - - generic_extractor("eagle", files, file_path, item) - - } - -} - diff --git a/src/format/easyeda.rs b/src/format/easyeda.rs deleted file mode 100644 index d5b2480..0000000 --- a/src/format/easyeda.rs +++ /dev/null @@ -1,13 +0,0 @@ -use super::extractor_prelude::*; - -pub struct Extractor; - -impl ExtractorTrait for Extractor { - - fn extract>(files: &mut Files, file_path: S, item: &mut ZipFile) -> LLResult<()> { - - generic_extractor("easyeda", files, file_path, item) - - } - -} diff --git a/src/format/extractor_prelude.rs b/src/format/extractor_prelude.rs deleted file mode 100644 index e485930..0000000 --- a/src/format/extractor_prelude.rs +++ /dev/null @@ -1,27 +0,0 @@ -use std::collections::HashMap; - -pub(super) use zip::read::ZipFile; -pub(super) use super::super::error::LLResult; -pub(super) use std::{io::Read, path::PathBuf}; - -pub type Files = HashMap::>; - -pub trait ExtractorTrait { - fn extract>(files: &mut Files, file_path: S, item: &mut ZipFile) -> LLResult<()>; -} - -pub(super) fn generic_extractor>(match_path: &str, files: &mut Files, file_path: S, item: &mut ZipFile) -> LLResult<()> { - - let fp = file_path.into(); - - if fp.to_lowercase().contains(match_path) { - let path = PathBuf::from(fp); - let base_name = path.file_name().unwrap().to_string_lossy().to_string(); - let mut f_data = Vec::::new(); - item.read_to_end(&mut f_data)?; - files.insert(base_name, f_data); - } - - Ok(()) - -} diff --git a/src/format/extractors/eagle.rs b/src/format/extractors/eagle.rs new file mode 100644 index 0000000..c9a2d3f --- /dev/null +++ b/src/format/extractors/eagle.rs @@ -0,0 +1,9 @@ +use super::*; + +pub fn extract(format: &Format, files: &mut Files, file_path: String, item: &mut ZipFile) -> LLResult<()> { + + + generic_extractor(format, files, file_path, item) + +} + diff --git a/src/format/extractors/easyeda.rs b/src/format/extractors/easyeda.rs new file mode 100644 index 0000000..fdd2489 --- /dev/null +++ b/src/format/extractors/easyeda.rs @@ -0,0 +1,7 @@ +use super::*; + +pub fn extract(format: &Format, files: &mut Files, file_path: String, item: &mut ZipFile) -> LLResult<()> { + + generic_extractor(format, files, file_path, item) + +} diff --git a/src/format/extractors/kicad.rs b/src/format/extractors/kicad.rs new file mode 100644 index 0000000..fdd2489 --- /dev/null +++ b/src/format/extractors/kicad.rs @@ -0,0 +1,7 @@ +use super::*; + +pub fn extract(format: &Format, files: &mut Files, file_path: String, item: &mut ZipFile) -> LLResult<()> { + + generic_extractor(format, files, file_path, item) + +} diff --git a/src/format/extractors/mod.rs b/src/format/extractors/mod.rs new file mode 100644 index 0000000..97c8257 --- /dev/null +++ b/src/format/extractors/mod.rs @@ -0,0 +1,42 @@ +// * Keep these in alphabetical order +pub mod eagle; +pub mod easyeda; +pub mod kicad; + +use std::collections::HashMap; + +pub(super) use zip::read::ZipFile; +pub(super) use super::super::error::LLResult; +pub(super) use std::{io::Read, path::PathBuf}; +pub(super) use super::Format; + +pub type Files = HashMap::>; + +pub(super) fn generic_extractor(format: &Format, files: &mut Files, file_path: String, item: &mut ZipFile) -> LLResult<()> { + + let file_path_lower = file_path.to_lowercase(); + + // Ignore files + for ignore in &format.ignore { + + if file_path_lower.contains(ignore.to_lowercase().as_str()) { + + return Ok(()) + + } + + } + + if file_path_lower.contains(&format.match_path.to_lowercase()) { + + let path = PathBuf::from(file_path); + let base_name = path.file_name().unwrap().to_string_lossy().to_string(); + let mut f_data = Vec::::new(); + item.read_to_end(&mut f_data)?; + files.insert(base_name, f_data); + + } + + Ok(()) + +} diff --git a/src/format/kicad.rs b/src/format/kicad.rs deleted file mode 100644 index 0978f42..0000000 --- a/src/format/kicad.rs +++ /dev/null @@ -1,13 +0,0 @@ -use super::extractor_prelude::*; - -pub struct Extractor; - -impl ExtractorTrait for Extractor { - - fn extract>(files: &mut Files, file_path: S, item: &mut ZipFile) -> LLResult<()> { - - generic_extractor("kicad", files, file_path, item) - - } - -} diff --git a/src/format/mod.rs b/src/format/mod.rs index 51f2c44..1206b72 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -1,38 +1,79 @@ -pub mod eagle; -pub mod easyeda; -pub mod kicad; +mod extractors; +use zip::read::ZipFile; +use super::error::LLResult; -pub(super) mod extractor_prelude; -pub use extractor_prelude::{ - ExtractorTrait as Extractor, - Files -}; +pub use extractors::Files; #[derive(Debug, Clone, PartialEq)] -pub enum Format { +pub enum ECAD { + // * Keep these in alphabetical order EAGLE, EASYEDA, KICAD, ZIP } +#[derive(Debug, Clone, PartialEq)] +pub struct Format { + pub ecad: ECAD, + pub create_folder: bool, + match_path: &'static str, + ignore: Vec<&'static str> +} + impl Format { pub fn from>(format: S) -> Self { let f = format.into().to_lowercase(); + // * Keep these in alphabetical order match f.as_str() { - "eagle" => Self::EAGLE, - "easyeda" => Self::EASYEDA, - "kicad" => Self::KICAD, - "zip" => Self::ZIP, + "eagle" => Self { + ecad: ECAD::EAGLE, + create_folder: false, + match_path: "EAGLE", + ignore: vec!["Readme.html"] + }, + "easyeda" => Self { + ecad: ECAD::EASYEDA, + create_folder: false, + match_path: "EasyEDA", + ignore: vec!["Readme.html"] + }, + "kicad" => Self { + ecad: ECAD::KICAD, + create_folder: true, + match_path: "KiCad", + ignore: vec![] + }, + "zip" => Self { + ecad: ECAD::ZIP, + create_folder: false, + match_path: "", + ignore: vec![] + }, _ => { - eprintln!("Unknown format. Defaulting to ZIP!"); - Self::ZIP + eprintln!("{}#{}: Unknown format. Defaulting to ZIP!", std::file!(), std::line!()); + Self::from("zip") } } } + pub fn extract(&self, files: &mut Files, file_path: String, item: &mut ZipFile) -> LLResult<()> { + + + match &self.ecad { + // * Keep these in alphabetical order + ECAD::EAGLE => extractors::eagle::extract(&self, files, file_path, item)?, + ECAD::EASYEDA => extractors::easyeda::extract(&self, files, file_path, item)?, + ECAD::KICAD => extractors::kicad::extract(&self, files, file_path, item)?, + ECAD::ZIP => panic!("This should be unreachable!") + // ! NOTE: DO NOT ADD A _ => {} CATCHER HERE! + }; + + Ok(()) + } + } diff --git a/src/main.rs b/src/main.rs index 43072a0..f104c27 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ mod config; mod format; mod consts; mod watcher; +mod check_updates; use config::Config; use epw::Epw; @@ -21,6 +22,24 @@ use std::io::Read; fn main() { + // Check for updates + let update_handle = std::thread::spawn(move || { + match check_updates::check() { + Ok(available) => { + match available { + Some(update) => { + println!("New update available! {} -> {}", update.local, update.remote); + println!("{}", consts::DOWNLOAD_URL); + }, + None => {} + } + }, + Err(e) => { + eprintln!("{}#{}: Error checking for updates: {}", std::file!(), std::line!(), e); + } + } + }); + match real_main() { Ok(v) => v, Err(e) => { @@ -29,6 +48,8 @@ fn main() { } } + update_handle.join().unwrap(); + } fn real_main() -> LLResult<()> { @@ -56,12 +77,11 @@ fn real_main() -> LLResult<()> { let tx = w.get_tx(); // React on key input - std::thread::spawn(move || { - #[allow(unused_must_use)] - { - std::io::stdin().read(&mut [0u8]).unwrap(); - tx.send(Err(notify::Error::generic("stop"))); - } + let input_handle = std::thread::spawn(move || { + + std::io::stdin().read(&mut [0u8]).unwrap(); + tx.send(Err(notify::Error::generic("stop"))).unwrap(); + }); let watch_path_buf = std::path::PathBuf::from(&conf.settings.watch_path.unwrap()); @@ -69,10 +89,11 @@ fn real_main() -> LLResult<()> { println!("Watching {}", watch_path_buf.as_path().canonicalize()?.to_string_lossy()); println!("Saving to: {}", save_to_buf.as_path().canonicalize()?.to_string_lossy()); - println!("Saving in format: {:?}", &conf.settings.format); + println!("Saving in format: {:?}", &conf.settings.format.ecad); println!("Press to exit"); w.start()?; + input_handle.join().unwrap(); } else if conf.cli.input.is_empty() {