From ee2d714b674db3e1b64c75f0f7bb5d149312884d Mon Sep 17 00:00:00 2001 From: Tensor-Programming Date: Sun, 12 Jan 2020 20:27:35 -0500 Subject: [PATCH] Feat(CLI) Icon Check fix: #309 (#310) * add icon check for windows. * fix spelling * add basic icon logic * make error more prolific --- cli/tauri-cli/src/bundle.rs | 13 +++++++++++++ cli/tauri-cli/src/main.rs | 12 +++++++++--- cli/tauri.js/templates/src-tauri/src/build.rs | 11 +++++++---- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/cli/tauri-cli/src/bundle.rs b/cli/tauri-cli/src/bundle.rs index 2452cf9ce..f3ec36f2b 100644 --- a/cli/tauri-cli/src/bundle.rs +++ b/cli/tauri-cli/src/bundle.rs @@ -43,3 +43,16 @@ pub fn bundle_project(settings: Settings) -> crate::Result> { } Ok(paths) } + +// Check to see if there are icons in the settings struct +pub fn check_icons(settings: &Settings) -> crate::Result { + // make a peekable iterator of the icon_files + let mut iter = settings.icon_files().peekable(); + + // if iter's first value is a None then there are no Icon files in the settings struct + if iter.peek().is_none() { + Ok(false) + } else { + Ok(true) + } +} diff --git a/cli/tauri-cli/src/main.rs b/cli/tauri-cli/src/main.rs index b70f84b65..7313ab082 100644 --- a/cli/tauri-cli/src/main.rs +++ b/cli/tauri-cli/src/main.rs @@ -12,7 +12,7 @@ extern crate tempfile; mod bundle; -use crate::bundle::{bundle_project, BuildArtifact, PackageType, Settings}; +use crate::bundle::{bundle_project, check_icons, BuildArtifact, PackageType, Settings}; use clap::{App, AppSettings, Arg, SubCommand}; use std::env; use std::process; @@ -141,8 +141,14 @@ fn run() -> crate::Result<()> { .map_err(From::from) .and_then(|d| Settings::new(d, m)) .and_then(|s| { - build_project_if_unbuilt(&s)?; - Ok(s) + if check_icons(&s)? { + build_project_if_unbuilt(&s)?; + Ok(s) + } else { + Err(crate::Error::from( + "Could not find Icon Paths. Please make sure they exist and are in your Cargo.toml's icon key.", + )) + } }) .and_then(bundle_project)?; bundle::print_finished(&output_paths)?; diff --git a/cli/tauri.js/templates/src-tauri/src/build.rs b/cli/tauri.js/templates/src-tauri/src/build.rs index fcd568038..5bd8f5cb7 100644 --- a/cli/tauri.js/templates/src-tauri/src/build.rs +++ b/cli/tauri.js/templates/src-tauri/src/build.rs @@ -3,10 +3,13 @@ extern crate winres; #[cfg(windows)] fn main() { - let mut res = winres::WindowsResource::new(); - res.set_icon("icons/icon.ico"); - res.compile().expect("Unable to find visual studio tools"); -} + if std::path::Path::new("icons/icon.ico").exists() { + let mut res = winres::WindowsResource::new(); + res.set_icon("icons/icon.ico"); + res.compile().expect("Unable to find visual studio tools"); + } else { + panic!("No Icon.ico found. Please add one or check the path"); + } #[cfg(not(windows))] fn main() {}