Skip to content

Commit 17194a9

Browse files
feat: add config option to disable linux desktop entry (#313)
* feat: add config option to disable linux desktop entry - CLI applications do not need to have desktop entries. - Additionally, this should also help applications that want to use their own Desktop entries for all the packages. - Currently, there seems to be an option to specify custom desktop entry template in debconfig, but not appimage and pacman. Signed-off-by: Ayush Singh <[email protected]> * cleanup * fmt --------- Signed-off-by: Ayush Singh <[email protected]> Co-authored-by: Lucas Nogueira <[email protected]>
1 parent 728fa01 commit 17194a9

File tree

6 files changed

+84
-4
lines changed

6 files changed

+84
-4
lines changed

.changes/disable-desktop-entry.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"cargo-packager": patch
3+
"@crabnebula/packager": patch
4+
---
5+
6+
Added `linux > generateDesktopEntry` config to allow disabling generating a .desktop file on Linux bundles (defaults to true).

bindings/packager/nodejs/schema.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,17 @@
248248
}
249249
]
250250
},
251+
"linux": {
252+
"description": "Linux-specific configuration",
253+
"anyOf": [
254+
{
255+
"$ref": "#/definitions/LinuxConfig"
256+
},
257+
{
258+
"type": "null"
259+
}
260+
]
261+
},
251262
"deb": {
252263
"description": "Debian-specific configuration.",
253264
"anyOf": [
@@ -792,6 +803,18 @@
792803
},
793804
"additionalProperties": false
794805
},
806+
"LinuxConfig": {
807+
"description": "Linux configuration",
808+
"type": "object",
809+
"properties": {
810+
"generateDesktopEntry": {
811+
"description": "Flag to indicate if desktop entry should be generated.",
812+
"default": true,
813+
"type": "boolean"
814+
}
815+
},
816+
"additionalProperties": false
817+
},
795818
"DebianConfig": {
796819
"description": "The Linux Debian configuration.",
797820
"type": "object",

crates/packager/schema.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,17 @@
248248
}
249249
]
250250
},
251+
"linux": {
252+
"description": "Linux-specific configuration",
253+
"anyOf": [
254+
{
255+
"$ref": "#/definitions/LinuxConfig"
256+
},
257+
{
258+
"type": "null"
259+
}
260+
]
261+
},
251262
"deb": {
252263
"description": "Debian-specific configuration.",
253264
"anyOf": [
@@ -792,6 +803,18 @@
792803
},
793804
"additionalProperties": false
794805
},
806+
"LinuxConfig": {
807+
"description": "Linux configuration",
808+
"type": "object",
809+
"properties": {
810+
"generateDesktopEntry": {
811+
"description": "Flag to indicate if desktop entry should be generated.",
812+
"default": true,
813+
"type": "boolean"
814+
}
815+
},
816+
"additionalProperties": false
817+
},
795818
"DebianConfig": {
796819
"description": "The Linux Debian configuration.",
797820
"type": "object",

crates/packager/src/config/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,21 @@ impl MacOsConfig {
840840
}
841841
}
842842

843+
/// Linux configuration
844+
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
845+
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
846+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
847+
#[non_exhaustive]
848+
pub struct LinuxConfig {
849+
/// Flag to indicate if desktop entry should be generated.
850+
#[serde(
851+
default = "default_true",
852+
alias = "generate-desktop-entry",
853+
alias = "generate_desktop_entry"
854+
)]
855+
pub generate_desktop_entry: bool,
856+
}
857+
843858
/// A wix language.
844859
#[derive(Debug, Clone, Deserialize, Serialize)]
845860
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
@@ -1715,6 +1730,8 @@ pub struct Config {
17151730
pub windows: Option<WindowsConfig>,
17161731
/// MacOS-specific configuration.
17171732
pub macos: Option<MacOsConfig>,
1733+
/// Linux-specific configuration
1734+
pub linux: Option<LinuxConfig>,
17181735
/// Debian-specific configuration.
17191736
pub deb: Option<DebianConfig>,
17201737
/// AppImage configuration.
@@ -1745,6 +1762,11 @@ impl Config {
17451762
self.macos.as_ref()
17461763
}
17471764

1765+
/// Returns the [linux](Config::linux) specific configuration.
1766+
pub fn linux(&self) -> Option<&LinuxConfig> {
1767+
self.linux.as_ref()
1768+
}
1769+
17481770
/// Returns the [nsis](Config::nsis) specific configuration.
17491771
pub fn nsis(&self) -> Option<&NsisConfig> {
17501772
self.nsis.as_ref()

crates/packager/src/package/app/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,13 @@ fn create_info_plist(
317317

318318
plist.insert("LSRequiresCarbon".into(), true.into());
319319
plist.insert("NSHighResolutionCapable".into(), true.into());
320-
320+
321321
if let Some(macos_config) = config.macos() {
322322
if macos_config.background_app {
323323
plist.insert("LSUIElement".into(), true.into());
324324
}
325325
}
326-
326+
327327
if let Some(copyright) = &config.copyright {
328328
plist.insert("NSHumanReadableCopyright".into(), copyright.clone().into());
329329
}

crates/packager/src/package/deb/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,14 @@ pub fn generate_data(config: &Config, data_dir: &Path) -> crate::Result<BTreeSet
208208
tracing::debug!("Generating icons");
209209
let icons = generate_icon_files(config, data_dir)?;
210210

211-
tracing::debug!("Generating desktop file");
212-
generate_desktop_file(config, data_dir)?;
211+
let generate_desktop_entry = config
212+
.linux()
213+
.map_or(true, |linux| linux.generate_desktop_entry);
214+
215+
if generate_desktop_entry {
216+
tracing::debug!("Generating desktop file");
217+
generate_desktop_file(config, data_dir)?;
218+
}
213219

214220
Ok(icons)
215221
}

0 commit comments

Comments
 (0)