diff --git a/plugins/src/pop_shell/config.rs b/plugins/src/pop_shell/config.rs new file mode 100644 index 0000000..337ff81 --- /dev/null +++ b/plugins/src/pop_shell/config.rs @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-3.0-only +// Copyright © 2021 System76 + +use serde::Deserialize; + +pub fn bool_true() -> bool { + true +} + +#[derive(Debug, Deserialize, Clone)] +pub struct SearchScope { + #[serde(default = "bool_true")] + pub name: bool, + + #[serde(default = "bool_true")] + pub description: bool, +} + +impl Default for SearchScope { + fn default() -> SearchScope { + SearchScope { + name: true, + description: true, + } + } +} + +#[derive(Debug, Default, Deserialize, Clone)] +pub struct Config { + #[serde(default)] + pub search: SearchScope, +} + +pub fn load() -> Config { + let mut config = Config::default(); + + for path in pop_launcher::config::find("pop_shell") { + let string = match std::fs::read_to_string(&path) { + Ok(string) => string, + Err(why) => { + tracing::error!("failed to read config: {}", why); + continue; + } + }; + + match ron::from_str::(&string) { + Ok(raw) => config.search = raw.search, + Err(why) => { + tracing::error!("failed to deserialize config: {}", why); + } + } + } + + config +} diff --git a/plugins/src/pop_shell/mod.rs b/plugins/src/pop_shell/mod.rs index cdc5546..6470bc7 100644 --- a/plugins/src/pop_shell/mod.rs +++ b/plugins/src/pop_shell/mod.rs @@ -11,6 +11,9 @@ use tokio::io::{AsyncWrite, AsyncWriteExt}; use zbus::Connection; use zvariant::{Signature, Type}; +mod config; +pub use config::{load, Config}; + const DEST: &str = "com.System76.PopShell"; const PATH: &str = "/com/System76/PopShell"; @@ -59,6 +62,7 @@ pub async fn main() { } struct App { + config: Config, desktop_entries: Vec<(fde::PathSource, PathBuf)>, entries: Vec, connection: Connection, @@ -68,6 +72,7 @@ struct App { impl App { fn new(connection: Connection, tx: W) -> Self { Self { + config: config::load(), desktop_entries: fde::Iter::new(fde::default_paths()) .map(|path| (fde::PathSource::guess_from(&path), path)) .collect(), @@ -119,8 +124,9 @@ impl App { } for (id, item) in self.entries.iter().enumerate() { - let retain = contains_pattern(&item.name, &haystack) - || contains_pattern(&item.description, &haystack); + let retain = (self.config.search.name && contains_pattern(&item.name, &haystack)) + || (self.config.search.description + && contains_pattern(&item.description, &haystack)); if !retain { continue;