Forráskód Böngészése

fix: add missing file properties on Windows, closes #6676 (#6693)

Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.studio>
Amr Bashir 2 éve
szülő
commit
af93729031

+ 5 - 0
.changes/tauri-build-shortdesc-copyright.md

@@ -0,0 +1,5 @@
+---
+'tauri-build': 'patch'
+---
+
+On Windows, set `LegalCopyright` and `FileDescription` file properties on the executable from `tauri.bundle.copyright` and `tauri.bundle.shortDescription`,

+ 10 - 5
core/tauri-build/src/lib.rs

@@ -419,18 +419,23 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
           ));
         }
       }
-      if let Some(version) = &config.package.version {
-        if let Ok(v) = Version::parse(version) {
+      if let Some(version_str) = &config.package.version {
+        if let Ok(v) = Version::parse(version_str) {
           let version = v.major << 48 | v.minor << 32 | v.patch << 16;
           res.set_version_info(VersionInfo::FILEVERSION, version);
           res.set_version_info(VersionInfo::PRODUCTVERSION, version);
         }
-        res.set("FileVersion", version);
-        res.set("ProductVersion", version);
+        res.set("FileVersion", version_str);
+        res.set("ProductVersion", version_str);
       }
       if let Some(product_name) = &config.package.product_name {
         res.set("ProductName", product_name);
-        res.set("FileDescription", product_name);
+      }
+      if let Some(short_description) = &config.tauri.bundle.short_description {
+        res.set("FileDescription", short_description);
+      }
+      if let Some(copyright) = &config.tauri.bundle.copyright {
+        res.set("LegalCopyright", copyright);
       }
       res.set_icon_with_id(&window_icon_path.display().to_string(), "32512");
       res.compile().with_context(|| {

+ 27 - 1
tooling/bundler/src/bundle/windows/nsis.rs

@@ -121,6 +121,25 @@ fn get_and_extract_nsis(nsis_toolset_path: &Path, _tauri_tools_path: &Path) -> c
   Ok(())
 }
 
+fn add_build_number_if_needed(version_str: &str) -> anyhow::Result<String> {
+  let version = semver::Version::parse(version_str).context("invalid app version")?;
+  if !version.build.is_empty() {
+    let build = version.build.parse::<u64>();
+    if build.is_ok() {
+      return Ok(format!(
+        "{}.{}.{}.{}",
+        version.major, version.minor, version.patch, version.build
+      ));
+    } else {
+      anyhow::bail!("optional build metadata in app version must be numeric-only");
+    }
+  }
+
+  Ok(format!(
+    "{}.{}.{}.0",
+    version.major, version.minor, version.patch,
+  ))
+}
 fn build_nsis_app_installer(
   settings: &Settings,
   _nsis_toolset_path: &Path,
@@ -164,7 +183,9 @@ fn build_nsis_app_installer(
   let mut data = BTreeMap::new();
 
   let bundle_id = settings.bundle_identifier();
-  let manufacturer = bundle_id.split('.').nth(1).unwrap_or(bundle_id);
+  let manufacturer = settings
+    .publisher()
+    .unwrap_or_else(|| bundle_id.split('.').nth(1).unwrap_or(bundle_id));
 
   #[cfg(not(target_os = "windows"))]
   {
@@ -177,10 +198,15 @@ fn build_nsis_app_installer(
   data.insert("bundle_id", to_json(bundle_id));
   data.insert("manufacturer", to_json(manufacturer));
   data.insert("product_name", to_json(settings.product_name()));
+  data.insert("short_description", to_json(settings.short_description()));
   data.insert("copyright", to_json(settings.copyright_string()));
 
   let version = settings.version_string();
   data.insert("version", to_json(version));
+  data.insert(
+    "version_with_build",
+    to_json(add_build_number_if_needed(version)?),
+  );
 
   data.insert(
     "allow_downgrades",

+ 9 - 0
tooling/bundler/src/bundle/windows/templates/installer.nsi

@@ -9,6 +9,8 @@ Var ReinstallPageCheck
 !define MANUFACTURER "{{manufacturer}}"
 !define PRODUCTNAME "{{product_name}}"
 !define VERSION "{{version}}"
+!define VERSIONWITHBUILD "{{version_with_build}}"
+!define SHORTDESCRIPTION "{{short_description}}"
 !define INSTALLMODE "{{install_mode}}"
 !define LICENSE "{{license}}"
 !define INSTALLERICON "{{installer_icon}}"
@@ -35,6 +37,13 @@ OutFile "${OUTFILE}"
 Unicode true
 SetCompressor /SOLID lzma
 
+VIProductVersion "${VERSIONWITHBUILD}"
+VIAddVersionKey "ProductName" "${PRODUCTNAME}"
+VIAddVersionKey "FileDescription" "${SHORTDESCRIPTION}"
+VIAddVersionKey "LegalCopyright" "${COPYRIGHT}"
+VIAddVersionKey "FileVersion" "${VERSION}"
+VIAddVersionKey "ProductVersion" "${VERSION}"
+
 !if "${PLUGINSPATH}" != ""
     !addplugindir "${PLUGINSPATH}"
 !endif