Fix desktop entries with Terminal=true
not working
This commit is contained in:
@@ -16,5 +16,8 @@ Config(
|
||||
// Also show the Desktop Actions defined in the desktop files, e.g. "New Window" from LibreWolf
|
||||
desktop_actions: true,
|
||||
max_entries: 5,
|
||||
// The terminal used for running terminal based desktop entries, if left as `None` a static list of terminals is used
|
||||
// to determine what terminal to use.
|
||||
terminal: Some("alacritty"),
|
||||
)
|
||||
```
|
@@ -9,6 +9,7 @@ use std::{fs, process::Command};
|
||||
pub struct Config {
|
||||
desktop_actions: bool,
|
||||
max_entries: usize,
|
||||
terminal: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
@@ -16,6 +17,7 @@ impl Default for Config {
|
||||
Self {
|
||||
desktop_actions: false,
|
||||
max_entries: 5,
|
||||
terminal: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +29,8 @@ pub struct State {
|
||||
|
||||
mod scrubber;
|
||||
|
||||
const SENSIBLE_TERMINALS: &[&str] = &["alacritty", "foot", "kitty", "wezterm", "wterm"];
|
||||
|
||||
#[handler]
|
||||
pub fn handler(selection: Match, state: &State) -> HandleResult {
|
||||
let entry = state
|
||||
@@ -41,8 +45,28 @@ pub fn handler(selection: Match, state: &State) -> HandleResult {
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
if let Err(why) = Command::new("sh").arg("-c").arg(&entry.exec).spawn() {
|
||||
println!("Error running desktop entry: {}", why);
|
||||
if entry.term {
|
||||
match &state.config.terminal {
|
||||
Some(term) => {
|
||||
if let Err(why) = Command::new(term).arg("-e").arg(&entry.exec).spawn() {
|
||||
eprintln!("Error running desktop entry: {}", why);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
for term in SENSIBLE_TERMINALS {
|
||||
if Command::new(term)
|
||||
.arg("-e")
|
||||
.arg(&entry.exec)
|
||||
.spawn()
|
||||
.is_ok()
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if let Err(why) = Command::new("sh").arg("-c").arg(&entry.exec).spawn() {
|
||||
eprintln!("Error running desktop entry: {}", why);
|
||||
}
|
||||
|
||||
HandleResult::Close
|
||||
|
@@ -8,6 +8,7 @@ pub struct DesktopEntry {
|
||||
pub name: String,
|
||||
pub desc: Option<String>,
|
||||
pub icon: String,
|
||||
pub term: bool,
|
||||
}
|
||||
|
||||
const FIELD_CODE_LIST: &[&str] = &[
|
||||
@@ -78,6 +79,10 @@ impl DesktopEntry {
|
||||
.get("Icon")
|
||||
.unwrap_or(&"application-x-executable")
|
||||
.to_string(),
|
||||
term: map
|
||||
.get("Terminal")
|
||||
.map(|val| val.to_lowercase() == "true")
|
||||
.unwrap_or(false),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
@@ -119,6 +124,10 @@ impl DesktopEntry {
|
||||
},
|
||||
desc: Some(entry.name.clone()),
|
||||
icon: entry.icon.clone(),
|
||||
term: map
|
||||
.get("Terminal")
|
||||
.map(|val| val.to_lowercase() == "true")
|
||||
.unwrap_or(false),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user