From 078ae1dfda9c7c70faa3619ebded0cc3111d440e Mon Sep 17 00:00:00 2001 From: Tensor-Programming Date: Tue, 24 Dec 2019 14:33:41 -0500 Subject: [PATCH] [Feature/Bug(#133)] add icon to windows Exe and MSI (#211) * add icon to msi * remove print * make attohttpc windows only * make attohttpc error windows only * copy icon files to resource folder in output. * add ico to template * remove print * remove duplicate * add uninstaller to wix * fix typos * fix program flow * add windows icon logic to template. * update serde, phf and change includedir to tauri * update next.js with new tauri setup * update monolith * remove unnessecary deps * remove updater.rs and deps * update react examples * update vue example * Revert "update vue example" This reverts commit a5d58f55b42ec7719ed200d03d9503ffebf8e212. * Revert "update react examples" This reverts commit cce215f97e397e14c6da2cbe866d2480f2d94f97. * Revert "remove updater.rs and deps" This reverts commit 8d422294f4337a8738b64044f59a01de5a1be061. * Revert "remove unnessecary deps" This reverts commit 30e023f3831530df827a932a2e1f48473d2bbc9b. * Revert "update monolith" This reverts commit fac097f51a5684d92c03750238dd567d0207e00b. * Revert "update next.js with new tauri setup" This reverts commit caf5f198eacbd1c9feba8d1c0f72ec65be9f8fa2. * revert smoke-test changes * revert smoke-test changes * fix conflicts * fix conflicts --- cli/tauri-cli/Cargo.toml | 1 + cli/tauri-cli/src/bundle/templates/main.wxs | 44 +++++++++++++++--- cli/tauri-cli/src/bundle/wix.rs | 45 +++++++++++++++++-- cli/tauri-cli/src/main.rs | 2 +- cli/tauri.js/templates/src-tauri/Cargo.toml | 10 +++-- cli/tauri.js/templates/src-tauri/src/build.rs | 12 +++++ 6 files changed, 99 insertions(+), 15 deletions(-) create mode 100644 cli/tauri.js/templates/src-tauri/src/build.rs diff --git a/cli/tauri-cli/Cargo.toml b/cli/tauri-cli/Cargo.toml index e7c1f059d..3a5b1edf6 100644 --- a/cli/tauri-cli/Cargo.toml +++ b/cli/tauri-cli/Cargo.toml @@ -33,6 +33,7 @@ toml = "0.5.5" uuid = { version = "0.8", features = ["v5"] } walkdir = "2" +[target.'cfg(target_os = "windows")'.dependencies] attohttpc = { version = "0.7.0" } [target.'cfg(not(target_os = "linux"))'.dependencies] diff --git a/cli/tauri-cli/src/bundle/templates/main.wxs b/cli/tauri-cli/src/bundle/templates/main.wxs index 352ede3b3..df0aa492e 100644 --- a/cli/tauri-cli/src/bundle/templates/main.wxs +++ b/cli/tauri-cli/src/bundle/templates/main.wxs @@ -21,17 +21,21 @@ + + + - - - + + + + @@ -43,16 +47,45 @@ + + + + + + + + + + + + + + + + - \ No newline at end of file diff --git a/cli/tauri-cli/src/bundle/wix.rs b/cli/tauri-cli/src/bundle/wix.rs index d647f68c5..f77700308 100644 --- a/cli/tauri-cli/src/bundle/wix.rs +++ b/cli/tauri-cli/src/bundle/wix.rs @@ -1,5 +1,7 @@ use super::common; +use super::path_utils::{copy, Options}; use super::settings::Settings; + use handlebars::Handlebars; use lazy_static::lazy_static; use sha2::Digest; @@ -44,11 +46,42 @@ lazy_static! { handlebars .register_template_string("main.wxs", include_str!("templates/main.wxs")) + .or_else(|e| Err(e.to_string())) .unwrap(); handlebars }; } +fn copy_icons(settings: &Settings) -> crate::Result { + let base_dir = settings.binary_path(); + let base_dir = base_dir.parent().expect("Failed to get dir"); + + let resource_dir = base_dir.join("resources"); + + let mut image_path = PathBuf::from(settings.project_out_directory()); + + // pop off till in tauri_src dir + image_path.pop(); + image_path.pop(); + + // get icon dir and icon file. + let image_path = image_path.join("icons"); + let opts = super::path_utils::Options::default(); + + copy( + image_path, + &resource_dir, + &Options { + copy_files: true, + overwrite: true, + ..opts + }, + ) + .or_else(|e| Err(e.to_string()))?; + + Ok(resource_dir) +} + // Function used to download Wix and VC_REDIST. Checks SHA256 to verify the download. fn download_and_verify(url: &str, hash: &str) -> crate::Result> { common::print_info(format!("Downloading {}", url).as_str())?; @@ -322,6 +355,9 @@ pub fn build_wix_app_installer( let path_guid = generate_package_guid(settings).to_string(); data.insert("path_component_guid", &path_guid.as_str()); + let shortcut_guid = generate_package_guid(settings).to_string(); + data.insert("shortcut_guid", &shortcut_guid.as_str()); + let app_exe_name = settings.binary_name().to_string(); data.insert("app_exe_name", &app_exe_name); @@ -329,11 +365,12 @@ pub fn build_wix_app_installer( data.insert("app_exe_source", &app_exe_source); - let image_path = PathBuf::from("../../../../icons/icon.ico") - .display() - .to_string(); + // copy icons from icons folder to resource folder near msi + let image_path = copy_icons(&settings)?; - data.insert("icon_path", &image_path); + let path = image_path.join("icon.ico").display().to_string(); + + data.insert("icon_path", path.as_str()); let temp = HANDLEBARS .render("main.wxs", &data) diff --git a/cli/tauri-cli/src/main.rs b/cli/tauri-cli/src/main.rs index e0c52576f..71f8586b3 100644 --- a/cli/tauri-cli/src/main.rs +++ b/cli/tauri-cli/src/main.rs @@ -27,7 +27,7 @@ error_chain! { Term(::term::Error); Toml(::toml::de::Error); Walkdir(::walkdir::Error); - HttpError(::attohttpc::Error); + HttpError(::attohttpc::Error) #[cfg(windows)]; StripError(std::path::StripPrefixError); } diff --git a/cli/tauri.js/templates/src-tauri/Cargo.toml b/cli/tauri.js/templates/src-tauri/Cargo.toml index 0f8fafe0f..67f4a2437 100755 --- a/cli/tauri.js/templates/src-tauri/Cargo.toml +++ b/cli/tauri.js/templates/src-tauri/Cargo.toml @@ -7,18 +7,20 @@ license = "" repository = "" default-run = "app" edition = "2018" +build = "src/build.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] serde_json = "1.0.41" -serde = "1.0" -serde_derive = "1.0" +serde = "1.0.104" +serde_derive = "1.0.104" tiny_http = "0.6" -phf = "0.7.24" -includedir = "0.5.0" tauri = <%= tauriDep || `{ version = "0.2.0" }` %> +[target."cfg(windows)".build-dependencies] +winres = "0.1" + [features] dev-server = [ "tauri/dev-server" ] embedded-server = [ "tauri/embedded-server" ] diff --git a/cli/tauri.js/templates/src-tauri/src/build.rs b/cli/tauri.js/templates/src-tauri/src/build.rs new file mode 100644 index 000000000..fcd568038 --- /dev/null +++ b/cli/tauri.js/templates/src-tauri/src/build.rs @@ -0,0 +1,12 @@ +#[cfg(windows)] +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"); +} + +#[cfg(not(windows))] +fn main() {}