diff --git a/Cargo.toml b/Cargo.toml index e9934e45..a90b0e73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/desktop.rs b/src/desktop.rs index c9c4c491..34673f91 100644 --- a/src/desktop.rs +++ b/src/desktop.rs @@ -47,6 +47,7 @@ pub struct DesktopEntryData { pub desktop_actions: Vec, pub mime_types: Vec, 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(exec: S, env_vars: I, app_id: Option<&str>) -where +pub async fn spawn_desktop_exec( + exec: S, + env_vars: I, + app_id: Option<&str>, + terminal: bool, +) where S: AsRef, I: IntoIterator, K: AsRef, V: AsRef, { - 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,