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
[dependencies]
freedesktop-desktop-entry = "0.5.0"
freedesktop-icons = "0.2.3"
log = "0.4.19"
once_cell = "1.18.0"
regex = "1.9.1"
freedesktop-desktop-entry = "0.5.2"
freedesktop-icons = "0.2.6"
log = "0.4.21"
once_cell = "1.19.0"
rayon = "1.10.0"
regex = "1.10.4"
rmenu-plugin = { version = "0.0.2", path = "../rmenu-plugin" }
rust-ini = "0.19.0"
serde_json = "1.0.104"
rust-ini = "0.21.0"
serde_json = "1.0.117"
shellexpand = "3.1.0"
thiserror = "1.0.44"
walkdir = "2.3.3"
thiserror = "1.0.61"
walkdir = "2.5.0"

View File

@ -3,6 +3,7 @@ use std::path::PathBuf;
use freedesktop_desktop_entry::{DesktopEntry, Iter};
use once_cell::sync::Lazy;
use rayon::prelude::*;
use regex::Regex;
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,
// otherwise return None
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;
}
@ -133,10 +137,10 @@ fn main() {
})
.collect();
desktops.sort_by_cached_key(|e| e.name.to_owned());
desktops
desktops.par_sort_by_cached_key(|e| e.name.to_owned());
let _: Vec<()> = desktops
.into_iter()
.filter_map(|e| serde_json::to_string(&e).ok())
.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
[dependencies]
rayon = "1.10.0"
rmenu-plugin = { version = "0.0.2", path = "../rmenu-plugin" }
serde_json = "1.0.103"
walkdir = "2.3.3"
serde_json = "1.0.117"
walkdir = "2.5.0"

View File

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