Browse Source

fix: keep original `productName` for .desktop `Name` field, closes #2295 (#2384)

Lucas Fernandes Nogueira 4 năm trước cách đây
mục cha
commit
3f039cb8a3

+ 6 - 0
.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 - 0
.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).

+ 0 - 3
core/tauri-utils/Cargo.toml

@@ -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" ]

+ 1 - 7
core/tauri-utils/src/lib.rs

@@ -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()
   }
 }
 

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
examples/api/public/build/bundle.js


Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
examples/api/public/build/bundle.js.map


+ 3 - 0
tooling/bundler/Cargo.toml

@@ -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"

+ 2 - 1
tooling/bundler/src/bundle/linux/debian.rs

@@ -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};
@@ -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)?;

+ 1 - 0
tooling/cli.rs/Cargo.lock

@@ -1893,6 +1893,7 @@ dependencies = [
  "dirs-next",
  "glob",
  "handlebars",
+ "heck",
  "hex",
  "icns",
  "image",

+ 3 - 0
tooling/cli.rs/Cargo.toml

@@ -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" ] }

+ 16 - 0
tooling/cli.rs/config_definition.rs

@@ -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;
@@ -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)]

+ 10 - 1
tooling/cli.rs/src/build.rs

@@ -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::{
@@ -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 `{}`",

+ 1 - 8
tooling/cli.rs/src/helpers/config.rs

@@ -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;
@@ -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);
 

+ 9 - 6
tooling/cli.rs/src/interface/rust.rs

@@ -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};
@@ -212,8 +214,7 @@ impl AppSettings {
             BundleBinary::new(
               config
                 .package
-                .product_name
-                .clone()
+                .binary_name()
                 .unwrap_or_else(|| binary.name.clone()),
               true,
             )
@@ -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,
           ));
@@ -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,
       )),

Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác