Skip to content

Commit 92766af

Browse files
authored
feat(pop_shell): add config with window name/description search scope settings (#159)
1 parent 930c50c commit 92766af

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

plugins/src/pop_shell/config.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// SPDX-License-Identifier: GPL-3.0-only
2+
// Copyright © 2021 System76
3+
4+
use serde::Deserialize;
5+
6+
pub fn bool_true() -> bool {
7+
true
8+
}
9+
10+
#[derive(Debug, Deserialize, Clone)]
11+
pub struct SearchScope {
12+
#[serde(default = "bool_true")]
13+
pub name: bool,
14+
15+
#[serde(default = "bool_true")]
16+
pub description: bool,
17+
}
18+
19+
impl Default for SearchScope {
20+
fn default() -> SearchScope {
21+
SearchScope {
22+
name: true,
23+
description: true,
24+
}
25+
}
26+
}
27+
28+
#[derive(Debug, Default, Deserialize, Clone)]
29+
pub struct Config {
30+
#[serde(default)]
31+
pub search: SearchScope,
32+
}
33+
34+
pub fn load() -> Config {
35+
let mut config = Config::default();
36+
37+
for path in pop_launcher::config::find("pop_shell") {
38+
let string = match std::fs::read_to_string(&path) {
39+
Ok(string) => string,
40+
Err(why) => {
41+
tracing::error!("failed to read config: {}", why);
42+
continue;
43+
}
44+
};
45+
46+
match ron::from_str::<Config>(&string) {
47+
Ok(raw) => config.search = raw.search,
48+
Err(why) => {
49+
tracing::error!("failed to deserialize config: {}", why);
50+
}
51+
}
52+
}
53+
54+
config
55+
}

plugins/src/pop_shell/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ use tokio::io::{AsyncWrite, AsyncWriteExt};
1111
use zbus::Connection;
1212
use zvariant::{Signature, Type};
1313

14+
mod config;
15+
pub use config::{load, Config};
16+
1417
const DEST: &str = "com.System76.PopShell";
1518
const PATH: &str = "/com/System76/PopShell";
1619

@@ -59,6 +62,7 @@ pub async fn main() {
5962
}
6063

6164
struct App<W> {
65+
config: Config,
6266
desktop_entries: Vec<(fde::PathSource, PathBuf)>,
6367
entries: Vec<Item>,
6468
connection: Connection,
@@ -68,6 +72,7 @@ struct App<W> {
6872
impl<W: AsyncWrite + Unpin> App<W> {
6973
fn new(connection: Connection, tx: W) -> Self {
7074
Self {
75+
config: config::load(),
7176
desktop_entries: fde::Iter::new(fde::default_paths())
7277
.map(|path| (fde::PathSource::guess_from(&path), path))
7378
.collect(),
@@ -119,8 +124,9 @@ impl<W: AsyncWrite + Unpin> App<W> {
119124
}
120125

121126
for (id, item) in self.entries.iter().enumerate() {
122-
let retain = contains_pattern(&item.name, &haystack)
123-
|| contains_pattern(&item.description, &haystack);
127+
let retain = (self.config.search.name && contains_pattern(&item.name, &haystack))
128+
|| (self.config.search.description
129+
&& contains_pattern(&item.description, &haystack));
124130

125131
if !retain {
126132
continue;

0 commit comments

Comments
 (0)