Skip to content

Commit

Permalink
fix: keep original productName for .desktop Name field, closes #2295
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Aug 10, 2021
1 parent 8b2cc26 commit 3f039cb
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 43 deletions.
6 changes: 6 additions & 0 deletions .changes/linux-app-name.md
@@ -0,0 +1,6 @@
---
"cli.rs": patch
"tauri-bundler": patch
---

Only convert package name and binary name to kebab-case, keeping the `.desktop` `Name` field with the original configured value.
6 changes: 6 additions & 0 deletions .changes/product-name-original.md
@@ -0,0 +1,6 @@
---
"tauri": patch
"tauri-utils": patch
---

Keep original value on `config > package > productName` on Linux (previously converted to kebab-case).
3 changes: 0 additions & 3 deletions core/tauri-utils/Cargo.toml
Expand Up @@ -22,8 +22,5 @@ html5ever = "0.25"
proc-macro2 = { version = "1.0", optional = true }
quote = { version = "1.0", optional = true }

[target."cfg(target_os = \"linux\")".dependencies]
heck = "0.3"

[features]
build = [ "proc-macro2", "quote" ]
8 changes: 1 addition & 7 deletions core/tauri-utils/src/lib.rs
Expand Up @@ -27,13 +27,7 @@ impl PackageInfo {
/// Returns the application package name.
/// On macOS and Windows it's the `name` field, and on Linux it's the `name` in `kebab-case`.
pub fn package_name(&self) -> String {
#[cfg(target_os = "linux")]
{
use heck::KebabCase;
self.name.to_kebab_case()
}
#[cfg(not(target_os = "linux"))]
return self.name.clone();
self.name.clone()
}
}

Expand Down
18 changes: 2 additions & 16 deletions examples/api/public/build/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion examples/api/public/build/bundle.js.map

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions tooling/bundler/Cargo.toml
Expand Up @@ -53,6 +53,9 @@ hex = "0.4"
chrono = "0.4"
dirs-next = "2.0"

[target."cfg(target_os = \"linux\")".dependencies]
heck = "0.3"

[lib]
name = "tauri_bundler"
path = "src/lib.rs"
3 changes: 2 additions & 1 deletion tooling/bundler/src/bundle/linux/debian.rs
Expand Up @@ -26,6 +26,7 @@ use super::super::common;
use crate::Settings;

use anyhow::Context;
use heck::KebabCase;
use image::{self, png::PngDecoder, GenericImageView, ImageDecoder};
use libflate::gzip;
use std::process::{Command, Stdio};
Expand Down Expand Up @@ -251,7 +252,7 @@ fn generate_control_file(
writeln!(
&mut file,
"Package: {}",
str::replace(settings.product_name(), " ", "-").to_ascii_lowercase()
settings.product_name().to_kebab_case().to_ascii_lowercase()
)?;
writeln!(&mut file, "Version: {}", settings.version_string())?;
writeln!(&mut file, "Architecture: {}", arch)?;
Expand Down
1 change: 1 addition & 0 deletions tooling/cli.rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tooling/cli.rs/Cargo.toml
Expand Up @@ -54,6 +54,9 @@ encode_unicode = "0.3"
[target."cfg(target_os = \"linux\")".dependencies]
heck = "0.3"

[target."cfg(target_os = \"linux\")".build-dependencies]
heck = "0.3"

[build-dependencies]
schemars = "0.8"
serde = { version = "1.0", features = [ "derive" ] }
Expand Down
16 changes: 16 additions & 0 deletions tooling/cli.rs/config_definition.rs
Expand Up @@ -4,6 +4,8 @@

#![allow(clippy::field_reassign_with_default)]

#[cfg(target_os = "linux")]
use heck::KebabCase;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::Value as JsonValue;
Expand Down Expand Up @@ -103,6 +105,20 @@ pub struct PackageConfig {
pub version: Option<String>,
}

impl PackageConfig {
#[allow(dead_code)]
pub fn binary_name(&self) -> Option<String> {
#[cfg(target_os = "linux")]
{
self.product_name.as_ref().map(|n| n.to_kebab_case())
}
#[cfg(not(target_os = "linux"))]
{
self.product_name.clone()
}
}
}

#[skip_serializing_none]
#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
Expand Down
11 changes: 10 additions & 1 deletion tooling/cli.rs/src/build.rs
Expand Up @@ -3,6 +3,8 @@
// SPDX-License-Identifier: MIT

use anyhow::Context;
#[cfg(target_os = "linux")]
use heck::KebabCase;
use tauri_bundler::bundle::{bundle_project, PackageType};

use crate::helpers::{
Expand Down Expand Up @@ -139,8 +141,15 @@ impl Build {
out_dir.join(format!("{}.exe", product_name)),
)
};
#[cfg(not(windows))]
#[cfg(target_os = "macos")]
let (bin_path, product_path) = { (out_dir.join(bin_name), out_dir.join(product_name)) };
#[cfg(target_os = "linux")]
let (bin_path, product_path) = {
(
out_dir.join(bin_name),
out_dir.join(product_name.to_kebab_case()),
)
};
rename(&bin_path, &product_path).with_context(|| {
format!(
"failed to rename `{}` to `{}`",
Expand Down
9 changes: 1 addition & 8 deletions tooling/cli.rs/src/helpers/config.rs
Expand Up @@ -3,8 +3,6 @@
// SPDX-License-Identifier: MIT

use anyhow::Context;
#[cfg(target_os = "linux")]
use heck::KebabCase;
use json_patch::merge;
use once_cell::sync::Lazy;
use serde_json::Value as JsonValue;
Expand Down Expand Up @@ -99,12 +97,7 @@ fn get_internal(merge_config: Option<&str>, reload: bool) -> crate::Result<Confi
merge(&mut config, &platform_config);
}

#[allow(unused_mut)]
let mut config: Config = serde_json::from_value(config)?;
#[cfg(target_os = "linux")]
if let Some(product_name) = config.package.product_name.as_mut() {
*product_name = product_name.to_kebab_case();
}
let config: Config = serde_json::from_value(config)?;
set_var("TAURI_CONFIG", serde_json::to_string(&config)?);
*config_handle().lock().unwrap() = Some(config);

Expand Down
15 changes: 9 additions & 6 deletions tooling/cli.rs/src/interface/rust.rs
Expand Up @@ -11,6 +11,8 @@ use std::{
};

use anyhow::Context;
#[cfg(target_os = "linux")]
use heck::KebabCase;
use serde::Deserialize;

use crate::helpers::{app_paths::tauri_dir, config::Config, manifest::Manifest};
Expand Down Expand Up @@ -212,8 +214,7 @@ impl AppSettings {
BundleBinary::new(
config
.package
.product_name
.clone()
.binary_name()
.unwrap_or_else(|| binary.name.clone()),
true,
)
Expand Down Expand Up @@ -244,16 +245,15 @@ impl AppSettings {
if let Some(default_run) = self.package_settings.default_run.as_ref() {
match binaries.iter_mut().find(|bin| bin.name() == default_run) {
Some(bin) => {
if let Some(product_name) = config.package.product_name.clone() {
bin.set_name(product_name);
if let Some(bin_name) = config.package.binary_name() {
bin.set_name(bin_name);
}
}
None => {
binaries.push(BundleBinary::new(
config
.package
.product_name
.clone()
.binary_name()
.unwrap_or_else(|| default_run.to_string()),
true,
));
Expand All @@ -263,6 +263,9 @@ impl AppSettings {

match binaries.len() {
0 => binaries.push(BundleBinary::new(
#[cfg(target_os = "linux")]
self.package_settings.product_name.to_kebab_case(),
#[cfg(not(target_os = "linux"))]
self.package_settings.product_name.clone(),
true,
)),
Expand Down

0 comments on commit 3f039cb

Please sign in to comment.