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 13, 2024
1 parent 33caff2 commit d9d658d
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 26 deletions.
67 changes: 67 additions & 0 deletions core/tauri-config-schema/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
}
]
},
"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 Expand Up @@ -2473,6 +2480,36 @@
"type": "string"
}
},
"provides": {
"description": "The list of dependencies the package provides.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"conflicts": {
"description": "The list of package conflicts.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"replaces": {
"description": "The list of package replaces.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"files": {
"description": "The files to include on the package.",
"default": {},
Expand Down Expand Up @@ -2526,6 +2563,36 @@
"type": "string"
}
},
"provides": {
"description": "The list of RPM dependencies your application provides.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"conflicts": {
"description": "The list of RPM dependencies your application conflicts with. They must not be present in order for the package to be installed.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"obsoletes": {
"description": "The list of RPM dependencies your application supersedes - if this package is installed, packages listed as “obsoletes” will be automatically removed (if they are present).",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"release": {
"description": "The RPM release tag.",
"default": "1",
Expand Down
33 changes: 26 additions & 7 deletions core/tauri-utils/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1989,6 +1989,9 @@ pub struct Config {
/// App name.
#[serde(alias = "product-name")]
pub product_name: Option<ProductName>,
/// 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 @@ -2053,12 +2056,6 @@ pub enum ProductName {
},
}

impl From<&str> for ProductName {
fn from(s: &str) -> Self {
Self::Default(s.to_string())
}
}

impl Display for ProductName {

fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down Expand Up @@ -2642,10 +2639,31 @@ mod build {
}
}

impl ToTokens for ProductName {
fn to_tokens(&self, tokens: &mut TokenStream) {
let prefix = quote! { ::tauri::utils::config::ProductName };

tokens.append_all(match self {
Self::Default(val) => {
let val = str_lit(val);
quote! { #prefix::Default(#val) }
},
Self::PerPlatform { default, linux, windows, macos } => {
let default = str_lit(default);
let linux = opt_str_lit(linux.as_ref());
let windows = opt_str_lit(windows.as_ref());
let macos = opt_str_lit(macos.as_ref());
quote! { #prefix::PerPlatform { default: #default, linux: #linux, windows: #windows, macos: #macos } }
}
})
}
}

impl ToTokens for Config {
fn to_tokens(&self, tokens: &mut TokenStream) {
let schema = quote!(None);
let product_name = opt_str_lit(self.product_name.as_ref().map(|n| n.to_string()));
let product_name = opt_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 @@ -2658,6 +2676,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 @@ -808,6 +810,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
67 changes: 67 additions & 0 deletions tooling/cli/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
}
]
},
"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 Expand Up @@ -2473,6 +2480,36 @@
"type": "string"
}
},
"provides": {
"description": "The list of dependencies the package provides.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"conflicts": {
"description": "The list of package conflicts.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"replaces": {
"description": "The list of package replaces.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"files": {
"description": "The files to include on the package.",
"default": {},
Expand Down Expand Up @@ -2526,6 +2563,36 @@
"type": "string"
}
},
"provides": {
"description": "The list of RPM dependencies your application provides.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"conflicts": {
"description": "The list of RPM dependencies your application conflicts with. They must not be present in order for the package to be installed.",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"obsoletes": {
"description": "The list of RPM dependencies your application supersedes - if this package is installed, packages listed as “obsoletes” will be automatically removed (if they are present).",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
},
"release": {
"description": "The RPM release tag.",
"default": "1",
Expand Down

0 comments on commit d9d658d

Please sign in to comment.