Skip to main content

hyprshell_launcher_lib/
debug.rs

1#![allow(clippy::print_stderr, clippy::print_stdout)]
2
3use crate::plugin::{MatchedLaunchItem, match_launch_item};
4use crate::plugins::get_static_items;
5use crate::reload_applications_desktop_entries_map;
6use config_lib::Plugins;
7use core_lib::WarnWithDetails;
8use core_lib::default::reload_default_files;
9use std::path::Path;
10use tracing::debug;
11
12pub fn get_matches(plugins: &Plugins, text: &str, all_items: bool, max_items: u8, data_dir: &Path) {
13    reload_default_files().warn_details("Failed to reload default files");
14    reload_applications_desktop_entries_map()
15        .warn_details("Failed to reload applications desktop entries map");
16    debug!("text: {text}");
17    let results = get_static_items(plugins, data_dir);
18    let mut results: Vec<MatchedLaunchItem> = results
19        .into_iter()
20        .filter_map(|item| match_launch_item(item, text))
21        .collect();
22    // reverse sorting, so that the most relevant items are at the top
23    results.sort_by_key(|b| std::cmp::Reverse(b.score));
24    println!("{} options returned", results.len());
25    let options = if all_items {
26        results
27    } else {
28        debug!("shorting options to {max_items}");
29        results.into_iter().take(max_items as usize).collect()
30    };
31    for option in options {
32        println!(
33            "{}: {:?}; {} children. bonus: {}, highlight: {:?}",
34            option.item.name,
35            option.score,
36            option.item.children.len(),
37            option.item.bonus_score,
38            option.highlight,
39        );
40        debug!("{option:?}");
41    }
42}