feat(pop_shell): add config with window name/description search scope settings (#159)
This commit is contained in:
parent
930c50c95f
commit
92766af95f
2 changed files with 63 additions and 2 deletions
55
plugins/src/pop_shell/config.rs
Normal file
55
plugins/src/pop_shell/config.rs
Normal file
|
|
@ -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::<Config>(&string) {
|
||||
Ok(raw) => config.search = raw.search,
|
||||
Err(why) => {
|
||||
tracing::error!("failed to deserialize config: {}", why);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
config
|
||||
}
|
||||
|
|
@ -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<W> {
|
||||
config: Config,
|
||||
desktop_entries: Vec<(fde::PathSource, PathBuf)>,
|
||||
entries: Vec<Item>,
|
||||
connection: Connection,
|
||||
|
|
@ -68,6 +72,7 @@ struct App<W> {
|
|||
impl<W: AsyncWrite + Unpin> App<W> {
|
||||
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<W: AsyncWrite + Unpin> App<W> {
|
|||
}
|
||||
|
||||
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue