add feature to exclude apps with certain ids

This commit is contained in:
Dorian Rudolph 2020-12-31 18:21:14 +01:00
parent e94b33a309
commit 6e47a8d311
5 changed files with 25 additions and 8 deletions

13
Cargo.lock generated
View File

@ -99,9 +99,9 @@ checksum = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
[[package]]
name = "freedesktop_entry_parser"
version = "1.0.0"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d5fcedb5da81703ad74294fa19b727d2bac8f773f00482e20c297912196c10d"
checksum = "db5c69c16a5ac0988394d994f76d0f8fa0aa21224e33ac5b359379a1f173bed0"
dependencies = [
"nom",
"thiserror",
@ -641,9 +641,9 @@ dependencies = [
[[package]]
name = "regex"
version = "1.3.9"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c3780fcf44b193bc4d09f36d2a3c87b251da4a046c87795a0d35f4f927ad8e6"
checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c"
dependencies = [
"aho-corasick",
"memchr",
@ -653,9 +653,9 @@ dependencies = [
[[package]]
name = "regex-syntax"
version = "0.6.18"
version = "0.6.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26412eb97c6b088a6997e05f69403a802a92d520de2f8e63c2b65f9e0f47c4e8"
checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189"
[[package]]
name = "ryu"
@ -696,6 +696,7 @@ dependencies = [
"libc",
"locale-types",
"pango",
"regex",
"serde",
"serde_derive",
"toml",

View File

@ -5,7 +5,7 @@ authors = ["Dorian Rudolph"]
edition = "2018"
[dependencies]
freedesktop_entry_parser = "1.0.0"
freedesktop_entry_parser = "1.1.0"
locale-types = "0.4.0"
libc = "0.2.74"
gtk-layer-shell = { git = "https://github.com/DorianRudolph/gtk-layer-shell-rs.git" }
@ -21,6 +21,7 @@ xdg = "2.2.0"
serde = "1.0.114"
serde_derive = "1.0.114"
toml = "0.5.6"
regex = "1.4.2"
[profile.release]
lto = true

View File

@ -35,6 +35,12 @@ hide_extra_if_contained = true # hide extra field if it is already contained in
hidden_fields = [] # list of fields considered for search but hidden
exclude = [] # list of regexes for excluded app ids (name of the .desktop file)
# prefix for running commands instead of launching an app (e.g., `:xeyes` to launch xeyes)
# use "" to disable launching commands
command_prefix = ":"
# specify name overrides (id is the name of the desktop file)
[name_overrides]
# id = "name\rextra"hide_extra_if_contained

View File

@ -26,6 +26,7 @@ use gio::{AppInfo, AppInfoExt};
use glib::shell_unquote;
use futures::prelude::*;
use super::{clone, consts::*, Config, Field};
use regex::RegexSet;
pub struct AppEntry {
pub display_string: String,
@ -105,6 +106,7 @@ pub fn load_entries(config: &Config) -> HashMap<ListBoxRow, AppEntry> {
let icon_theme = IconTheme::get_default().unwrap();
let apps = gio::AppInfo::get_all();
let main_context = glib::MainContext::default();
let exclude = RegexSet::new(&config.exclude).expect("Invalid regex");
for app in apps {
let name = match app.get_display_name() {
@ -112,6 +114,12 @@ pub fn load_entries(config: &Config) -> HashMap<ListBoxRow, AppEntry> {
_=> continue
};
if let Some(id) = app.get_id().map(|s| s.to_string()) {
if exclude.is_match(&id) {
continue
}
}
let (display_string, extra_range) = if let Some(name)
= get_app_field(&app, Field::Id).and_then(|id| config.name_overrides.get(&id)) {
let i = name.find('\r');

View File

@ -66,7 +66,8 @@ make_config!(Config {
hidden_fields: Vec<Field> = (Vec::new()) "hidden_fields",
name_overrides: HashMap<String, String> = (HashMap::new()) "name_overrides",
hide_extra_if_contained: bool = (true) "hide_extra_if_contained",
command_prefix: String = (":".into()) "command_prefix"
command_prefix: String = (":".into()) "command_prefix",
exclude: Vec<String> = (Vec::new()) "exclude"
});
fn deserialize_markup<'de, D>(deserializer: D) -> Result<Vec<Attribute>, D::Error>