Merge pull request #244 from rdbtCVS/fix/launcher-desktop-wrapper

Preserve package wrappers in launcher desktop entries
This commit is contained in:
Ludovic Marie
2026-10-15 02:09:35 +02:00
committed by GitHub
3 changed files with 66 additions and 1 deletions
+4
View File
@@ -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
+7 -1
View File
@@ -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<bool, String> {
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> {
+55
View File
@@ -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();
}