Эх сурвалжийг харах

[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
Tensor-Programming 5 жил өмнө
parent
commit
078ae1dfda

+ 1 - 0
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]

+ 38 - 6
cli/tauri-cli/src/bundle/templates/main.wxs

@@ -21,17 +21,21 @@
 
         <Package Id="*"
                  Keywords="Installer"
-                 InstallerVersion="200"
+                 InstallerVersion="450"
                  Languages="1033"
                  Compressed="yes"
                  InstallScope="perMachine"
                  SummaryCodepage="1252"/>
 
         <Media Id="1" Cabinet="app.cab" EmbedCab="yes" />
+        
+        <WixVariable Id="WixUIBannerBmp" Value="{{{icon_path}}}" />
+        
         <Icon Id="ProductIcon" SourceFile="{{{icon_path}}}"/>
-        <Property Id="ARPPRODUCTICON" Value="ProductIcon"/>
-        <Property Id="ARPNOREPAIR" Value="1"/>
-        <Property Id="ARPNOMODIFY" Value="1"/>
+        <Property Id="ARPPRODUCTICON" Value="ProductIcon" />
+        <Property Id="ARPNOREPAIR" Value="yes" Secure="yes" />      <!-- Remove repair -->
+        <Property Id="ARPNOMODIFY" Value="yes" Secure="yes" />      <!-- Remove modify -->
+
 
         <Directory Id="TARGETDIR" Name="SourceDir">
             <Directory Id="$(var.PlatformProgramFilesFolder)" Name="PFiles">
@@ -43,16 +47,45 @@
             </Directory>
         </Directory>
 
+        <DirectoryRef Id="APPLICATIONFOLDER">
+            <Component Id="CMP_ReadFileShortcut"
+                Guid="1AF06B42-CD42-4AED-959F-36DB5E512046">
+
+                <Shortcut Id="UninstallShortcut"
+						  Name="Uninstall {{{product_name}}}"
+						  Description="Uninstalls {{{product_name}}}"
+						  Target="[System64Folder]msiexec.exe"
+						  Arguments="/x [ProductCode]" />
+
+				<RemoveFolder Id="RemoveDIR_Shortcuts"
+							  On="uninstall" />
+
+				<RegistryValue Root="HKCU"
+							   Key="Software\{{{manufacturer}}}\{{{product_name}}}"
+							   Name="installed"
+							   Type="integer"
+							   Value="1"
+							   KeyPath="yes" />
+            
+            </Component>
+        </DirectoryRef>
+
         <Feature
                 Id="MainProgram"
                 Title="Application"
-                Description="Installs the executable."
+                Description="Installs {{{product_name}}}."
                 Level="1"
                 ConfigurableDirectory="APPLICATIONFOLDER"
                 AllowAdvertise="no"
                 Display="expand"
                 Absent="disallow">
 
+            <Feature Id="ShortcutsFeature"
+			 Title="Shortcuts"
+			 Level="1">
+			<ComponentRef Id="CMP_ReadFileShortcut" />
+		    </Feature>
+
             <Feature
                     Id="Environment"
                     Title="PATH Environment Variable"
@@ -64,6 +97,5 @@
         </Feature>
 
         <SetProperty Id="ARPINSTALLLOCATION" Value="[APPLICATIONFOLDER]" After="CostFinalize"/>
-
     </Product>
 </Wix>

+ 41 - 4
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<PathBuf> {
+  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<Vec<u8>> {
   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)?;
+
+  let path = image_path.join("icon.ico").display().to_string();
 
-  data.insert("icon_path", &image_path);
+  data.insert("icon_path", path.as_str());
 
   let temp = HANDLEBARS
     .render("main.wxs", &data)

+ 1 - 1
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);
 
     }

+ 6 - 4
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" ]

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