Skip to content

Commit

Permalink
feat: add bundle > homepage option (#9977)
Browse files Browse the repository at this point in the history
* feat: add `bundle > homepage` option

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

closes #9949

* Update settings.rs
  • Loading branch information
amrbashir authored Jun 5, 2024
1 parent 40c0f44 commit fafc238
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .changes/bundler-homepage-url.md
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions core/tauri-config-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
8 changes: 8 additions & 0 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down Expand Up @@ -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());
Expand All @@ -2439,6 +2445,7 @@ mod build {
::tauri::utils::config::BundleConfig,
active,
publisher,
homepage,
icon,
targets,
resources,
Expand Down Expand Up @@ -2756,6 +2763,7 @@ mod test {
active: false,
targets: Default::default(),
publisher: None,
homepage: None,
icon: Vec::new(),
resources: None,
copyright: None,
Expand Down
5 changes: 3 additions & 2 deletions tooling/bundler/src/bundle/linux/debian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(", "))?;
Expand Down
6 changes: 5 additions & 1 deletion tooling/bundler/src/bundle/linux/rpm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 12 additions & 3 deletions tooling/bundler/src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions tooling/bundler/src/bundle/windows/msi/wix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 4 additions & 0 deletions tooling/bundler/src/bundle/windows/nsis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
6 changes: 6 additions & 0 deletions tooling/bundler/src/bundle/windows/templates/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tooling/bundler/src/bundle/windows/templates/main.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -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"/>
Expand Down
7 changes: 7 additions & 0 deletions tooling/cli/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down
1 change: 1 addition & 0 deletions tooling/cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit fafc238

Please sign in to comment.