Terminal app execution
This commit is contained in:
parent
42907b8982
commit
0f4117b436
1 changed files with 23 additions and 8 deletions
|
@ -1,4 +1,4 @@
|
|||
use std::{os::unix::prelude::CommandExt, process::{Child, Command, Stdio}};
|
||||
use std::{os::unix::prelude::CommandExt, process::{Command, Stdio}};
|
||||
|
||||
use freedesktop_entry_parser as parser;
|
||||
use log::{debug, error};
|
||||
|
@ -11,6 +11,7 @@ use crate::roftl::{Action, Entry, Source};
|
|||
struct App {
|
||||
name: String,
|
||||
command: String,
|
||||
terminal: bool
|
||||
}
|
||||
|
||||
fn with_term<'a>(term_cmd: &'a Option<String>, exec: &'a str,) {
|
||||
|
@ -25,10 +26,10 @@ fn with_term<'a>(term_cmd: &'a Option<String>, exec: &'a str,) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn parse_command_string<'a>(exec: &'a str) -> (String, Vec<&'a str>) {
|
||||
pub fn parse_command_string<'a>(exec: &'a str) -> (String, Vec<String>) {
|
||||
let mut iter = exec.split(' ');
|
||||
let cmd = iter.next().expect("Empty Exec").to_owned();
|
||||
let args = iter.collect();
|
||||
let args = iter.map(|arg| arg.to_owned()).collect();
|
||||
(cmd, args)
|
||||
}
|
||||
|
||||
|
@ -49,14 +50,25 @@ pub fn run_bg(mut command: Command) {
|
|||
}
|
||||
|
||||
impl App {
|
||||
pub fn run(&self, term_cmd: &Option<String>) {
|
||||
pub fn run(&self) {
|
||||
debug!("Exec: `{}`", self.command);
|
||||
let(cmd, args) = parse_command_string(&self.command);
|
||||
let (cmd, mut args) = parse_command_string(&self.command);
|
||||
|
||||
if self.terminal {
|
||||
debug!("Running `{} {}` in terminal ", cmd, args.join(" "));
|
||||
let mut command = Command::new("xfce4-terminal");
|
||||
args.insert(0, cmd);
|
||||
args.insert(0, "-x".into());
|
||||
command.args(&args);
|
||||
let _ = run_bg(command);
|
||||
} else {
|
||||
|
||||
debug!("Running `{} {}`", cmd, args.join(" "));
|
||||
let mut command = Command::new(&cmd);
|
||||
command.args(&args);
|
||||
let _ = run_bg(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&App> for Entry
|
||||
|
@ -77,7 +89,8 @@ impl From<&App> for Entry
|
|||
struct AppBuilder<'a> {
|
||||
name: Option<&'a str>,
|
||||
exec: Option<&'a str>,
|
||||
hidden: Option<&'a str>
|
||||
hidden: Option<&'a str>,
|
||||
terminal: Option<&'a str>
|
||||
}
|
||||
|
||||
impl<'a> AppBuilder<'a>
|
||||
|
@ -92,6 +105,7 @@ impl<'a> AppBuilder<'a>
|
|||
App {
|
||||
name: self.name.unwrap().into(),
|
||||
command: strip_entry_args(self.exec.unwrap()).into(),
|
||||
terminal: self.terminal.map_or(false, |term| term.parse().unwrap_or(false))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +140,7 @@ impl Source for Apps {
|
|||
fn entries(&mut self) -> Vec<Entry> {
|
||||
let paths = vec![
|
||||
"/usr/share/applications/",
|
||||
"~/.local/share/applications/",
|
||||
"/home/armin/.local/share/applications/",
|
||||
"/var/lib/snapd/desktop/applications",
|
||||
"/var/lib/flatpak/exports/share/applications"
|
||||
];
|
||||
|
@ -153,6 +167,7 @@ impl Source for Apps {
|
|||
"Exec" => app_builder.exec = attr.value,
|
||||
"NoDisplay" => app_builder.hidden = attr.value,
|
||||
"Hidden" => app_builder.hidden = attr.value,
|
||||
"Terminal" => app_builder.terminal = attr.value,
|
||||
_ => ()
|
||||
}
|
||||
}
|
||||
|
@ -179,6 +194,6 @@ impl Source for Apps {
|
|||
debug!{"Apps has entries {:?}", self.entries}
|
||||
let app = self.entries.get(entry.identifier as usize).unwrap();
|
||||
debug!{"Doing primary action {} for {}", app.name, app.command}
|
||||
app.run(&Some("/bin/bash".into()));
|
||||
app.run();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue