From 930f6fa19e87681a38edce6c1cffb76196ee0b1f Mon Sep 17 00:00:00 2001 From: rdbtCVS <87152661+rdbtCVS@users.noreply.github.com> Date: Thu, 15 Oct 2026 00:49:41 +0100 Subject: [PATCH] Honor package wrappers in launcher desktop entries --- launcher/README.md | 4 +++ launcher/src/desktop.rs | 8 +++++- launcher/tests/desktop.rs | 55 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 launcher/tests/desktop.rs diff --git a/launcher/README.md b/launcher/README.md index 14014702b..cf5b24e4d 100644 --- a/launcher/README.md +++ b/launcher/README.md @@ -52,6 +52,10 @@ It also updates itself from GitHub releases tagged `launcher-vX.Y.Z` (Horizon's own binary, and offers "Restart" in the footer. Development builds and `HORIZON_LAUNCHER_NO_SELF_UPDATE=1` never replace themselves. +Linux packagers can set `HORIZON_LAUNCHER_DESKTOP_EXEC` to a wrapper's absolute path. +Menu entries created by Settings or `desktop-entry` then start that wrapper, which can +set `HORIZON_LAUNCHER_NO_SELF_UPDATE=1` to keep launcher updates with the package manager. + Launcher releases are automatic (docs/release-flow.md in the repository): when main changes the launcher, `horizon-prepare` or `horizon-theme`, the `launcher` workflow builds Linux, macOS and Windows and publishes `launcher-vX.Y.Z` (the next patch, or the next minor after a pull request diff --git a/launcher/src/desktop.rs b/launcher/src/desktop.rs index f97433139..430043dca 100644 --- a/launcher/src/desktop.rs +++ b/launcher/src/desktop.rs @@ -152,9 +152,15 @@ pub fn remove_in(data: &Path) -> io::Result<()> { Ok(()) } +/// Registers the launcher, using a distributor's wrapper when one is configured. +/// Both GUI registration (including the settings switch) and the CLI use this path. pub fn install(exe: &Path) -> Result { let data = data_home().ok_or("No home folder to put the menu entry in.")?; - install_in(&data, exe).map_err(|e| format!("{}: {e}", data.display())) + let wrapper = std::env::var_os("HORIZON_LAUNCHER_DESKTOP_EXEC") + .filter(|path| !path.is_empty()) + .map(PathBuf::from); + install_in(&data, wrapper.as_deref().unwrap_or(exe)) + .map_err(|e| format!("{}: {e}", data.display())) } pub fn remove() -> Result<(), String> { diff --git a/launcher/tests/desktop.rs b/launcher/tests/desktop.rs new file mode 100644 index 000000000..0a9f33ff1 --- /dev/null +++ b/launcher/tests/desktop.rs @@ -0,0 +1,55 @@ +//! Distributor wrappers must survive disabling and re-enabling menu integration. +#![cfg(target_os = "linux")] + +use std::path::Path; +use std::process::Command; + +fn desktop_entry(home: &Path, wrapper: Option<&str>, args: &[&str]) { + let mut command = Command::new(env!("CARGO_BIN_EXE_horizon-launcher")); + command + .arg("desktop-entry") + .args(args) + .env("HORIZON_LAUNCHER_HOME", home.join("launcher")) + .env("XDG_DATA_HOME", home.join("data")) + .env("HORIZON_LAUNCHER_NO_SELF_UPDATE", "1") + .env_remove("HORIZON_LAUNCHER_DESKTOP_EXEC"); + if let Some(wrapper) = wrapper { + command.env("HORIZON_LAUNCHER_DESKTOP_EXEC", wrapper); + } + let output = command.output().unwrap(); + assert!( + output.status.success(), + "{}", + String::from_utf8_lossy(&output.stderr) + ); +} + +#[test] +fn menu_registration_preserves_the_package_wrapper() { + let home = std::env::temp_dir().join(format!("horizon-desktop-wrapper-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&home); + let entry = home.join("data/applications/horizon-launcher.desktop"); + + // Migrate a registration that pointed at the private executable. + desktop_entry(&home, None, &[]); + let original = std::fs::read_to_string(&entry).unwrap(); + assert!(original.contains(&format!( + "Exec=\"{}\"\n", + env!("CARGO_BIN_EXE_horizon-launcher") + ))); + + let wrapper = "/usr/bin/horizon-launcher"; + for _ in 0..2 { + desktop_entry(&home, Some(wrapper), &[]); + let text = std::fs::read_to_string(&entry).unwrap(); + assert!(text.contains(&format!("Exec=\"{wrapper}\"\n"))); + assert!(text.contains(&format!("TryExec={wrapper}\n"))); + desktop_entry(&home, Some(wrapper), &["--remove"]); + assert!(!entry.exists()); + } + + // An unset or empty override keeps standalone installations working. + desktop_entry(&home, Some(""), &[]); + assert_eq!(std::fs::read_to_string(&entry).unwrap(), original); + std::fs::remove_dir_all(&home).unwrap(); +}