feat: use rayon for desktop/run plugins

This commit is contained in:
imgurbot12 2024-06-18 22:40:14 -07:00
parent cde679fbfd
commit c8926f5ec4
4 changed files with 27 additions and 20 deletions

View File

@ -6,14 +6,15 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
freedesktop-desktop-entry = "0.5.0" freedesktop-desktop-entry = "0.5.2"
freedesktop-icons = "0.2.3" freedesktop-icons = "0.2.6"
log = "0.4.19" log = "0.4.21"
once_cell = "1.18.0" once_cell = "1.19.0"
regex = "1.9.1" rayon = "1.10.0"
regex = "1.10.4"
rmenu-plugin = { version = "0.0.2", path = "../rmenu-plugin" } rmenu-plugin = { version = "0.0.2", path = "../rmenu-plugin" }
rust-ini = "0.19.0" rust-ini = "0.21.0"
serde_json = "1.0.104" serde_json = "1.0.117"
shellexpand = "3.1.0" shellexpand = "3.1.0"
thiserror = "1.0.44" thiserror = "1.0.61"
walkdir = "2.3.3" walkdir = "2.5.0"

View File

@ -3,6 +3,7 @@ use std::path::PathBuf;
use freedesktop_desktop_entry::{DesktopEntry, Iter}; use freedesktop_desktop_entry::{DesktopEntry, Iter};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use rayon::prelude::*;
use regex::Regex; use regex::Regex;
use rmenu_plugin::{Action, Entry, Method}; use rmenu_plugin::{Action, Entry, Method};
@ -59,7 +60,10 @@ fn parse_desktop(path: &PathBuf, locale: Option<&str>) -> Option<Entry> {
// if an entry only is shown on a specific desktop, check whether desktop is set and matches, // if an entry only is shown on a specific desktop, check whether desktop is set and matches,
// otherwise return None // otherwise return None
let de = std::env::var(XDG_CURRENT_DESKTOP_ENV); let de = std::env::var(XDG_CURRENT_DESKTOP_ENV);
if entry.only_show_in().is_some_and(|e| !(de.is_ok() && de.unwrap() == e.to_string())){ if entry
.only_show_in()
.is_some_and(|e| !(de.is_ok() && de.unwrap() == e.to_string()))
{
return None; return None;
} }
@ -133,10 +137,10 @@ fn main() {
}) })
.collect(); .collect();
desktops.sort_by_cached_key(|e| e.name.to_owned()); desktops.par_sort_by_cached_key(|e| e.name.to_owned());
desktops let _: Vec<()> = desktops
.into_iter() .into_iter()
.filter_map(|e| serde_json::to_string(&e).ok()) .filter_map(|e| serde_json::to_string(&e).ok())
.map(|s| println!("{}", s)) .map(|s| println!("{}", s))
.last(); .collect();
} }

View File

@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
rayon = "1.10.0"
rmenu-plugin = { version = "0.0.2", path = "../rmenu-plugin" } rmenu-plugin = { version = "0.0.2", path = "../rmenu-plugin" }
serde_json = "1.0.103" serde_json = "1.0.117"
walkdir = "2.3.3" walkdir = "2.5.0"

View File

@ -1,6 +1,7 @@
use std::env; use std::env;
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
use rayon::prelude::*;
use rmenu_plugin::Entry; use rmenu_plugin::Entry;
use walkdir::{DirEntry, WalkDir}; use walkdir::{DirEntry, WalkDir};
@ -49,16 +50,16 @@ fn find_binaries(path: String) -> Vec<Entry> {
fn main() { fn main() {
// collect entries for sorting // collect entries for sorting
let mut entries: Vec<Entry> = bin_paths() let mut entries: Vec<Entry> = bin_paths()
.into_iter() .into_par_iter()
.map(find_binaries) .map(find_binaries)
.flatten() .flatten()
.collect(); .collect();
// sort entries and render to json // sort entries and render to json
entries.sort_by_cached_key(|e| e.name.clone()); entries.par_sort_by_cached_key(|e| e.name.clone());
entries let _: Vec<()> = entries
.into_iter() .into_par_iter()
.map(|e| serde_json::to_string(&e)) .map(|e| serde_json::to_string(&e))
.filter_map(|r| r.ok()) .filter_map(|r| r.ok())
.map(|s| println!("{}", s)) .map(|s| println!("{}", s))
.last(); .collect();
} }