Przeglądaj źródła

Feat(CLI) Icon Check fix: #309 (#310)

* add icon check for windows.

* fix spelling

* add basic icon logic

* make error more prolific
Tensor-Programming 5 lat temu
rodzic
commit
ee2d714b67

+ 13 - 0
cli/tauri-cli/src/bundle.rs

@@ -43,3 +43,16 @@ pub fn bundle_project(settings: Settings) -> crate::Result<Vec<PathBuf>> {
   }
   Ok(paths)
 }
+
+// Check to see if there are icons in the settings struct
+pub fn check_icons(settings: &Settings) -> crate::Result<bool> {
+  // 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)
+  }
+}

+ 9 - 3
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)?;

+ 7 - 4
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() {}