fix!(desktop): support launching terminal-based desktop entries

This commit is contained in:
Michael Aaron Murphy 2025-06-11 09:25:21 +02:00
parent f835afa59c
commit 8edbbec1e8
No known key found for this signature in database
GPG key ID: B2732D4240C9212C
2 changed files with 29 additions and 3 deletions

View file

@ -40,6 +40,7 @@ rfd = ["dep:rfd"]
# Enables desktop files helpers
desktop = [
"process",
"dep:cosmic-settings-config",
"dep:freedesktop-desktop-entry",
"dep:mime",
"dep:shlex",
@ -105,6 +106,7 @@ auto_enums = "0.8.7"
cctk = { git = "https://github.com/pop-os/cosmic-protocols", package = "cosmic-client-toolkit", rev = "178eb0b", optional = true }
chrono = "0.4.40"
cosmic-config = { path = "cosmic-config" }
cosmic-settings-config = { git = "https://github.com/pop-os/cosmic-settings-daemon", optional = true }
cosmic-settings-daemon = { git = "https://github.com/pop-os/dbus-settings-bindings", optional = true }
css-color = "0.2.8"
derive_setters = "0.1.6"

View file

@ -47,6 +47,7 @@ pub struct DesktopEntryData {
pub desktop_actions: Vec<DesktopAction>,
pub mime_types: Vec<Mime>,
pub prefers_dgpu: bool,
pub terminal: bool,
}
#[cfg(not(windows))]
@ -196,6 +197,7 @@ impl DesktopEntryData {
})
.unwrap_or_default(),
prefers_dgpu: de.prefers_non_default_gpu(),
terminal: de.terminal(),
path: Some(de.path),
}
}
@ -203,14 +205,36 @@ impl DesktopEntryData {
#[cfg(not(windows))]
#[cold]
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>,
V: AsRef<OsStr>,
{
let mut exec = shlex::Shlex::new(exec.as_ref());
let term_exec;
let exec_str = if terminal {
let term = cosmic_settings_config::shortcuts::context()
.ok()
.and_then(|config| {
cosmic_settings_config::shortcuts::system_actions(&config)
.get(&cosmic_settings_config::shortcuts::action::System::Terminal)
.cloned()
})
.unwrap_or_else(|| String::from("cosmic-term"));
term_exec = format!("{term} -- {}", exec.as_ref());
&term_exec
} else {
exec.as_ref()
};
let mut exec = shlex::Shlex::new(exec_str);
let executable = match exec.next() {
Some(executable) if !executable.contains('=') => executable,