Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ desktop = [
"dep:freedesktop-desktop-entry",
"dep:mime",
"dep:shlex",
"dep:xdg",
"tokio?/io-util",
"tokio?/net",
]
Expand Down Expand Up @@ -95,6 +96,7 @@ cosmic-config = { path = "cosmic-config" }
cosmic-settings-daemon = { git = "https://github.com/pop-os/dbus-settings-bindings", optional = true }
css-color = "0.2.5"
derive_setters = "0.1.5"
icu_collator = "1.5"
image = { version = "0.25.5", default-features = false, features = [
"jpeg",
"png",
Expand All @@ -103,6 +105,8 @@ lazy_static = "1.4.0"
libc = { version = "0.2.155", optional = true }
license = { version = "3.5.1", optional = true }
mime = { version = "0.3.17", optional = true }
mime_guess = "2"
once_cell = "1.19"
palette = "0.7.3"
rfd = { version = "0.14.0", default-features = false, features = ["xdg-portal"], optional = true }
rustix = { version = "0.38.34", features = [
Expand All @@ -117,11 +121,13 @@ tokio = { version = "1.24.2", optional = true }
tracing = "0.1.41"
unicode-segmentation = "1.6"
url = "2.4.0"
xdg = { version = "2.5.2", optional = true }
zbus = { version = "4.2.1", default-features = false, optional = true }

[target.'cfg(unix)'.dependencies]
freedesktop-icons = { package = "cosmic-freedesktop-icons", git = "https://github.com/pop-os/freedesktop-icons" }
freedesktop-desktop-entry = { version = "0.5.1", optional = true }
freedesktop_entry_parser = "1.3"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parsing of desktop entries is already provided by freedesktop-desktop-entry in the line above.

shlex = { version = "1.3.0", optional = true }

[dependencies.cosmic-theme]
Expand Down
25 changes: 16 additions & 9 deletions src/desktop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use std::path::{Path, PathBuf};
#[cfg(not(windows))]
use std::{borrow::Cow, ffi::OsStr};

use crate::mime_app::{exec_term_to_command, exec_to_command};

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum IconSource {
Name(String),
Expand Down Expand Up @@ -62,6 +64,7 @@ pub struct DesktopEntryData {
pub desktop_actions: Vec<DesktopAction>,
pub mime_types: Vec<Mime>,
pub prefers_dgpu: bool,
pub terminal: bool,
}

#[cfg(not(windows))]
Expand Down Expand Up @@ -233,13 +236,18 @@ impl DesktopEntryData {
})
.unwrap_or_default(),
prefers_dgpu: de.prefers_non_default_gpu(),
terminal: de.terminal(),
}
}
}

#[cfg(not(windows))]
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 @@ -252,14 +260,13 @@ where
_ => return,
};

let mut cmd = std::process::Command::new(&executable);
let cmd = if terminal {
exec_term_to_command(&executable, None)
} else {
exec_to_command(&executable, None)
};

for arg in exec {
// TODO handle "%" args here if necessary?
if !arg.starts_with('%') {
cmd.arg(arg);
}
}
let Some(mut cmd) = cmd else { return };

cmd.envs(env_vars);

Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ pub mod keyboard_nav;

#[cfg(feature = "desktop")]
pub mod desktop;

#[cfg(feature = "desktop")]
pub mod mime_app;

#[cfg(all(feature = "process", not(windows)))]
pub mod process;

Expand Down
Loading