Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ pub enum SetConfigFields {
SetPage(MainPage),
SetEventDuration(String),
SetShowOnStartup(bool),
Blacklist(Editable<String>),
Modes(Editable<(String, String)>),
Aliases(Editable<(String, String)>),
SearchDirs(Editable<String>),
Expand Down
53 changes: 53 additions & 0 deletions src/app/pages/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,8 @@ fn commands_tab(
modes_item(config.modes.clone(), &theme),
section_header_with_reset("Search Directories", ResetField::SearchDirs, theme.clone()),
search_dirs_item(&theme, config.search_dirs.clone()),
section_header_with_reset("Blacklist", ResetField::SearchDirs, theme.clone()),
blacklist_item(&theme, config.blacklist.clone()),
Space::new().height(10).into(),
section_header_with_reset("Shell commands", ResetField::ShellCommands, theme.clone()),
shell_commands_item(config.shells.clone(), theme.clone(), hotkey_capture),
Expand Down Expand Up @@ -1116,6 +1118,57 @@ fn search_dirs_item(theme: &Theme, search_dirs: Vec<String>) -> Element<'static,
.into()
}

fn blacklist_item(theme: &Theme, blacklist: Vec<String>) -> Element<'static, Message> {
Column::from_iter([
container(
Column::from_iter(blacklist.iter().map(|item| {
let theme_clone_2 = theme.clone();
let blacklist_item = item.clone();
let blacklist_item_clone = blacklist_item.clone();
container(
Row::from_iter([
text_input_cell(blacklist_item.clone(), &theme_clone_2, "App name")
.on_input(move |input| {
Message::SetConfig(SetConfigFields::Blacklist(Editable::Update {
old: blacklist_item_clone.clone(),
new: input,
}))
})
.into(),
Button::new("Delete")
.on_press(Message::SetConfig(SetConfigFields::Blacklist(
Editable::Delete(blacklist_item.clone()),
)))
.style(move |_, _| delete_button_style(&theme_clone_2))
.into(),
])
.spacing(10)
.align_y(Alignment::Center),
)
.width(Length::Fill)
.align_x(Alignment::Center)
.into()
}))
.spacing(10),
)
.height(Length::Fill)
.width(Length::Fill)
.align_x(Alignment::Center)
.align_y(Alignment::Center)
.into(),
dir_adder_button("+", theme.to_owned())
.on_press(Message::SetConfig(SetConfigFields::Blacklist(
Editable::Create("".to_string()),
)))
.into(),
])
.spacing(10)
.height(Length::Fill)
.width(Length::Fill)
.align_x(Alignment::Center)
.into()
}

fn text_input_cell(text: String, theme: &Theme, placeholder: &str) -> TextInput<'static, Message> {
text_input(placeholder, &text)
.font(theme.font())
Expand Down
20 changes: 15 additions & 5 deletions src/app/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use url::Url;
use std::cell::RefCell;
use std::collections::HashMap;
use std::fmt::Debug;
use std::sync::Arc;
use std::time::Duration;

/// This is a wrapper around the sender to disable dropping
Expand All @@ -58,8 +59,13 @@ struct AppIndex {

impl AppIndex {
/// Search for an element in the index that starts with the provided prefix
fn search_prefix<'a>(&'a self, prefix: &'a str) -> impl ParallelIterator<Item = &'a App> + 'a {
fn search_prefix<'a>(
&'a self,
prefix: &'a str,
blacklist: Vec<String>,
) -> impl ParallelIterator<Item = &'a App> + 'a {
let pattern = Pattern::parse(prefix, CaseMatching::Ignore, Normalization::Smart);
let blacklist_rc = Arc::new(blacklist);

self.by_name.par_iter().filter_map(move |(name, app)| {
thread_local! {
Expand All @@ -68,6 +74,10 @@ impl AppIndex {
);
}

if blacklist_rc.contains(&name.to_lowercase()) {
return None;
}

MATCHER.with(|m| {
let mut buf = Vec::new();
let haystack = Utf32Str::new(name, &mut buf);
Expand Down Expand Up @@ -405,7 +415,7 @@ impl Tile {
&AppIndex::empty()
};
let results: Vec<App> = options
.search_prefix(&query)
.search_prefix(&query, self.config.blacklist.clone())
.map(|x| x.to_owned())
.collect();

Expand Down Expand Up @@ -704,15 +714,15 @@ mod tests {
]);

let prefix_results: Vec<_> = index
.search_prefix("sa")
.search_prefix("sa", Vec::new())
.map(|app| app.display_name.clone())
.collect();
let spaced_results: Vec<_> = index
.search_prefix("studio")
.search_prefix("studio", Vec::new())
.map(|app| app.display_name.clone())
.collect();
let hyphen_results: Vec<_> = index
.search_prefix("desktop")
.search_prefix("desktop", Vec::new())
.map(|app| app.display_name.clone())
.collect();

Expand Down
2 changes: 1 addition & 1 deletion src/app/tile/elm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub fn view(tile: &Tile, wid: window::Id) -> Element<'_, Message> {
Page::EmojiSearch => emoji_page(
tile.config.theme.clone(),
tile.emoji_apps
.search_prefix(&tile.query_lc)
.search_prefix(&tile.query_lc, Vec::new())
.map(|x| x.to_owned())
.collect(),
tile.focus_id,
Expand Down
38 changes: 35 additions & 3 deletions src/app/tile/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,10 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
for _ in 0..amount {
let len = match tile.page {
Page::ClipboardHistory => tile.clipboard_content.len() as u32,
Page::EmojiSearch => {
tile.emoji_apps.search_prefix(&tile.query_lc).count() as u32
} // or tile.results.len()
Page::EmojiSearch => tile
.emoji_apps
.search_prefix(&tile.query_lc, Vec::new())
.count() as u32, // or tile.results.len()
_ => tile.results.len() as u32,
};

Expand Down Expand Up @@ -933,6 +934,37 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
final_config.aliases.remove(&old.0);
final_config.aliases.insert(new.0, new.1);
}
SetConfigFields::Blacklist(Editable::Create(item)) => {
if !final_config.blacklist.contains(&item.to_lowercase()) {
final_config.blacklist.push(item.to_lowercase());
}
}
SetConfigFields::Blacklist(Editable::Delete(target)) => {
final_config.blacklist = final_config
.blacklist
.iter()
.filter_map(|item| {
if &target != item {
Some(item.to_lowercase())
} else {
None
}
})
.collect();
}
SetConfigFields::Blacklist(Editable::Update { old, new }) => {
final_config.blacklist = final_config
.blacklist
.iter()
.map(|item| {
if item == &old {
new.to_lowercase()
} else {
item.to_owned()
}
})
.collect();
}
SetConfigFields::SearchDirs(Editable::Create(dir)) => {
if !final_config.search_dirs.contains(&dir) {
final_config.search_dirs.push(dir);
Expand Down
4 changes: 3 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub struct Config {
pub modes: HashMap<String, String>,
pub aliases: HashMap<String, String>,
pub search_dirs: Vec<String>,
pub blacklist: Vec<String>,
pub log_path: String,
pub debounce_delay: u64,
pub auto_update: bool,
Expand All @@ -137,13 +138,14 @@ impl Default for Config {
haptic_feedback: false,
auto_update: true,
show_trayicon: true,
blacklist: Vec::new(),
window_location: Position::Default,
main_page: MainPage::default(),
search_dirs: vec!["~".to_string()],
log_path: "/tmp/rustcast.log".to_string(),
modes: HashMap::new(),
aliases: HashMap::new(),
shells: vec![],
shells: Vec::new(),
debounce_delay: 300,
input_source_on_open: None,
restore_input_source_on_close: true,
Expand Down
Loading