mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-28 20:48:52 +03:00
Co-authored-by: Fabian-Lars <fabianlars@fabianlars.de> Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
parent
ff5e4dbbb0
commit
35cd751adc
7
.changes/deb-custom-desktop-file-config.md
Normal file
7
.changes/deb-custom-desktop-file-config.md
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
"tauri-utils": patch
|
||||
"tauri-cli": patch
|
||||
"@tauri-apps/cli": patch
|
||||
---
|
||||
|
||||
Added the `desktop_template` option on `tauri.conf.json > tauri > bundle > deb`.
|
5
.changes/deb-custom-desktop-file.md
Normal file
5
.changes/deb-custom-desktop-file.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri-bundler": "minor:feat"
|
||||
---
|
||||
|
||||
Added `desktop_template` option on `DebianSettings`.
|
@ -1270,6 +1270,13 @@
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"desktopTemplate": {
|
||||
"description": "Path to a custom desktop file Handlebars template.\n\nAvailable variables: `categories`, `comment` (optional), `exec`, `icon` and `name`.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
@ -276,6 +276,10 @@ pub struct DebConfig {
|
||||
/// The files to include on the package.
|
||||
#[serde(default)]
|
||||
pub files: HashMap<PathBuf, PathBuf>,
|
||||
/// Path to a custom desktop file Handlebars template.
|
||||
///
|
||||
/// Available variables: `categories`, `comment` (optional), `exec`, `icon` and `name`.
|
||||
pub desktop_template: Option<PathBuf>,
|
||||
}
|
||||
|
||||
fn de_minimum_system_version<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
|
||||
|
@ -26,16 +26,18 @@
|
||||
use super::super::common;
|
||||
use crate::Settings;
|
||||
use anyhow::Context;
|
||||
use handlebars::Handlebars;
|
||||
use heck::AsKebabCase;
|
||||
use image::{self, codecs::png::PngDecoder, ImageDecoder};
|
||||
use libflate::gzip;
|
||||
use log::info;
|
||||
use serde::Serialize;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use std::{
|
||||
collections::BTreeSet,
|
||||
ffi::OsStr,
|
||||
fs::{self, File},
|
||||
fs::{self, read_to_string, File},
|
||||
io::{self, Write},
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
@ -141,23 +143,51 @@ fn generate_desktop_file(settings: &Settings, data_dir: &Path) -> crate::Result<
|
||||
let desktop_file_path = data_dir
|
||||
.join("usr/share/applications")
|
||||
.join(desktop_file_name);
|
||||
let file = &mut common::create_file(&desktop_file_path)?;
|
||||
|
||||
// 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]")?;
|
||||
if let Some(category) = settings.app_category() {
|
||||
writeln!(file, "Categories={}", category.gnome_desktop_categories())?;
|
||||
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 {
|
||||
writeln!(file, "Categories=")?;
|
||||
handlebars
|
||||
.register_template_string("main.desktop", include_str!("./templates/main.desktop"))
|
||||
.with_context(|| "Failed to setup custom handlebar template")?;
|
||||
}
|
||||
if !settings.short_description().is_empty() {
|
||||
writeln!(file, "Comment={}", settings.short_description())?;
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct DesktopTemplateParams<'a> {
|
||||
categories: &'a str,
|
||||
comment: Option<&'a str>,
|
||||
exec: &'a str,
|
||||
icon: &'a str,
|
||||
name: &'a str,
|
||||
}
|
||||
writeln!(file, "Exec={}", bin_name)?;
|
||||
writeln!(file, "Icon={}", bin_name)?;
|
||||
writeln!(file, "Name={}", settings.product_name())?;
|
||||
writeln!(file, "Terminal=false")?;
|
||||
writeln!(file, "Type=Application")?;
|
||||
|
||||
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,
|
||||
name: settings.product_name(),
|
||||
},
|
||||
file,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
10
tooling/bundler/src/bundle/linux/templates/main.desktop
Normal file
10
tooling/bundler/src/bundle/linux/templates/main.desktop
Normal file
@ -0,0 +1,10 @@
|
||||
[Desktop Entry]
|
||||
Categories={{categories}}
|
||||
{{#if comment}}
|
||||
Comment={{comment}}
|
||||
{{/if}}
|
||||
Exec={{exec}}
|
||||
Icon={{icon}}
|
||||
Name={{name}}
|
||||
Terminal=false
|
||||
Type=Application
|
@ -156,6 +156,15 @@ pub struct DebianSettings {
|
||||
/// List of custom files to add to the deb package.
|
||||
/// Maps the path on the debian package to the path of the file to include (relative to the current working directory).
|
||||
pub files: HashMap<PathBuf, PathBuf>,
|
||||
/// Path to a custom desktop file Handlebars template.
|
||||
///
|
||||
/// Available variables: `categories`, `comment` (optional), `exec`, `icon` and `name`.
|
||||
///
|
||||
/// Default file contents:
|
||||
/// ```text
|
||||
#[doc = include_str!("./linux/templates/main.desktop")]
|
||||
/// ```
|
||||
pub desktop_template: Option<PathBuf>,
|
||||
}
|
||||
|
||||
/// The macOS bundle settings.
|
||||
|
@ -1270,6 +1270,13 @@
|
||||
"additionalProperties": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"desktopTemplate": {
|
||||
"description": "Path to a custom desktop file Handlebars template.\n\nAvailable variables: `categories`, `comment` (optional), `exec`, `icon` and `name`.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
@ -1067,6 +1067,7 @@ fn tauri_config_to_bundle_settings(
|
||||
Some(depends)
|
||||
},
|
||||
files: config.deb.files,
|
||||
desktop_template: config.deb.desktop_template,
|
||||
},
|
||||
macos: MacOsSettings {
|
||||
frameworks: config.macos.frameworks,
|
||||
|
Loading…
Reference in New Issue
Block a user