From 437763f51f4584863918b171c9f4204d10905f46 Mon Sep 17 00:00:00 2001 From: Alexander Mohr Date: Sat, 19 Apr 2025 19:52:01 +0200 Subject: [PATCH] filter drun menu better and make some commands actually run --- Cargo.lock | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + README.md | 8 +++++--- src/lib/mode.rs | 32 +++++++++++++++++++---------- src/main.rs | 2 +- 5 files changed, 82 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8cef9e4..ba645a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -391,6 +391,12 @@ dependencies = [ "regex", ] +[[package]] +name = "env_home" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f84e12ccf0a7ddc17a6c41c93326024c42920d7ee630d04950e6926645c0fe" + [[package]] name = "env_logger" version = "0.11.8" @@ -410,6 +416,16 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" +[[package]] +name = "errno" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + [[package]] name = "field-offset" version = "0.3.6" @@ -970,6 +986,12 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +[[package]] +name = "linux-raw-sys" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" + [[package]] name = "log" version = "0.4.27" @@ -1259,6 +1281,19 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d97817398dd4bb2e6da002002db259209759911da105da92bec29ccb12cf58bf" +dependencies = [ + "bitflags 2.9.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.59.0", +] + [[package]] name = "ryu" version = "1.0.20" @@ -1534,6 +1569,18 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "which" +version = "7.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d643ce3fd3e5b54854602a080f34fb10ab75e0b813ee32d00ca2b44fa74762" +dependencies = [ + "either", + "env_home", + "rustix", + "winsafe", +] + [[package]] name = "winapi" version = "0.3.9" @@ -1656,6 +1703,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "winsafe" +version = "0.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904" + [[package]] name = "worf" version = "0.1.0" @@ -1679,6 +1732,7 @@ dependencies = [ "strsim 0.11.1", "thiserror", "toml", + "which", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 87f2c10..15ebdf3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,3 +41,4 @@ libc = "0.2.171" freedesktop-file-parser = "0.1.3" strsim = "0.11.1" dirs = "6.0.0" +which = "7.0.3" diff --git a/README.md b/README.md index df84cbf..e465362 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,12 @@ layerrule = blur, worf because worf is build on GTK4 instead of GTK3 there will be differences in the look and feel. * Configuration files are not 100% compatible, Worf is using toml files instead, for most part this only means strings have to be quoted * Color files are not supported -* `mode` dropped, use show -* `D` argument dropped. Arguments are the same as config in worf, no need to have have this flag. -## Dropped configuration options +## Dropped arguments +* `mode`, use show +* `D`, arguments are the same as config in worf, no need to have have this flag. + +### Dropped configuration options * stylesheet -> use style instead * color / colors -> GTK4 does not support color files diff --git a/src/lib/mode.rs b/src/lib/mode.rs index 798f50e..fadab7a 100644 --- a/src/lib/mode.rs +++ b/src/lib/mode.rs @@ -42,17 +42,30 @@ pub fn d_run(config: &Config) -> anyhow::Result<()> { f.entry.hidden.is_none_or(|hidden| !hidden) && f.entry.no_display.is_none_or(|no_display| !no_display) }) { - let (action, working_dir) = match &file.entry.entry_type { - EntryType::Application(app) => (app.exec.clone(), app.path.clone()), - _ => (None, None), - }; - let Some(name) = lookup_name_with_locale( &locale_variants, &file.entry.name.variants, &file.entry.name.default, ) else { - log::debug!("Skipping desktop entry without name {file:?}"); + log::warn!("Skipping desktop entry without name {file:?}"); + continue; + }; + + let (action, working_dir) = match &file.entry.entry_type { + EntryType::Application(app) => (app.exec.clone(), app.path.clone()), + _ => (None, None), + }; + + let cmd_exists = action.as_ref().map(|a| { + a.split(' ') + .next() + .map(|cmd| cmd.replace("\"", "")) + .map(|cmd| { + PathBuf::from(&cmd).exists() || which::which(&cmd).is_ok() + })}).flatten().unwrap_or(false); + + if !cmd_exists { + log::warn!("Skipping desktop entry for {name:?} because action {action:?} does not exist"); continue; }; @@ -174,11 +187,8 @@ fn create_file_if_not_exists(path: &PathBuf) -> anyhow::Result<()> { } fn spawn_fork(cmd: &str, working_dir: Option<&String>) -> anyhow::Result<()> { - // todo probably remove arguments? - // todo support working dir - // todo fix actions + // todo fix actions ?? // todo graphical disk map icon not working - // Unix-like systems (Linux, macOS) let parts = cmd.split(' ').collect::>(); if parts.is_empty() { @@ -189,7 +199,7 @@ fn spawn_fork(cmd: &str, working_dir: Option<&String>) -> anyhow::Result<()> { env::set_current_dir(dir)?; } - let exec = parts[0]; + let exec = parts[0].replace("\"", ""); let args: Vec<_> = parts .iter() .skip(1) diff --git a/src/main.rs b/src/main.rs index 418f3f0..8be9da2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ fn main() -> anyhow::Result<()> { env_logger::Builder::new() // todo change to error as default - .parse_filters(&env::var("RUST_LOG").unwrap_or_else(|_| "debug".to_owned())) + .parse_filters(&env::var("RUST_LOG").unwrap_or_else(|_| "error".to_owned())) .init(); let args = config::parse_args();