mirror of
https://github.com/Dasemu/Grove.git
synced 2026-11-26 23:36:11 +00:00
Merge pull request #17 from Dasemu/fix/desktop-exec-absolute-path
fix(gui): launch grove-gui by absolute path from desktop files
This commit is contained in:
3 files changed
+64
-3
No files matched your search
@@ -3,6 +3,23 @@
|
|||||||
Keeps your git repos in sync across machines without manual commit/push/pull, including
|
Keeps your git repos in sync across machines without manual commit/push/pull, including
|
||||||
work in progress. Early stage (Phase 1: core library and CLI). See `docs/` for details.
|
work in progress. Early stage (Phase 1: core library and CLI). See `docs/` for details.
|
||||||
|
|
||||||
|
## Install from source
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cargo install --locked --root ~/.local --path crates/grove
|
||||||
|
cargo install --locked --root ~/.local --path crates/grove-daemon
|
||||||
|
cargo install --locked --root ~/.local --path crates/grove-gui
|
||||||
|
install -Dm644 contrib/groved.service ~/.config/systemd/user/groved.service
|
||||||
|
systemctl --user enable --now groved
|
||||||
|
# Menu entry: desktop sessions often lack ~/.local/bin in PATH, so use the absolute path.
|
||||||
|
sed "s|^Exec=grove-gui|Exec=$HOME/.local/bin/grove-gui|" contrib/grove.desktop \
|
||||||
|
> ~/.local/share/applications/grove.desktop
|
||||||
|
install -Dm644 assets/grove.png ~/.local/share/icons/hicolor/64x64/apps/grove.png
|
||||||
|
```
|
||||||
|
|
||||||
|
Start-at-login is a toggle in the app's Settings. A `.deb` is also available
|
||||||
|
(`cargo deb -p grove`, see `docs/phase7.md`).
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
MIT, see `LICENSE`.
|
MIT, see `LICENSE`.
|
||||||
|
|||||||
@@ -16,6 +16,29 @@ pub fn file(config_home: &Path) -> PathBuf {
|
|||||||
config_home.join("autostart").join("grove.desktop")
|
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 {
|
pub fn is_enabled(config_home: &Path) -> bool {
|
||||||
file(config_home).exists()
|
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() {
|
if let Some(d) = f.parent() {
|
||||||
std::fs::create_dir_all(d)?;
|
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 {
|
} else {
|
||||||
match std::fs::remove_file(&f) {
|
match std::fs::remove_file(&f) {
|
||||||
Err(e) if e.kind() != std::io::ErrorKind::NotFound => Err(e),
|
Err(e) if e.kind() != std::io::ErrorKind::NotFound => Err(e),
|
||||||
@@ -47,10 +71,29 @@ mod tests {
|
|||||||
set(&d, true).unwrap();
|
set(&d, true).unwrap();
|
||||||
assert!(is_enabled(&d));
|
assert!(is_enabled(&d));
|
||||||
let text = std::fs::read_to_string(file(&d)).unwrap();
|
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();
|
set(&d, false).unwrap();
|
||||||
assert!(!is_enabled(&d));
|
assert!(!is_enabled(&d));
|
||||||
set(&d, false).unwrap(); // already off: fine
|
set(&d, false).unwrap(); // already off: fine
|
||||||
let _ = std::fs::remove_dir_all(&d);
|
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}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+2
-1
@@ -54,7 +54,8 @@ grove-gui --view settings # start on a view (activity, new, im
|
|||||||
`grove` is looked up next to the `grove-gui` binary, then in `PATH`. Packaging: `.deb` installs
|
`grove` is looked up next to the `grove-gui` binary, then in `PATH`. Packaging: `.deb` installs
|
||||||
`grove-gui`, `contrib/grove.desktop`, `assets/grove.png` and a copy of the autostart file under
|
`grove-gui`, `contrib/grove.desktop`, `assets/grove.png` and a copy of the autostart file under
|
||||||
`/usr/share/grove/`. Autostart is opt-in: Settings has a "Start Grove at login" toggle that writes or
|
`/usr/share/grove/`. Autostart is opt-in: Settings has a "Start Grove at login" toggle that writes or
|
||||||
removes `~/.config/autostart/grove.desktop`. The deb recommends `libnotify-bin` (`notify-send`). Dev builds need no system Qt: Slint is built with the `winit` backend (Wayland and
|
removes `~/.config/autostart/grove.desktop`; its `Exec` is the running binary's absolute path,
|
||||||
|
because desktop sessions often lack `~/.local/bin` in `PATH` (a source install from the README). The deb recommends `libnotify-bin` (`notify-send`). Dev builds need no system Qt: Slint is built with the `winit` backend (Wayland and
|
||||||
X11 loaded at runtime) and the software renderer.
|
X11 loaded at runtime) and the software renderer.
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
|
|||||||
Reference in new issue
Block a user