Repository: tauri-apps/tauri
File: tooling/bundler/src/bundle/linux/debian.rs (Rust)

Code before:

  Ok((data_dir, icons))
}

/// Generate the application desktop file and store it under the `data_dir`.
fn generate_desktop_file(settings: &Settings, data_dir: &Path) -> crate::Result<()> {
  let bin_name = settings.main_binary_name();
  let desktop_file_name = format!("{}.desktop", bin_name);
  let desktop_file_path = data_dir
    .join("usr/share/applications")
    .join(desktop_file_name);

  // For more information about the format of this file, see
  // https://developer.gnome.org/integration-guide/stable/desktop-files.html.en
  let file = &mut common::create_file(&desktop_file_path)?;

  let mut handlebars = Handlebars::new();
  if let Some(template) = &settings.deb().desktop_template {
    handlebars
      .register_template_string("main.desktop", read_to_string(template)?)
      .map_err(|e| e.to_string())
      .expect("Failed to setup custom handlebar template");
  } else {
    handlebars
      .register_template_string("main.desktop", include_str!("./templates/main.desktop"))
      .map_err(|e| e.to_string())
      .expect("Failed to setup handlebar template");
  }

  #[derive(Serialize)]
  struct DesktopTemplateParams<'a> {
    categories: &'a str,
    comment: Option<&'a str>,
    exec: &'a str,
    icon: &'a str,
    name: &'a str,
  }

  handlebars.render_to_write(
    "main.desktop",
    &DesktopTemplateParams {
      categories: settings
        .app_category()
        .map(|app_category| app_category.gnome_desktop_categories())
        .unwrap_or(""),
      comment: if !settings.short_description().is_empty() {
        Some(settings.short_description())
      } else {
        None
      },
      exec: bin_name,

Review comment (bug):
```suggestion
    handlebars
      .register_template_string("main.desktop", include_str!("./templates/main.desktop"))
      .with_context(|| "Failed to setup handlebar template")?;
```

Code after:

  Ok((data_dir, icons))
}

/// Generate the application desktop file and store it under the `data_dir`.
fn generate_desktop_file(settings: &Settings, data_dir: &Path) -> crate::Result<()> {
  let bin_name = settings.main_binary_name();
  let desktop_file_name = format!("{}.desktop", bin_name);
  let desktop_file_path = data_dir
    .join("usr/share/applications")
    .join(desktop_file_name);

  // For more information about the format of this file, see
  // https://developer.gnome.org/integration-guide/stable/desktop-files.html.en
  let file = &mut common::create_file(&desktop_file_path)?;

  let mut handlebars = Handlebars::new();
  handlebars.register_escape_fn(handlebars::no_escape);
  if let Some(template) = &settings.deb().desktop_template {
    handlebars
      .register_template_string("main.desktop", read_to_string(template)?)
      .with_context(|| "Failed to setup custom handlebar template")?;
  } else {
    handlebars
      .register_template_string("main.desktop", include_str!("./templates/main.desktop"))
      .with_context(|| "Failed to setup custom handlebar template")?;
  }

  #[derive(Serialize)]
  struct DesktopTemplateParams<'a> {
    categories: &'a str,
    comment: Option<&'a str>,
    exec: &'a str,
    icon: &'a str,
    name: &'a str,
  }

  handlebars.render_to_write(
    "main.desktop",
    &DesktopTemplateParams {
      categories: settings
        .app_category()
        .map(|app_category| app_category.gnome_desktop_categories())
        .unwrap_or(""),
      comment: if !settings.short_description().is_empty() {
        Some(settings.short_description())
      } else {
        None
      },
      exec: bin_name,
      icon: bin_name,