mirror of
https://github.com/Dasemu/Grove.git
synced 2026-11-26 15:26:09 +00:00
fix(gui): launch grove-gui by absolute path from desktop files
Desktop sessions (KDE Plasma on Fedora) often lack ~/.local/bin in PATH, so Exec=grove-gui never started a source install from the menu or at login. The Start-at-login toggle now writes the running binary's absolute path, and the README documents a source install whose menu entry does the same. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
31c8d5b4f7
commit
96e2d9585e
3 files changed
+64
-3
No files matched your search
@@ -16,6 +16,29 @@ pub fn file(config_home: &Path) -> PathBuf {
|
||||
config_home.join("autostart").join("grove.desktop")
|
||||
}
|
||||
|
||||
/// The autostart file, its `Exec` pointing at `exe` (this binary) by absolute path: desktop
|
||||
/// sessions often lack `~/.local/bin` (where `cargo install --root ~/.local` puts it) in `PATH`,
|
||||
/// and then a bare `grove-gui` never starts. Without a usable path the bare name is kept.
|
||||
fn desktop_text(exe: Option<&Path>) -> String {
|
||||
let Some(exe) = exe.filter(|e| e.is_absolute()).and_then(|e| e.to_str()) else {
|
||||
return DESKTOP.to_string();
|
||||
};
|
||||
// Desktop Entry spec: quote arguments with reserved characters, escaping `"`, `` ` ``, `$`, `\`.
|
||||
let exe = if exe.contains(|c: char| " \t\n\"'\\><~|&;$*?#()`".contains(c)) {
|
||||
let esc: String = exe
|
||||
.chars()
|
||||
.flat_map(|c| match c {
|
||||
'"' | '`' | '$' | '\\' => vec!['\\', c],
|
||||
c => vec![c],
|
||||
})
|
||||
.collect();
|
||||
format!("\"{esc}\"")
|
||||
} else {
|
||||
exe.to_string()
|
||||
};
|
||||
DESKTOP.replace("Exec=grove-gui", &format!("Exec={exe}"))
|
||||
}
|
||||
|
||||
pub fn is_enabled(config_home: &Path) -> bool {
|
||||
file(config_home).exists()
|
||||
}
|
||||
@@ -26,7 +49,8 @@ pub fn set(config_home: &Path, on: bool) -> std::io::Result<()> {
|
||||
if let Some(d) = f.parent() {
|
||||
std::fs::create_dir_all(d)?;
|
||||
}
|
||||
std::fs::write(&f, DESKTOP)
|
||||
let exe = std::env::current_exe().ok();
|
||||
std::fs::write(&f, desktop_text(exe.as_deref()))
|
||||
} else {
|
||||
match std::fs::remove_file(&f) {
|
||||
Err(e) if e.kind() != std::io::ErrorKind::NotFound => Err(e),
|
||||
@@ -47,10 +71,29 @@ mod tests {
|
||||
set(&d, true).unwrap();
|
||||
assert!(is_enabled(&d));
|
||||
let text = std::fs::read_to_string(file(&d)).unwrap();
|
||||
assert!(text.contains("Exec=grove-gui --hidden"));
|
||||
let exe = std::env::current_exe().unwrap();
|
||||
assert!(
|
||||
text.contains(&format!("Exec={} --hidden", exe.display())) || text.contains("Exec=\"")
|
||||
);
|
||||
set(&d, false).unwrap();
|
||||
assert!(!is_enabled(&d));
|
||||
set(&d, false).unwrap(); // already off: fine
|
||||
let _ = std::fs::remove_dir_all(&d);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exec_uses_the_absolute_binary_path_quoted_when_needed() {
|
||||
let t = desktop_text(Some(Path::new("/home/u/.local/bin/grove-gui")));
|
||||
assert!(
|
||||
t.contains("Exec=/home/u/.local/bin/grove-gui --hidden"),
|
||||
"{t}"
|
||||
);
|
||||
let t = desktop_text(Some(Path::new("/opt/my apps/grove-gui")));
|
||||
assert!(
|
||||
t.contains("Exec=\"/opt/my apps/grove-gui\" --hidden"),
|
||||
"{t}"
|
||||
);
|
||||
let t = desktop_text(None);
|
||||
assert!(t.contains("Exec=grove-gui --hidden"), "{t}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user