Skip to content

Commit 9de6dbf

Browse files
authored
Merge pull request #203 from jiasunzhu613/file-search-debounce
2 parents 640ae33 + b94be97 commit 9de6dbf

7 files changed

Lines changed: 237 additions & 148 deletions

File tree

src/app.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ use std::collections::HashMap;
33

44
use crate::app::apps::{App, AppCommand, ICNS_ICON};
55
use crate::commands::Function;
6+
use crate::config::Config;
7+
use crate::debounce::DebouncePolicy;
68
use crate::utils::icns_data_to_handle;
79
use crate::{app::tile::ExtSender, clipboard::ClipBoardContentType};
10+
use iced::time::Duration;
811

912
pub mod apps;
1013
pub mod menubar;
@@ -82,6 +85,7 @@ pub enum Message {
8285
SwitchToPage(Page),
8386
ClipboardHistory(ClipBoardContentType),
8487
ChangeFocus(ArrowKey, u32),
88+
DebouncedSearch(Id),
8589
}
8690

8791
/// The window settings for rustcast
@@ -156,3 +160,14 @@ impl ToApps for HashMap<String, String> {
156160
to_apps
157161
}
158162
}
163+
164+
impl DebouncePolicy for Page {
165+
fn debounce_delay(&self, config: &Config) -> Option<Duration> {
166+
match self {
167+
Page::Main => None,
168+
Page::FileSearch => Some(Duration::from_millis(config.debounce_delay)),
169+
Page::ClipboardHistory => None,
170+
Page::EmojiSearch => Some(Duration::from_millis(config.debounce_delay)),
171+
}
172+
}
173+
}

src/app/tile.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub mod update;
55
use crate::app::{ArrowKey, Message, Move, Page};
66
use crate::clipboard::ClipBoardContentType;
77
use crate::config::Config;
8+
use crate::debounce::Debouncer;
89
use crate::utils::open_settings;
910
use crate::{app::apps::App, platform::default_app_paths};
1011

@@ -96,7 +97,7 @@ impl AppIndex {
9697
/// - Query Lowercase (String, but lowercase)
9798
/// - Previous Query Lowercase (String)
9899
/// - Results (Vec<[`App`]>) the results of the search
99-
/// - Options ([`AppIndex`]) the options to search through (is a BTreeMap wrapper)
100+
/// - Options ([`AppIndex`]) the options to search through (is a HashMap wrapper)
100101
/// - Emoji Apps ([`AppIndex`]) emojis that are considered as "apps"
101102
/// - Visible (bool) whether the window is visible or not
102103
/// - Focused (bool) whether the window is focused or not
@@ -129,6 +130,7 @@ pub struct Tile {
129130
sender: Option<ExtSender>,
130131
page: Page,
131132
pub height: f32,
133+
debouncer: Debouncer,
132134
}
133135

134136
/// A struct to store all the hotkeys

src/app/tile/elm.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::app::pages::emoji::emoji_page;
1818
use crate::app::tile::{AppIndex, Hotkeys};
1919
use crate::app::{DEFAULT_WINDOW_HEIGHT, ToApp, ToApps};
2020
use crate::config::Theme;
21+
use crate::debounce::Debouncer;
2122
use crate::styles::{contents_style, glass_border, glass_surface, rustcast_text_input_style};
2223
use crate::{app::WINDOW_WIDTH, platform};
2324
use crate::{app::pages::clipboard::clipboard_view, platform::get_installed_apps};
@@ -82,6 +83,7 @@ pub fn new(hotkey: HotKey, config: &Config) -> (Tile, Task<Message>) {
8283
sender: None,
8384
page: Page::Main,
8485
height: DEFAULT_WINDOW_HEIGHT,
86+
debouncer: Debouncer::new(config.debounce_delay),
8587
},
8688
Task::batch([open.map(|_| Message::OpenWindow)]),
8789
)

0 commit comments

Comments
 (0)