Skip to content

Commit

Permalink
feat(bundler): displayName for bundle tauri-apps#8109
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Mar 14, 2024
1 parent ea0242d commit af9e21b
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 19 deletions.
7 changes: 7 additions & 0 deletions core/tauri-config-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
],
"pattern": "^[^/\\:*?\"<>|]+$"
},
"displayName": {
"description": "App display name, will use `productName` if not set.",
"type": [
"string",
"null"
]
},
"version": {
"description": "App version. It is a semver version number or a path to a `package.json` file containing the `version` field. If removed the version number from `Cargo.toml` is used.",
"type": [
Expand Down
5 changes: 5 additions & 0 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1973,6 +1973,9 @@ pub struct Config {
#[serde(alias = "product-name")]
#[cfg_attr(feature = "schema", validate(regex(pattern = "^[^/\\:*?\"<>|]+$")))]
pub product_name: Option<String>,
/// App display name, will use `productName` if not set.
#[serde(alias = "display-name")]
pub display_name: Option<String>,
/// App version. It is a semver version number or a path to a `package.json` file containing the `version` field. If removed the version number from `Cargo.toml` is used.
#[serde(deserialize_with = "version_deserializer", default)]
pub version: Option<String>,
Expand Down Expand Up @@ -2578,6 +2581,7 @@ mod build {
fn to_tokens(&self, tokens: &mut TokenStream) {
let schema = quote!(None);
let product_name = opt_str_lit(self.product_name.as_ref());
let display_name = opt_str_lit(self.display_name.as_ref());
let version = opt_str_lit(self.version.as_ref());
let identifier = str_lit(&self.identifier);
let app = &self.app;
Expand All @@ -2590,6 +2594,7 @@ mod build {
::tauri::utils::config::Config,
schema,
product_name,
display_name,
version,
identifier,
app,
Expand Down
1 change: 1 addition & 0 deletions core/tauri/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub fn mock_context<R: Runtime, A: Assets<R>>(assets: A) -> crate::Context<R> {
config: Config {
schema: None,
product_name: Default::default(),
display_name: Default::default(),
version: Default::default(),
identifier: Default::default(),
app: AppConfig {
Expand Down
2 changes: 1 addition & 1 deletion tooling/bundler/src/bundle/linux/freedesktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ pub fn generate_desktop_file(
},
exec: bin_name,
icon: bin_name,
name: settings.product_name(),
name: settings.display_name(),
mime_type,
},
file,
Expand Down
2 changes: 1 addition & 1 deletion tooling/bundler/src/bundle/macos/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ fn create_info_plist(

let mut plist = plist::Dictionary::new();
plist.insert("CFBundleDevelopmentRegion".into(), "English".into());
plist.insert("CFBundleDisplayName".into(), settings.product_name().into());
plist.insert("CFBundleDisplayName".into(), settings.display_name().into());
plist.insert(
"CFBundleExecutable".into(),
settings.main_binary_name().into(),
Expand Down
2 changes: 1 addition & 1 deletion tooling/bundler/src/bundle/macos/ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ fn generate_info_plist(
writeln!(
file,
" <key>CFBundleDisplayName</key>\n <string>{}</string>",
settings.product_name()
settings.display_name()
)?;
writeln!(
file,
Expand Down
7 changes: 7 additions & 0 deletions tooling/bundler/src/bundle/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ const ALL_PACKAGE_TYPES: &[PackageType] = &[
pub struct PackageSettings {
/// the package's product name.
pub product_name: String,
/// the package's display name.
pub display_name: String,
/// the package's version.
pub version: String,
/// the package's description.
Expand Down Expand Up @@ -794,6 +796,11 @@ impl Settings {
&self.package.product_name
}

/// Returns the display name.
pub fn display_name(&self) -> &str {
&self.package.display_name
}

/// Returns the bundle's identifier
pub fn bundle_identifier(&self) -> &str {
self.bundle_settings.identifier.as_deref().unwrap_or("")
Expand Down
4 changes: 3 additions & 1 deletion tooling/bundler/src/bundle/windows/msi/wix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ pub fn build_wix_app_installer(
.unwrap_or_default();

data.insert("product_name", to_json(settings.product_name()));
data.insert("display_name", to_json(settings.display_name()));
data.insert("version", to_json(app_version));
let bundle_id = settings.bundle_identifier();
let manufacturer = settings
Expand Down Expand Up @@ -744,7 +745,8 @@ pub fn build_wix_app_installer(
let locale_strings = include_str!("./default-locale-strings.xml")
.replace("__language__", &language_metadata.lang_id.to_string())
.replace("__codepage__", &language_metadata.ascii_code.to_string())
.replace("__productName__", settings.product_name());
.replace("__productName__", settings.product_name())
.replace("__displayName__", settings.display_name());

let mut unset_locale_strings = String::new();
let prefix_len = "<String ".len();
Expand Down
1 change: 1 addition & 0 deletions tooling/bundler/src/bundle/windows/nsis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ 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("display_name", to_json(settings.display_name()));
data.insert("short_description", to_json(settings.short_description()));
data.insert("copyright", to_json(settings.copyright_string()));

Expand Down
7 changes: 4 additions & 3 deletions tooling/bundler/src/bundle/windows/templates/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ${StrLoc}

!define MANUFACTURER "{{manufacturer}}"
!define PRODUCTNAME "{{product_name}}"
!define DISPLAYNAME "{{display_name}}"
!define VERSION "{{version}}"
!define VERSIONWITHBUILD "{{version_with_build}}"
!define SHORTDESCRIPTION "{{short_description}}"
Expand All @@ -44,7 +45,7 @@ ${StrLoc}
!define UNINSTALLERSIGNCOMMAND "{{uninstaller_sign_cmd}}"
!define ESTIMATEDSIZE "{{estimated_size}}"

Name "${PRODUCTNAME}"
Name "${DISPLAYNAME}"
BrandingText "${COPYRIGHT}"
OutFile "${OUTFILE}"

Expand Down Expand Up @@ -557,7 +558,7 @@ Section Install
; Create file associations
{{#each file_associations as |association| ~}}
{{#each association.ext as |ext| ~}}
!insertmacro APP_ASSOCIATE "{{ext}}" "{{or association.name ext}}" "{{association-description association.description ext}}" "$INSTDIR\${MAINBINARYNAME}.exe,0" "Open with ${PRODUCTNAME}" "$INSTDIR\${MAINBINARYNAME}.exe $\"%1$\""
!insertmacro APP_ASSOCIATE "{{ext}}" "{{or association.name ext}}" "{{association-description association.description ext}}" "$INSTDIR\${MAINBINARYNAME}.exe,0" "Open with ${DISPLAYNAME}" "$INSTDIR\${MAINBINARYNAME}.exe $\"%1$\""
{{/each}}
{{/each}}

Expand All @@ -582,7 +583,7 @@ Section Install
!endif

; Registry information for add/remove programs
WriteRegStr SHCTX "${UNINSTKEY}" "DisplayName" "${PRODUCTNAME}"
WriteRegStr SHCTX "${UNINSTKEY}" "DisplayName" "${DISPLAYNAME}"
WriteRegStr SHCTX "${UNINSTKEY}" "DisplayIcon" "$\"$INSTDIR\${MAINBINARYNAME}.exe$\""
WriteRegStr SHCTX "${UNINSTKEY}" "DisplayVersion" "${VERSION}"
WriteRegStr SHCTX "${UNINSTKEY}" "Publisher" "${MANUFACTURER}"
Expand Down
12 changes: 6 additions & 6 deletions tooling/bundler/src/bundle/windows/templates/main.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="DesktopFolder" Name="Desktop">
<Component Id="ApplicationShortcutDesktop" Guid="*">
<Shortcut Id="ApplicationDesktopShortcut" Name="{{product_name}}" Description="Runs {{product_name}}" Target="[!Path]" WorkingDirectory="INSTALLDIR" />
<Shortcut Id="ApplicationDesktopShortcut" Name="{{display_name}}" Description="Runs {{display_name}}" Target="[!Path]" WorkingDirectory="INSTALLDIR" />
<RemoveFolder Id="DesktopFolder" On="uninstall" />
<RegistryValue Root="HKCU" Key="Software\\{{manufacturer}}\\{{product_name}}" Name="Desktop Shortcut" Type="integer" Value="1" KeyPath="yes" />
</Component>
Expand Down Expand Up @@ -131,7 +131,7 @@
{{#each association.ext as |ext| ~}}
<ProgId Id="{{../../product_name}}.{{ext}}" Advertise="yes" Description="{{association.description}}">
<Extension Id="{{ext}}" Advertise="yes">
<Verb Id="open" Command="Open with {{../../product_name}}" Argument="&quot;%1&quot;" />
<Verb Id="open" Command="Open with {{../../display_name}}" Argument="&quot;%1&quot;" />
</Extension>
</ProgId>
{{/each~}}
Expand All @@ -157,8 +157,8 @@
<Component Id="CMP_UninstallShortcut" Guid="*">

<Shortcut Id="UninstallShortcut"
Name="Uninstall {{product_name}}"
Description="Uninstalls {{product_name}}"
Name="Uninstall {{display_name}}"
Description="Uninstalls {{display_name}}"
Target="[System64Folder]msiexec.exe"
Arguments="/x [ProductCode]" />

Expand All @@ -177,8 +177,8 @@
<DirectoryRef Id="ApplicationProgramsFolder">
<Component Id="ApplicationShortcut" Guid="*">
<Shortcut Id="ApplicationStartMenuShortcut"
Name="{{product_name}}"
Description="Runs {{product_name}}"
Name="{{display_name}}"
Description="Runs {{display_name}}"
Target="[!Path]"
Icon="ProductIcon"
WorkingDirectory="INSTALLDIR">
Expand Down
7 changes: 7 additions & 0 deletions tooling/cli/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
],
"pattern": "^[^/\\:*?\"<>|]+$"
},
"displayName": {
"description": "App display name, will use `productName` if not set.",
"type": [
"string",
"null"
]
},
"version": {
"description": "App version. It is a semver version number or a path to a `package.json` file containing the `version` field. If removed the version number from `Cargo.toml` is used.",
"type": [
Expand Down
14 changes: 8 additions & 6 deletions tooling/cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,13 +1001,15 @@ impl RustAppSettings {
.workspace
.and_then(|v| v.package);

let product_name = config.product_name.clone().unwrap_or_else(|| {
cargo_package_settings
.name
.clone()
.expect("Cargo manifest must have the `package.name` field")
});
let package_settings = PackageSettings {
product_name: config.product_name.clone().unwrap_or_else(|| {
cargo_package_settings
.name
.clone()
.expect("Cargo manifest must have the `package.name` field")
}),
product_name: product_name.clone(),
display_name: config.display_name.clone().unwrap_or_else(|| product_name.clone()),
version: config.version.clone().unwrap_or_else(|| {
cargo_package_settings
.version
Expand Down

0 comments on commit af9e21b

Please sign in to comment.