Skip to content

Commit

Permalink
Copy mime_app from cosmic-files
Browse files Browse the repository at this point in the history
- Add optional language sorter parameter to MimeAppCache::reload()
- Use mime_app::exec_term_command in desktop::spawn_desktop_exec()
- Add function mime_app::exec_term_to_command() to get exec command using terminal with fallback
  - Use this in MimeApp::command()
  - Use this in desktop::spawn_desktop_exec()
  • Loading branch information
jpttrssn committed Nov 25, 2024
1 parent 1e58854 commit b450653
Show file tree
Hide file tree
Showing 5 changed files with 364 additions and 13 deletions.
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,11 +96,14 @@ 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.1", optional = true }
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", optional = true }
rustix = { version = "0.38.34", features = [
Expand All @@ -115,11 +119,13 @@ tracing = "0.1"
unicode-segmentation = "1.6"
url = "2.4.0"
ustr = { version = "1.0.0", features = ["serde"] }
xdg = { version = "2.5.2", optional = true }
zbus = { version = "4.2.1", default-features = false, optional = true }

[target.'cfg(unix)'.dependencies]
freedesktop-icons = "0.2.5"
freedesktop-desktop-entry = { version = "0.5.1", optional = true }
freedesktop_entry_parser = "1.3"
shlex = { version = "1.3.0", optional = true }

[dependencies.cosmic-theme]
Expand Down
2 changes: 1 addition & 1 deletion iced
19 changes: 7 additions & 12 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},
};

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 @@ -249,21 +251,14 @@ pub async fn spawn_desktop_exec<S, I, K, V>(
_ => return,
};

let mut cmd = if terminal {
let mut cmd = std::process::Command::new("cosmic-term");
cmd.args(vec!["--", format!("{}", &executable).as_str()]);
cmd
let cmd = if terminal {
exec_term_to_command(&executable, None)
} else {
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
exec_to_command(&executable, None)
};

let Some(mut cmd) = cmd else { return };

cmd.envs(env_vars);

// https://systemd.io/DESKTOP_ENVIRONMENTS
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ pub mod keyboard_nav;

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

pub mod mime_app;

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

Expand Down
Loading

0 comments on commit b450653

Please sign in to comment.