Skip to content

Commit

Permalink
Support launching app in terminal
Browse files Browse the repository at this point in the history
- Get terminal setting from desktop file
- Launch app in terminal if set
  • Loading branch information
jpttrssn committed Nov 25, 2024
1 parent a9c7c3c commit dc62ac4
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub struct DesktopEntryData {
pub desktop_actions: Vec<DesktopAction>,
pub mime_types: Vec<Mime>,
pub prefers_dgpu: bool,
pub terminal: bool,
}

pub fn load_applications<'a>(
Expand Down Expand Up @@ -225,12 +226,17 @@ impl DesktopEntryData {
})
.unwrap_or_default(),
prefers_dgpu: de.prefers_non_default_gpu(),
terminal: de.terminal(),
}
}
}

pub async fn spawn_desktop_exec<S, I, K, V>(exec: S, env_vars: I, app_id: Option<&str>)
where
pub async fn spawn_desktop_exec<S, I, K, V>(
exec: S,
env_vars: I,
app_id: Option<&str>,
terminal: bool,
) where
S: AsRef<str>,
I: IntoIterator<Item = (K, V)>,
K: AsRef<OsStr>,
Expand All @@ -243,14 +249,23 @@ where
_ => return,
};

let mut cmd = std::process::Command::new(&executable);

for arg in exec {
// TODO handle "%" args here if necessary?
if !arg.starts_with('%') {
cmd.arg(arg);
let mut cmd = match terminal {
true => {
let mut cmd = std::process::Command::new("cosmic-term");
cmd.args(vec!["--", format!("{}", &executable).as_str()]);
cmd
}
}
false => {
let mut cmd = std::process::Command::new(&executable);
for arg in exec {
// TODO handle "%" args here if necessary?
if !arg.starts_with('%') {
cmd.arg(arg);
}
}
cmd
}
};

cmd.envs(env_vars);

Expand Down

0 comments on commit dc62ac4

Please sign in to comment.