Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support launching app in terminal #718

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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,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
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},
};

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 @@ -60,6 +62,7 @@ pub struct DesktopEntryData {
pub desktop_actions: Vec<DesktopAction>,
pub mime_types: Vec<Mime>,
pub prefers_dgpu: bool,
pub terminal: bool,
}

pub fn load_applications<'a>(
Expand Down Expand Up @@ -225,12 +228,17 @@ impl DesktopEntryData {
})
.unwrap_or_default(),
prefers_dgpu: de.prefers_non_default_gpu(),
terminal: de.terminal(),
}
}
}

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 @@ -243,14 +251,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
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