fix!(desktop): support launching terminal-based desktop entries
This commit is contained in:
parent
f835afa59c
commit
8edbbec1e8
2 changed files with 29 additions and 3 deletions
|
|
@ -40,6 +40,7 @@ rfd = ["dep:rfd"]
|
||||||
# Enables desktop files helpers
|
# Enables desktop files helpers
|
||||||
desktop = [
|
desktop = [
|
||||||
"process",
|
"process",
|
||||||
|
"dep:cosmic-settings-config",
|
||||||
"dep:freedesktop-desktop-entry",
|
"dep:freedesktop-desktop-entry",
|
||||||
"dep:mime",
|
"dep:mime",
|
||||||
"dep:shlex",
|
"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 }
|
cctk = { git = "https://github.com/pop-os/cosmic-protocols", package = "cosmic-client-toolkit", rev = "178eb0b", optional = true }
|
||||||
chrono = "0.4.40"
|
chrono = "0.4.40"
|
||||||
cosmic-config = { path = "cosmic-config" }
|
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 }
|
cosmic-settings-daemon = { git = "https://github.com/pop-os/dbus-settings-bindings", optional = true }
|
||||||
css-color = "0.2.8"
|
css-color = "0.2.8"
|
||||||
derive_setters = "0.1.6"
|
derive_setters = "0.1.6"
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ pub struct DesktopEntryData {
|
||||||
pub desktop_actions: Vec<DesktopAction>,
|
pub desktop_actions: Vec<DesktopAction>,
|
||||||
pub mime_types: Vec<Mime>,
|
pub mime_types: Vec<Mime>,
|
||||||
pub prefers_dgpu: bool,
|
pub prefers_dgpu: bool,
|
||||||
|
pub terminal: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
|
|
@ -196,6 +197,7 @@ impl DesktopEntryData {
|
||||||
})
|
})
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
prefers_dgpu: de.prefers_non_default_gpu(),
|
prefers_dgpu: de.prefers_non_default_gpu(),
|
||||||
|
terminal: de.terminal(),
|
||||||
path: Some(de.path),
|
path: Some(de.path),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -203,14 +205,36 @@ impl DesktopEntryData {
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
#[cold]
|
#[cold]
|
||||||
pub async fn spawn_desktop_exec<S, I, K, V>(exec: S, env_vars: I, app_id: Option<&str>)
|
pub async fn spawn_desktop_exec<S, I, K, V>(
|
||||||
where
|
exec: S,
|
||||||
|
env_vars: I,
|
||||||
|
app_id: Option<&str>,
|
||||||
|
terminal: bool,
|
||||||
|
) where
|
||||||
S: AsRef<str>,
|
S: AsRef<str>,
|
||||||
I: IntoIterator<Item = (K, V)>,
|
I: IntoIterator<Item = (K, V)>,
|
||||||
K: AsRef<OsStr>,
|
K: AsRef<OsStr>,
|
||||||
V: 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() {
|
let executable = match exec.next() {
|
||||||
Some(executable) if !executable.contains('=') => executable,
|
Some(executable) if !executable.contains('=') => executable,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue