瀏覽代碼

feat: add `bundle > homepage` option (#9977)

* feat: add `bundle > homepage` option

If unspecified, it will fallback to `homepage` define in Cargo.toml

closes #9949

* Update settings.rs
Amr Bashir 1 年之前
父節點
當前提交
fafc238f72

+ 7 - 0
.changes/bundler-homepage-url.md

@@ -0,0 +1,7 @@
+---
+"tauri-utils": "minor:feat"
+"tauri-bundler": "minor:feat"
+---
+
+Add `bundle > homepage` option, if unset, it will fallback to `homepage` defined in `Cargo.toml`.
+

+ 7 - 0
core/tauri-config-schema/schema.json

@@ -1532,6 +1532,13 @@
             "null"
           ]
         },
+        "homepage": {
+          "description": "A url to the home page of your application. If unset, will fallback to `homepage` defined in `Cargo.toml`.\n\nSupported bundle targets: `deb`, `rpm`, `nsis` and `msi`.",
+          "type": [
+            "string",
+            "null"
+          ]
+        },
         "icon": {
           "description": "The app's icons",
           "default": [],

+ 8 - 0
core/tauri-utils/src/config.rs

@@ -1054,6 +1054,11 @@ pub struct BundleConfig {
   /// The application's publisher. Defaults to the second element in the identifier string.
   /// Currently maps to the Manufacturer property of the Windows Installer.
   pub publisher: Option<String>,
+  /// A url to the home page of your application. If unset, will
+  /// fallback to `homepage` defined in `Cargo.toml`.
+  ///
+  /// Supported bundle targets: `deb`, `rpm`, `nsis` and `msi`.
+  pub homepage: Option<String>,
   /// The app's icons
   #[serde(default)]
   pub icon: Vec<String>,
@@ -2416,6 +2421,7 @@ mod build {
   impl ToTokens for BundleConfig {
     fn to_tokens(&self, tokens: &mut TokenStream) {
       let publisher = quote!(None);
+      let homepage = quote!(None);
       let icon = vec_lit(&self.icon, str_lit);
       let active = self.active;
       let targets = quote!(Default::default());
@@ -2439,6 +2445,7 @@ mod build {
         ::tauri::utils::config::BundleConfig,
         active,
         publisher,
+        homepage,
         icon,
         targets,
         resources,
@@ -2756,6 +2763,7 @@ mod test {
       active: false,
       targets: Default::default(),
       publisher: None,
+      homepage: None,
       icon: Vec::new(),
       resources: None,
       copyright: None,

+ 3 - 2
tooling/bundler/src/bundle/linux/debian.rs

@@ -175,9 +175,10 @@ fn generate_control_file(
     writeln!(file, "Priority: optional")?;
   }
 
-  if !settings.homepage_url().is_empty() {
-    writeln!(file, "Homepage: {}", settings.homepage_url())?;
+  if let Some(homepage) = settings.homepage_url() {
+    writeln!(file, "Homepage: {}", homepage)?;
   }
+
   let dependencies = settings.deb().depends.as_ref().cloned().unwrap_or_default();
   if !dependencies.is_empty() {
     writeln!(file, "Depends: {}", dependencies.join(", "))?;

+ 5 - 1
tooling/bundler/src/bundle/linux/rpm.rs

@@ -52,7 +52,11 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
     .compression(rpm::CompressionWithLevel::Gzip(6));
 
   if let Some(description) = settings.long_description() {
-    builder = builder.description(description.trim())
+    builder = builder.description(description);
+  }
+
+  if let Some(homepage) = settings.homepage_url() {
+    builder = builder.url(homepage);
   }
 
   // Add requirements

+ 12 - 3
tooling/bundler/src/bundle/settings.rs

@@ -523,6 +523,11 @@ pub struct BundleSettings {
   /// The app's publisher. Defaults to the second element in the identifier string.
   /// Currently maps to the Manufacturer property of the Windows Installer.
   pub publisher: Option<String>,
+  /// A url to the home page of your application. If None, will
+  /// fallback to [PackageSettings::homepage].
+  ///
+  /// Supported bundle targets: `deb`, `rpm`, `nsis` and `msi`
+  pub homepage: Option<String>,
   /// the app's icon list.
   pub icon: Option<Vec<String>>,
   /// the app's resources to bundle.
@@ -893,7 +898,7 @@ impl Settings {
     self.bundle_settings.identifier.as_deref().unwrap_or("")
   }
 
-  /// Returns the bundle's identifier
+  /// Returns the bundle's publisher
   pub fn publisher(&self) -> Option<&str> {
     self.bundle_settings.publisher.as_deref()
   }
@@ -999,8 +1004,12 @@ impl Settings {
   }
 
   /// Returns the package's homepage URL, defaulting to "" if not defined.
-  pub fn homepage_url(&self) -> &str {
-    self.package.homepage.as_deref().unwrap_or("")
+  pub fn homepage_url(&self) -> Option<&str> {
+    self
+      .bundle_settings
+      .homepage
+      .as_deref()
+      .or(self.package.homepage.as_deref())
   }
 
   /// Returns the app's category.

+ 1 - 0
tooling/bundler/src/bundle/windows/msi/wix.rs

@@ -518,6 +518,7 @@ pub fn build_wix_app_installer(
     "long_description",
     to_json(settings.long_description().unwrap_or_default()),
   );
+  data.insert("homepage", to_json(settings.homepage_url()));
   let bundle_id = settings.bundle_identifier();
   let manufacturer = settings
     .publisher()

+ 4 - 0
tooling/bundler/src/bundle/windows/nsis.rs

@@ -186,6 +186,10 @@ fn build_nsis_app_installer(
   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(
+    "homepage",
+    to_json(settings.homepage_url().unwrap_or_default()),
+  );
   data.insert(
     "long_description",
     to_json(settings.long_description().unwrap_or_default()),

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

@@ -28,6 +28,7 @@ ${StrLoc}
 !define VERSION "{{version}}"
 !define VERSIONWITHBUILD "{{version_with_build}}"
 !define SHORTDESCRIPTION "{{short_description}}"
+!define HOMEPAGE "{{homepage}}"
 !define INSTALLMODE "{{install_mode}}"
 !define LICENSE "{{license}}"
 !define INSTALLERICON "{{installer_icon}}"
@@ -579,6 +580,11 @@ Section Install
   WriteRegDWORD SHCTX "${UNINSTKEY}" "NoModify" "1"
   WriteRegDWORD SHCTX "${UNINSTKEY}" "NoRepair" "1"
   WriteRegDWORD SHCTX "${UNINSTKEY}" "EstimatedSize" "${ESTIMATEDSIZE}"
+  !if "${HOMEPAGE}" != ""
+    WriteRegStr SHCTX "${UNINSTKEY}" "URLInfoAbout" "${HOMEPAGE}"
+    WriteRegStr SHCTX "${UNINSTKEY}" "URLUpdateInfo" "${HOMEPAGE}"
+    WriteRegStr SHCTX "${UNINSTKEY}" "HelpLink" "${HOMEPAGE}"
+  !endif
 
   ; Create start menu shortcut
   !insertmacro MUI_STARTMENU_WRITE_BEGIN Application

+ 6 - 0
tooling/bundler/src/bundle/windows/templates/main.wxs

@@ -56,6 +56,12 @@
         <Property Id="ARPNOREPAIR" Value="yes" Secure="yes" />      <!-- Remove repair -->
         <SetProperty Id="ARPNOMODIFY" Value="1" After="InstallValidate" Sequence="execute"/>
 
+        {{#if homepage}}
+        <Property Id="ARPURLINFOABOUT" Value="{{homepage}}"/>
+        <Property Id="ARPHELPLINK" Value="{{homepage}}"/>
+        <Property Id="ARPURLUPDATEINFO" Value="{{homepage}}"/>
+        {{/if}}
+
         <!-- initialize with previous InstallDir -->
         <Property Id="INSTALLDIR">
             <RegistrySearch Id="PrevInstallDirReg" Root="HKCU" Key="Software\\{{manufacturer}}\\{{product_name}}" Name="InstallDir" Type="raw"/>

+ 7 - 0
tooling/cli/schema.json

@@ -1532,6 +1532,13 @@
             "null"
           ]
         },
+        "homepage": {
+          "description": "A url to the home page of your application. If unset, will fallback to `homepage` defined in `Cargo.toml`.\n\nSupported bundle targets: `deb`, `rpm`, `nsis` and `msi`.",
+          "type": [
+            "string",
+            "null"
+          ]
+        },
         "icon": {
           "description": "The app's icons",
           "default": [],

+ 1 - 0
tooling/cli/src/interface/rust.rs

@@ -1277,6 +1277,7 @@ fn tauri_config_to_bundle_settings(
   Ok(BundleSettings {
     identifier: Some(identifier),
     publisher: config.publisher,
+    homepage: config.homepage,
     icon: Some(config.icon),
     resources,
     resources_map,