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
|
// Also show the Desktop Actions defined in the desktop files, e.g. "New Window" from LibreWolf
|
||||||
desktop_actions: true,
|
desktop_actions: true,
|
||||||
max_entries: 5,
|
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 {
|
pub struct Config {
|
||||||
desktop_actions: bool,
|
desktop_actions: bool,
|
||||||
max_entries: usize,
|
max_entries: usize,
|
||||||
|
terminal: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
@@ -16,6 +17,7 @@ impl Default for Config {
|
|||||||
Self {
|
Self {
|
||||||
desktop_actions: false,
|
desktop_actions: false,
|
||||||
max_entries: 5,
|
max_entries: 5,
|
||||||
|
terminal: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,6 +29,8 @@ pub struct State {
|
|||||||
|
|
||||||
mod scrubber;
|
mod scrubber;
|
||||||
|
|
||||||
|
const SENSIBLE_TERMINALS: &[&str] = &["alacritty", "foot", "kitty", "wezterm", "wterm"];
|
||||||
|
|
||||||
#[handler]
|
#[handler]
|
||||||
pub fn handler(selection: Match, state: &State) -> HandleResult {
|
pub fn handler(selection: Match, state: &State) -> HandleResult {
|
||||||
let entry = state
|
let entry = state
|
||||||
@@ -41,8 +45,28 @@ pub fn handler(selection: Match, state: &State) -> HandleResult {
|
|||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
if let Err(why) = Command::new("sh").arg("-c").arg(&entry.exec).spawn() {
|
if entry.term {
|
||||||
println!("Error running desktop entry: {}", why);
|
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
|
HandleResult::Close
|
||||||
|
@@ -8,6 +8,7 @@ pub struct DesktopEntry {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
pub desc: Option<String>,
|
pub desc: Option<String>,
|
||||||
pub icon: String,
|
pub icon: String,
|
||||||
|
pub term: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
const FIELD_CODE_LIST: &[&str] = &[
|
const FIELD_CODE_LIST: &[&str] = &[
|
||||||
@@ -78,6 +79,10 @@ impl DesktopEntry {
|
|||||||
.get("Icon")
|
.get("Icon")
|
||||||
.unwrap_or(&"application-x-executable")
|
.unwrap_or(&"application-x-executable")
|
||||||
.to_string(),
|
.to_string(),
|
||||||
|
term: map
|
||||||
|
.get("Terminal")
|
||||||
|
.map(|val| val.to_lowercase() == "true")
|
||||||
|
.unwrap_or(false),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -119,6 +124,10 @@ impl DesktopEntry {
|
|||||||
},
|
},
|
||||||
desc: Some(entry.name.clone()),
|
desc: Some(entry.name.clone()),
|
||||||
icon: entry.icon.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