Forráskód Böngészése

feat(config): allow setting product name and version on tauri.conf.json (#1358)

Lucas Fernandes Nogueira 4 éve
szülő
commit
5b3d9b2c07

+ 6 - 0
.changes/package-config.md

@@ -0,0 +1,6 @@
+---
+"tauri": minor
+"tauri-cli": minor
+---
+
+Adds `productName` and `version` configs on `tauri.conf.json > package`.

+ 1 - 0
cli/core/Cargo.lock

@@ -1677,6 +1677,7 @@ dependencies = [
  "anyhow",
  "clap",
  "colored",
+ "heck",
  "json-patch",
  "notify",
  "once_cell",

+ 3 - 0
cli/core/Cargo.toml

@@ -35,3 +35,6 @@ serde_with = "1.6"
 
 [target."cfg(target_os = \"windows\")".dependencies]
 which = "4.0"
+
+[target."cfg(target_os = \"linux\")".dependencies]
+heck = "0.3"

+ 13 - 2
cli/core/config_definition.rs

@@ -35,6 +35,16 @@ pub struct OsxConfig {
   pub use_bootstrapper: bool,
 }
 
+#[skip_serializing_none]
+#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
+#[serde(rename_all = "camelCase", deny_unknown_fields)]
+pub struct PackageConfig {
+  /// App name. Automatically converted to kebab-case on Linux.
+  pub product_name: Option<String>,
+  /// App version.
+  pub version: Option<String>,
+}
+
 #[skip_serializing_none]
 #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
 #[serde(rename_all = "camelCase", deny_unknown_fields)]
@@ -43,12 +53,10 @@ pub struct BundleConfig {
   pub active: bool,
   /// The bundle targets, currently supports ["deb", "osx", "msi", "appimage", "dmg"] or "all"
   pub targets: Option<BundleTarget>,
-  pub name: Option<String>,
   /// The app's identifier
   pub identifier: Option<String>,
   /// The app's icons
   pub icon: Option<Vec<String>>,
-  pub version: Option<String>,
   /// App resources to bundle.
   /// Each resource is a path to a file or directory.
   /// Glob patterns are supported.
@@ -540,6 +548,9 @@ type JsonObject = HashMap<String, JsonValue>;
 #[derive(Debug, PartialEq, Clone, Deserialize, Serialize, JsonSchema)]
 #[serde(rename_all = "camelCase", deny_unknown_fields)]
 pub struct Config {
+  /// Package settings.
+  #[serde(default)]
+  pub package: PackageConfig,
   /// The Tauri configuration.
   #[serde(default)]
   pub tauri: TauriConfig,

+ 29 - 12
cli/core/schema.json

@@ -17,6 +17,15 @@
         }
       ]
     },
+    "package": {
+      "description": "Package settings.",
+      "default": {},
+      "allOf": [
+        {
+          "$ref": "#/definitions/PackageConfig"
+        }
+      ]
+    },
     "plugins": {
       "description": "The plugins config.",
       "default": {},
@@ -287,12 +296,6 @@
             "null"
           ]
         },
-        "name": {
-          "type": [
-            "string",
-            "null"
-          ]
-        },
         "osx": {
           "default": {
             "useBootstrapper": false
@@ -335,12 +338,6 @@
               "type": "null"
             }
           ]
-        },
-        "version": {
-          "type": [
-            "string",
-            "null"
-          ]
         }
       },
       "additionalProperties": false
@@ -773,6 +770,26 @@
       },
       "additionalProperties": false
     },
+    "PackageConfig": {
+      "type": "object",
+      "properties": {
+        "productName": {
+          "description": "App name. Automatically converted to kebab-case on Linux.",
+          "type": [
+            "string",
+            "null"
+          ]
+        },
+        "version": {
+          "description": "App version.",
+          "type": [
+            "string",
+            "null"
+          ]
+        }
+      },
+      "additionalProperties": false
+    },
     "SecurityConfig": {
       "type": "object",
       "properties": {

+ 28 - 11
cli/core/src/build.rs

@@ -8,7 +8,13 @@ use crate::helpers::{
   Logger, TauriScript,
 };
 
-use std::{env::set_current_dir, fs::File, io::Write, path::PathBuf, process::Command};
+use std::{
+  env::set_current_dir,
+  fs::{rename, File},
+  io::Write,
+  path::PathBuf,
+  process::Command,
+};
 
 mod rust;
 
@@ -98,33 +104,44 @@ impl Build {
 
     rust::build_project(self.debug)?;
 
+    let app_settings = rust::AppSettings::new(&config_)?;
+
+    let out_dir = app_settings.get_out_dir(self.debug)?;
+    if let Some(product_name) = config_.package.product_name.clone() {
+      let bin_name = app_settings.cargo_package_settings().name.clone();
+      #[cfg(windows)]
+      rename(
+        out_dir.join(format!("{}.exe", bin_name)),
+        out_dir.join(format!("{}.exe", product_name)),
+      )?;
+      #[cfg(not(windows))]
+      rename(out_dir.join(bin_name), out_dir.join(product_name))?;
+    }
+
     if config_.tauri.bundle.active {
-      let bundler_settings = rust::get_bundler_settings(&config_, self.debug)?;
       // move merge modules to the out dir so the bundler can load it
       #[cfg(windows)]
       {
         let (filename, vcruntime_msm) = if cfg!(target_arch = "x86") {
-          let _ =
-            std::fs::remove_file(bundler_settings.out_dir.join("Microsoft_VC142_CRT_x64.msm"));
+          let _ = std::fs::remove_file(out_dir.join("Microsoft_VC142_CRT_x64.msm"));
           (
             "Microsoft_VC142_CRT_x86.msm",
             include_bytes!("./MergeModules/Microsoft_VC142_CRT_x86.msm").to_vec(),
           )
         } else {
-          let _ =
-            std::fs::remove_file(bundler_settings.out_dir.join("Microsoft_VC142_CRT_x86.msm"));
+          let _ = std::fs::remove_file(out_dir.join("Microsoft_VC142_CRT_x86.msm"));
           (
             "Microsoft_VC142_CRT_x64.msm",
             include_bytes!("./MergeModules/Microsoft_VC142_CRT_x64.msm").to_vec(),
           )
         };
-        std::fs::write(bundler_settings.out_dir.join(filename), vcruntime_msm)?;
+        std::fs::write(out_dir.join(filename), vcruntime_msm)?;
       }
       let mut settings_builder = SettingsBuilder::new()
-        .package_settings(bundler_settings.package_settings)
-        .bundle_settings(bundler_settings.bundle_settings)
-        .binaries(bundler_settings.binaries)
-        .project_out_directory(bundler_settings.out_dir);
+        .package_settings(app_settings.get_package_settings())
+        .bundle_settings(app_settings.get_bundle_settings(&config_)?)
+        .binaries(app_settings.get_binaries(&config_)?)
+        .project_out_directory(out_dir);
 
       if self.verbose {
         settings_builder = settings_builder.verbose();

+ 141 - 64
cli/core/src/build/rust.rs

@@ -18,13 +18,30 @@ struct BinarySettings {
   path: Option<String>,
 }
 
+/// The package settings.
+#[derive(Debug, Clone, Deserialize)]
+pub struct CargoPackageSettings {
+  /// the package's name.
+  pub name: String,
+  /// the package's version.
+  pub version: String,
+  /// the package's description.
+  pub description: String,
+  /// the package's homepage.
+  pub homepage: Option<String>,
+  /// the package's authors.
+  pub authors: Option<Vec<String>>,
+  /// the default binary to run.
+  pub default_run: Option<String>,
+}
+
 /// The Cargo settings (Cargo.toml root descriptor).
 #[derive(Clone, Debug, Deserialize)]
 struct CargoSettings {
   /// the package settings.
   ///
   /// it's optional because ancestor workspace Cargo.toml files may not have package info.
-  package: Option<PackageSettings>,
+  package: Option<CargoPackageSettings>,
   /// the workspace settings.
   ///
   /// it's present if the read Cargo.toml belongs to a workspace root.
@@ -73,80 +90,142 @@ pub fn build_project(debug: bool) -> crate::Result<()> {
   Ok(())
 }
 
-pub struct BundlerSettings {
-  pub package_settings: PackageSettings,
-  pub bundle_settings: BundleSettings,
-  pub binaries: Vec<BundleBinary>,
-  pub out_dir: PathBuf,
+pub struct AppSettings {
+  cargo_settings: CargoSettings,
+  cargo_package_settings: CargoPackageSettings,
+  package_settings: PackageSettings,
 }
 
-pub fn get_bundler_settings(config: &Config, debug: bool) -> crate::Result<BundlerSettings> {
-  let tauri_dir = tauri_dir();
-  let cargo_settings = CargoSettings::load(&tauri_dir)?;
+impl AppSettings {
+  pub fn new(config: &Config) -> crate::Result<Self> {
+    let cargo_settings = CargoSettings::load(&tauri_dir())?;
+    let cargo_package_settings = match &cargo_settings.package {
+      Some(package_info) => package_info.clone(),
+      None => {
+        return Err(anyhow::anyhow!(
+          "No package info in the config file".to_owned(),
+        ))
+      }
+    };
 
-  let package = match cargo_settings.package {
-    Some(package_info) => package_info,
-    None => {
-      return Err(anyhow::anyhow!(
-        "No package info in the config file".to_owned(),
-      ))
-    }
-  };
-  let workspace_dir = get_workspace_dir(&tauri_dir);
-  let target_dir = get_target_dir(&workspace_dir, None, !debug)?;
-  let bundle_settings = tauri_config_to_bundle_settings(config.tauri.bundle.clone())?;
-
-  let mut binaries: Vec<BundleBinary> = vec![];
-  if let Some(bin) = cargo_settings.bin {
-    let default_run = package
-      .default_run
-      .clone()
-      .unwrap_or_else(|| "".to_string());
-    for binary in bin {
-      binaries.push(
-        BundleBinary::new(
-          binary.name.clone(),
-          binary.name.as_str() == package.name || binary.name.as_str() == default_run,
+    let package_settings = PackageSettings {
+      product_name: config
+        .package
+        .product_name
+        .clone()
+        .unwrap_or_else(|| cargo_package_settings.name.clone()),
+      version: config
+        .package
+        .version
+        .clone()
+        .unwrap_or_else(|| cargo_package_settings.version.clone()),
+      description: cargo_package_settings.description.clone(),
+      homepage: cargo_package_settings.homepage.clone(),
+      authors: cargo_package_settings.authors.clone(),
+      default_run: cargo_package_settings.default_run.clone(),
+    };
+
+    Ok(Self {
+      cargo_settings,
+      cargo_package_settings,
+      package_settings,
+    })
+  }
+
+  pub fn cargo_package_settings(&self) -> &CargoPackageSettings {
+    &self.cargo_package_settings
+  }
+
+  pub fn get_bundle_settings(&self, config: &Config) -> crate::Result<BundleSettings> {
+    tauri_config_to_bundle_settings(config.tauri.bundle.clone())
+  }
+
+  pub fn get_out_dir(&self, debug: bool) -> crate::Result<PathBuf> {
+    let tauri_dir = tauri_dir();
+    let workspace_dir = get_workspace_dir(&tauri_dir);
+    get_target_dir(&workspace_dir, None, !debug)
+  }
+
+  pub fn get_package_settings(&self) -> PackageSettings {
+    self.package_settings.clone()
+  }
+
+  pub fn get_binaries(&self, config: &Config) -> crate::Result<Vec<BundleBinary>> {
+    let mut binaries: Vec<BundleBinary> = vec![];
+    if let Some(bin) = &self.cargo_settings.bin {
+      let default_run = self
+        .package_settings
+        .default_run
+        .clone()
+        .unwrap_or_else(|| "".to_string());
+      for binary in bin {
+        binaries.push(
+          if binary.name.as_str() == self.cargo_package_settings.name
+            || binary.name.as_str() == default_run
+          {
+            BundleBinary::new(
+              config
+                .package
+                .product_name
+                .clone()
+                .unwrap_or_else(|| binary.name.clone()),
+              true,
+            )
+          } else {
+            BundleBinary::new(binary.name.clone(), false)
+          }
+          .set_src_path(binary.path.clone()),
         )
-        .set_src_path(binary.path),
-      )
+      }
     }
-  }
 
-  let mut bins_path = tauri_dir;
-  bins_path.push("src/bin");
-  if let Ok(fs_bins) = std::fs::read_dir(bins_path) {
-    for entry in fs_bins {
-      let path = entry?.path();
-      if let Some(name) = path.file_stem() {
-        let bin_exists = binaries.iter().any(|bin| {
-          bin.name() == name || path.ends_with(bin.src_path().as_ref().unwrap_or(&"".to_string()))
-        });
-        if !bin_exists {
-          binaries.push(BundleBinary::new(name.to_string_lossy().to_string(), false))
+    let mut bins_path = tauri_dir();
+    bins_path.push("src/bin");
+    if let Ok(fs_bins) = std::fs::read_dir(bins_path) {
+      for entry in fs_bins {
+        let path = entry?.path();
+        if let Some(name) = path.file_stem() {
+          let bin_exists = binaries.iter().any(|bin| {
+            bin.name() == name || path.ends_with(bin.src_path().as_ref().unwrap_or(&"".to_string()))
+          });
+          if !bin_exists {
+            binaries.push(BundleBinary::new(name.to_string_lossy().to_string(), false))
+          }
+        }
+      }
+    }
+
+    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);
+          }
+        }
+        None => {
+          binaries.push(BundleBinary::new(
+            config
+              .package
+              .product_name
+              .clone()
+              .unwrap_or_else(|| default_run.to_string()),
+            true,
+          ));
         }
       }
     }
-  }
 
-  if let Some(default_run) = package.default_run.as_ref() {
-    if !binaries.iter().any(|bin| bin.name() == default_run) {
-      binaries.push(BundleBinary::new(default_run.to_string(), true));
+    match binaries.len() {
+      0 => binaries.push(BundleBinary::new(
+        self.package_settings.product_name.clone(),
+        true,
+      )),
+      1 => binaries.get_mut(0).unwrap().set_main(true),
+      _ => {}
     }
-  }
 
-  match binaries.len() {
-    0 => binaries.push(BundleBinary::new(package.name.clone(), true)),
-    1 => binaries.get_mut(0).unwrap().set_main(true),
-    _ => {}
+    Ok(binaries)
   }
-
-  Ok(BundlerSettings {
-    package_settings: package,
-    bundle_settings,
-    binaries,
-    out_dir: target_dir,
-  })
 }
 
 /// This function determines where 'target' dir is and suffixes it with 'release' or 'debug'
@@ -225,10 +304,8 @@ fn tauri_config_to_bundle_settings(
   config: crate::helpers::config::BundleConfig,
 ) -> crate::Result<BundleSettings> {
   Ok(BundleSettings {
-    name: config.name,
     identifier: config.identifier,
     icon: config.icon,
-    version: config.version,
     resources: config.resources,
     copyright: config.copyright,
     category: match config.category {

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

@@ -1,3 +1,5 @@
+#[cfg(target_os = "linux")]
+use heck::KebabCase;
 use json_patch::merge;
 use once_cell::sync::Lazy;
 use serde_json::Value as JsonValue;
@@ -57,7 +59,12 @@ fn get_internal(merge_config: Option<&str>, reload: bool) -> crate::Result<Confi
     merge(&mut config, &merge_config);
   }
 
-  let config = serde_json::from_value(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();
+  }
   set_var("TAURI_CONFIG", serde_json::to_string(&config)?);
   *config_handle().lock().unwrap() = Some(config);
 

+ 4 - 4
cli/tauri-bundler/src/bundle/deb_bundle.rs

@@ -188,9 +188,10 @@ fn generate_desktop_file(settings: &Settings, data_dir: &Path) -> crate::Result<
   // For more information about the format of this file, see
   // https://developer.gnome.org/integration-guide/stable/desktop-files.html.en
   writeln!(file, "[Desktop Entry]")?;
-  writeln!(file, "Encoding=UTF-8")?;
   if let Some(category) = settings.app_category() {
     writeln!(file, "Categories={}", category.gnome_desktop_categories())?;
+  } else {
+    writeln!(file, "Categories=")?;
   }
   if !settings.short_description().is_empty() {
     writeln!(file, "Comment={}", settings.short_description())?;
@@ -206,10 +207,9 @@ fn generate_desktop_file(settings: &Settings, data_dir: &Path) -> crate::Result<
     }
   )?;
   writeln!(file, "Icon={}", bin_name)?;
-  writeln!(file, "Name={}", settings.bundle_name())?;
+  writeln!(file, "Name={}", settings.product_name())?;
   writeln!(file, "Terminal=false")?;
   writeln!(file, "Type=Application")?;
-  writeln!(file, "Version={}", settings.version_string())?;
   Ok(())
 }
 
@@ -227,7 +227,7 @@ fn generate_control_file(
   writeln!(
     &mut file,
     "Package: {}",
-    str::replace(settings.bundle_name(), " ", "-").to_ascii_lowercase()
+    str::replace(settings.product_name(), " ", "-").to_ascii_lowercase()
   )?;
   writeln!(&mut file, "Version: {}", settings.version_string())?;
   writeln!(&mut file, "Architecture: {}", arch)?;

+ 5 - 5
cli/tauri-bundler/src/bundle/dmg_bundle.rs

@@ -30,9 +30,9 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
   let dmg_name = format!("{}.dmg", &package_base_name);
   let dmg_path = output_path.join(&dmg_name);
 
-  let bundle_name = &format!("{}.app", &package_base_name);
+  let product_name = &format!("{}.app", &package_base_name);
   let bundle_dir = settings.project_out_directory().join("bundle/osx");
-  let bundle_path = bundle_dir.join(&bundle_name.clone());
+  let bundle_path = bundle_dir.join(&product_name.clone());
 
   let support_directory_path = output_path.join("support");
   if output_path.exists() {
@@ -83,7 +83,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
     "--volicon",
     "../../../../icons/icon.icns",
     "--icon",
-    &bundle_name,
+    &product_name,
     "180",
     "170",
     "--app-drop-link",
@@ -93,7 +93,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
     "660",
     "400",
     "--hide-extension",
-    &bundle_name,
+    &product_name,
   ];
 
   if let Some(license_path) = settings.osx_license() {
@@ -114,7 +114,7 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
   cmd
     .current_dir(bundle_dir.clone())
     .args(args)
-    .args(vec![dmg_name.as_str(), bundle_name.as_str()]);
+    .args(vec![dmg_name.as_str(), product_name.as_str()]);
 
   common::print_info("running bundle_dmg.sh")?;
   common::execute_with_verbosity(&mut cmd, &settings).map_err(|_| {

+ 6 - 6
cli/tauri-bundler/src/bundle/ios_bundle.rs

@@ -27,15 +27,15 @@ use std::{
 pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
   common::print_warning("iOS bundle support is still experimental.")?;
 
-  let app_bundle_name = format!("{}.app", settings.bundle_name());
-  common::print_bundling(&app_bundle_name)?;
+  let app_product_name = format!("{}.app", settings.product_name());
+  common::print_bundling(&app_product_name)?;
   let bundle_dir = settings
     .project_out_directory()
     .join("bundle/ios")
-    .join(&app_bundle_name);
+    .join(&app_product_name);
   if bundle_dir.exists() {
     fs::remove_dir_all(&bundle_dir)
-      .with_context(|| format!("Failed to remove old {}", app_bundle_name))?;
+      .with_context(|| format!("Failed to remove old {}", app_product_name))?;
   }
   fs::create_dir_all(&bundle_dir)
     .with_context(|| format!("Failed to create bundle directory at {:?}", bundle_dir))?;
@@ -153,12 +153,12 @@ fn generate_info_plist(
   writeln!(
     file,
     "  <key>CFBundleDisplayName</key>\n  <string>{}</string>",
-    settings.bundle_name()
+    settings.product_name()
   )?;
   writeln!(
     file,
     "  <key>CFBundleName</key>\n  <string>{}</string>",
-    settings.bundle_name()
+    settings.product_name()
   )?;
   writeln!(
     file,

+ 8 - 8
cli/tauri-bundler/src/bundle/osx_bundle.rs

@@ -44,15 +44,15 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
       other => other,
     }
   );
-  let app_bundle_name = format!("{}.app", package_base_name);
-  common::print_bundling(&app_bundle_name)?;
+  let app_product_name = format!("{}.app", package_base_name);
+  common::print_bundling(&app_product_name)?;
   let app_bundle_path = settings
     .project_out_directory()
     .join("bundle/osx")
-    .join(&app_bundle_name);
+    .join(&app_product_name);
   if app_bundle_path.exists() {
     fs::remove_dir_all(&app_bundle_path)
-      .with_context(|| format!("Failed to remove old {}", app_bundle_name))?;
+      .with_context(|| format!("Failed to remove old {}", app_product_name))?;
   }
   let bundle_directory = app_bundle_path.join("Contents");
   fs::create_dir_all(&bundle_directory).with_context(|| {
@@ -138,7 +138,7 @@ else
     exec \"`dirname \\\"$0\\\"`/{}\" $@ & disown
 fi
 exit 0",
-    settings.bundle_name()
+    settings.product_name()
   )?;
   file.flush()?;
 
@@ -179,7 +179,7 @@ fn create_info_plist(
   write!(
     file,
     "  <key>CFBundleDisplayName</key>\n  <string>{}</string>\n",
-    settings.bundle_name()
+    settings.product_name()
   )?;
   write!(
     file,
@@ -210,7 +210,7 @@ fn create_info_plist(
   write!(
     file,
     "  <key>CFBundleName</key>\n  <string>{}</string>\n",
-    settings.bundle_name()
+    settings.product_name()
   )?;
   write!(
     file,
@@ -411,7 +411,7 @@ fn create_icns_file(
   if !family.is_empty() {
     fs::create_dir_all(resources_dir)?;
     let mut dest_path = resources_dir.clone();
-    dest_path.push(settings.bundle_name());
+    dest_path.push(settings.product_name());
     dest_path.set_extension("icns");
     let icns_file = BufWriter::new(File::create(&dest_path)?);
     family.write(icns_file)?;

+ 11 - 20
cli/tauri-bundler/src/bundle/settings.rs

@@ -81,8 +81,8 @@ const ALL_PACKAGE_TYPES: &[PackageType] = &[
 /// The package settings.
 #[derive(Debug, Clone, Deserialize)]
 pub struct PackageSettings {
-  /// the package's name.
-  pub name: String,
+  /// the package's product name.
+  pub product_name: String,
   /// the package's version.
   pub version: String,
   /// the package's description.
@@ -98,15 +98,10 @@ pub struct PackageSettings {
 /// The bundle settings of the BuildArtifact we're bundling.
 #[derive(Clone, Debug, Deserialize, Default)]
 pub struct BundleSettings {
-  // General settings:
-  /// the name of the bundle.
-  pub name: Option<String>,
   /// the app's identifier.
   pub identifier: Option<String>,
   /// the app's icon list.
   pub icon: Option<Vec<String>>,
-  /// the app's version.
-  pub version: Option<String>,
   /// the app's resources to bundle.
   ///
   /// each item can be a path to a file or a path to a folder.
@@ -204,6 +199,10 @@ impl BundleBinary {
     self.main = main;
   }
 
+  pub fn set_name(&mut self, name: String) {
+    self.name = name;
+  }
+
   pub fn name(&self) -> &str {
     &self.name
   }
@@ -385,13 +384,9 @@ impl Settings {
     self.is_verbose
   }
 
-  /// Returns the bundle name, which is either package.metadata.bundle.name or package.name
-  pub fn bundle_name(&self) -> &str {
-    self
-      .bundle_settings
-      .name
-      .as_ref()
-      .unwrap_or(&self.package.name)
+  /// Returns the product name.
+  pub fn product_name(&self) -> &str {
+    &self.package.product_name
   }
 
   /// Returns the bundle's identifier
@@ -454,13 +449,9 @@ impl Settings {
     Ok(())
   }
 
-  /// Returns the version string of the bundle, which is either package.metadata.version or package.version.
+  /// Returns the version string of the bundle.
   pub fn version_string(&self) -> &str {
-    self
-      .bundle_settings
-      .version
-      .as_ref()
-      .unwrap_or(&self.package.version)
+    &self.package.version
   }
 
   /// Returns the copyright text.

+ 9 - 19
cli/tauri-bundler/src/bundle/templates/appimage

@@ -4,39 +4,29 @@ set -euxo pipefail
 
 export ARCH=x86_64
 
-mkdir -p {{app_name}}.AppDir
-cp -r ../appimage_deb/data/usr {{app_name}}.AppDir
+mkdir -p "{{app_name}}.AppDir"
+cp -r ../appimage_deb/data/usr "{{app_name}}.AppDir"
 
-cd {{app_name}}.AppDir
+cd "{{app_name}}.AppDir"
 
 wget -q -4 -O AppRun https://github.com/AppImage/AppImageKit/releases/download/continuous/AppRun-x86_64 || wget -q -4 -O AppRun https://github.com/AppImage/AppImageKit/releases/download/12/AppRun-aarch64
 chmod +x AppRun
 
-cp usr/share/icons/hicolor/256x256/apps/{{app_name}}.png {{app_name}}.png
+cp "usr/share/icons/hicolor/256x256/apps/{{app_name}}.png" "{{app_name}}.png"
 
 cd ..
 
-echo '[Desktop Entry]' > {{app_name}}.desktop
-echo 'Version=1.0' >> {{app_name}}.desktop
-echo 'Comment=A Tauri App' >> {{app_name}}.desktop
-echo 'Exec={{app_name}}' >> {{app_name}}.desktop
-echo 'Icon={{app_name}}' >> {{app_name}}.desktop
-echo 'Name={{app_name_uppercase}}' >> {{app_name}}.desktop
-echo 'Terminal=false' >> {{app_name}}.desktop
-echo 'Type=Application' >> {{app_name}}.desktop
-echo 'Categories=X-Web;' >> {{app_name}}.desktop
+cp "../appimage_deb/data/usr/share/applications/{{app_name}}.desktop" "{{app_name}}.AppDir/usr/share/applications/{{app_name}}.desktop"
+cp "../appimage_deb/data/usr/share/applications/{{app_name}}.desktop" "{{app_name}}.AppDir/{{app_name}}.desktop"
 
-cp {{app_name}}.desktop {{app_name}}.AppDir/usr/share/applications/{{app_name}}.desktop
-mv {{app_name}}.desktop {{app_name}}.AppDir/{{app_name}}.desktop
-
-mksquashfs {{app_name}}.AppDir {{app_name}}.squashfs -root-owned -noappend
+mksquashfs "{{app_name}}.AppDir" "{{app_name}}.squashfs" -root-owned -noappend
 
 wget -q -4 -O appimagetool https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-x86_64.AppImage || wget -q -4 -O appimagetool https://github.com/AppImage/AppImageKit/releases/download/12/appimagetool-x86_64.AppImage
 chmod +x appimagetool
 if lsmod | grep -q fuse; then
-  ./appimagetool {{app_name}}.AppDir {{appimage_filename}}
+  ./appimagetool "{{app_name}}.AppDir" "{{appimage_filename}}"
 else
   ./appimagetool --appimage-extract
-  ./squashfs-root/AppRun {{app_name}}.AppDir {{appimage_filename}}
+  ./squashfs-root/AppRun "{{app_name}}.AppDir" "{{appimage_filename}}"
   rm -rf ./squashfs-root
 fi

+ 1 - 1
cli/tauri-bundler/src/bundle/wix.rs

@@ -442,7 +442,7 @@ pub fn build_wix_app_installer(
 
   let mut data = BTreeMap::new();
 
-  data.insert("product_name", to_json(settings.bundle_name()));
+  data.insert("product_name", to_json(settings.product_name()));
   data.insert("version", to_json(settings.version_string()));
   let manufacturer = settings.bundle_identifier().to_string();
   data.insert("manufacturer", to_json(manufacturer.as_str()));

+ 4 - 0
cli/tauri.js/src/template/defaultConfig.ts

@@ -1,4 +1,8 @@
 export default {
+  package: {
+    productName: 'app',
+    version: '0.1.0'
+  },
   build: {
     distDir: '../dist',
     devPath: 'http://localhost:4000',

+ 4 - 0
examples/api/src-tauri/tauri.conf.json

@@ -5,6 +5,10 @@
     "beforeDevCommand": "yarn dev",
     "beforeBuildCommand": "yarn build"
   },
+  "package": {
+    "productName": "Tauri API",
+    "version": "0.1.0"
+  },
   "tauri": {
     "cli": {
       "description": "Tauri API example",