Skip to content

Commit

Permalink
0.2.6 - More robust desktop launching
Browse files Browse the repository at this point in the history
Fallback order
 - `dex`
 - `gio`
 - `exo-open`
 - `gtk-launch`
 - linch manual launch

It also checks gtk-launch to make sure it actually launches cause
APPARENTLY it doesn't know subdirectories exist???

I know there's others like `kde-open` but I couldn't make them work
seamlessly as a subprocess so too bad
  • Loading branch information
Beinsezii committed Aug 25, 2023
1 parent 4974ce0 commit 1d5cb38
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "linch"
version = "0.2.5"
version = "0.2.6"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# linch 0.2.5
# linch 0.2.6
Cross-desktop application launcher made with ~~iced~~ egui

<img src="./screenshot.png" height = 300 px />
Expand All @@ -13,7 +13,7 @@ Cross-desktop application launcher made with ~~iced~~ egui
## Usage
`linch bin` for running binaries directly from `PATH`

`linch app` for running [desktop applications](https://wiki.archlinux.org/title/Desktop_entries). If you do not have GTK installed or `gtk-launch` is unavailable, it's strongly recommended you install [dex](https://github.com/jceb/dex) for smarter launching of desktop entries. The fallback method employed directly by Linch is extremely barebones.
`linch app` for running [desktop applications](https://wiki.archlinux.org/title/Desktop_entries)

`linch help` for additional information

Expand Down
61 changes: 33 additions & 28 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1002,38 +1002,43 @@ fn main() {
true,
monochrome,
) {
let mut errs;
if let Err(err_gtk) = std::process::Command::new("gtk-launch")
for launcher in [
std::process::Command::new("dex").arg(&item.file),
std::process::Command::new("gio")
.arg("launch")
.arg(&item.file),
std::process::Command::new("exo-open").arg(&item.file),
] {
if launcher.spawn().is_ok() {
return;
}
}
eprintln!("All featured launchers failed. Falling back to gtk-launch");
match std::process::Command::new("gtk-launch")
.arg(item.file.file_stem().unwrap())
.spawn()
{
errs = format!("Could not start app through gtk-launch: {}", err_gtk);
if let Err(err_dex) = std::process::Command::new("dex").arg(&item.file).spawn()
{
errs += &format!("\nCould not start app through dex: {}", err_dex);
if let Some(exec) = item.exec.as_ref() {
let items = exec.split_whitespace().collect::<Vec<&str>>();
let mut command = if let Some(mut path) = item.path.clone() {
path.push(items[0]);
std::process::Command::new(path)
} else {
std::process::Command::new(items[0])
};
if let Some(args) = items.get(1..) {
command.args(args);
}
if let Err(err_exec) = command.spawn() {
eprintln!(
"{}\nStarting application directly failed: {}",
errs, err_exec
);
}
Ok(mut child) => {
if child.wait().unwrap().success() {
return;
}
eprintln!(
"{}\nCould not read Exec field from {}",
errs,
item.file.to_string_lossy()
);
}
Err(e) => eprintln!("{}", e),
}
eprintln!("Falling back to manual desktop entry launching");
if let Some(exec) = item.exec.as_ref() {
let items = exec.split_whitespace().collect::<Vec<&str>>();
let mut command = if let Some(mut path) = item.path.clone() {
path.push(items[0]);
std::process::Command::new(path)
} else {
std::process::Command::new(items[0])
};
if let Some(args) = items.get(1..) {
command.args(args);
}
if let Err(err_exec) = command.spawn() {
eprintln!("Starting application directly failed: {}", err_exec);
}
}
}
Expand Down

0 comments on commit 1d5cb38

Please sign in to comment.