From fafc238f7288548975ca7d3e5207b925c0295c91 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Wed, 5 Jun 2024 19:01:48 +0300 Subject: [PATCH] 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 --- .changes/bundler-homepage-url.md | 7 +++++++ core/tauri-config-schema/schema.json | 7 +++++++ core/tauri-utils/src/config.rs | 8 ++++++++ tooling/bundler/src/bundle/linux/debian.rs | 5 +++-- tooling/bundler/src/bundle/linux/rpm.rs | 6 +++++- tooling/bundler/src/bundle/settings.rs | 15 ++++++++++++--- tooling/bundler/src/bundle/windows/msi/wix.rs | 1 + tooling/bundler/src/bundle/windows/nsis.rs | 4 ++++ .../src/bundle/windows/templates/installer.nsi | 6 ++++++ .../bundler/src/bundle/windows/templates/main.wxs | 6 ++++++ tooling/cli/schema.json | 7 +++++++ tooling/cli/src/interface/rust.rs | 1 + 12 files changed, 67 insertions(+), 6 deletions(-) create mode 100644 .changes/bundler-homepage-url.md diff --git a/.changes/bundler-homepage-url.md b/.changes/bundler-homepage-url.md new file mode 100644 index 00000000000..5ef84d66eb6 --- /dev/null +++ b/.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`. + diff --git a/core/tauri-config-schema/schema.json b/core/tauri-config-schema/schema.json index 9092a329f62..649b051a6ed 100644 --- a/core/tauri-config-schema/schema.json +++ b/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": [], diff --git a/core/tauri-utils/src/config.rs b/core/tauri-utils/src/config.rs index e7a69b23e0a..4b2d7be9935 100644 --- a/core/tauri-utils/src/config.rs +++ b/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, + /// 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, /// The app's icons #[serde(default)] pub icon: Vec, @@ -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, diff --git a/tooling/bundler/src/bundle/linux/debian.rs b/tooling/bundler/src/bundle/linux/debian.rs index 250ad3b237c..95e9eb30c93 100644 --- a/tooling/bundler/src/bundle/linux/debian.rs +++ b/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(", "))?; diff --git a/tooling/bundler/src/bundle/linux/rpm.rs b/tooling/bundler/src/bundle/linux/rpm.rs index ee3383ae766..ad899901b8d 100644 --- a/tooling/bundler/src/bundle/linux/rpm.rs +++ b/tooling/bundler/src/bundle/linux/rpm.rs @@ -52,7 +52,11 @@ pub fn bundle_project(settings: &Settings) -> crate::Result> { .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 diff --git a/tooling/bundler/src/bundle/settings.rs b/tooling/bundler/src/bundle/settings.rs index 27af3e53867..2369037faae 100644 --- a/tooling/bundler/src/bundle/settings.rs +++ b/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, + /// 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, /// the app's icon list. pub icon: Option>, /// 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. diff --git a/tooling/bundler/src/bundle/windows/msi/wix.rs b/tooling/bundler/src/bundle/windows/msi/wix.rs index 61370778221..01614e46f62 100644 --- a/tooling/bundler/src/bundle/windows/msi/wix.rs +++ b/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() diff --git a/tooling/bundler/src/bundle/windows/nsis.rs b/tooling/bundler/src/bundle/windows/nsis.rs index 9d2380b537b..6940b08f696 100644 --- a/tooling/bundler/src/bundle/windows/nsis.rs +++ b/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()), diff --git a/tooling/bundler/src/bundle/windows/templates/installer.nsi b/tooling/bundler/src/bundle/windows/templates/installer.nsi index 323dea5f584..82281d1abfb 100644 --- a/tooling/bundler/src/bundle/windows/templates/installer.nsi +++ b/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 diff --git a/tooling/bundler/src/bundle/windows/templates/main.wxs b/tooling/bundler/src/bundle/windows/templates/main.wxs index 9a985b86aaf..4ba6a480cdb 100644 --- a/tooling/bundler/src/bundle/windows/templates/main.wxs +++ b/tooling/bundler/src/bundle/windows/templates/main.wxs @@ -56,6 +56,12 @@ + {{#if homepage}} + + + + {{/if}} + diff --git a/tooling/cli/schema.json b/tooling/cli/schema.json index 9092a329f62..649b051a6ed 100644 --- a/tooling/cli/schema.json +++ b/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": [], diff --git a/tooling/cli/src/interface/rust.rs b/tooling/cli/src/interface/rust.rs index 4668dcaec03..4d634e89285 100644 --- a/tooling/cli/src/interface/rust.rs +++ b/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,