feature/prod-ready #1

Merged
GKaszewski merged 12 commits from feature/prod-ready into master 2026-03-15 19:03:32 +00:00
Showing only changes of commit c68f07d522 - Show all commits

View File

@@ -27,6 +27,7 @@ pub struct KLauncherApp {
selected: usize, selected: usize,
cfg: AppearanceCfg, cfg: AppearanceCfg,
error: Option<String>, error: Option<String>,
search_epoch: u64,
} }
impl KLauncherApp { impl KLauncherApp {
@@ -43,6 +44,7 @@ impl KLauncherApp {
selected: 0, selected: 0,
cfg, cfg,
error: None, error: None,
search_epoch: 0,
} }
} }
} }
@@ -50,7 +52,7 @@ impl KLauncherApp {
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum Message { pub enum Message {
QueryChanged(String), QueryChanged(String),
ResultsReady(Arc<Vec<SearchResult>>), ResultsReady(u64, Arc<Vec<SearchResult>>),
KeyPressed(KeyEvent), KeyPressed(KeyEvent),
} }
@@ -60,14 +62,21 @@ fn update(state: &mut KLauncherApp, message: Message) -> Task<Message> {
state.error = None; state.error = None;
state.query = q.clone(); state.query = q.clone();
state.selected = 0; state.selected = 0;
state.search_epoch += 1;
let epoch = state.search_epoch;
let engine = state.engine.clone(); let engine = state.engine.clone();
Task::perform( Task::perform(
async move { engine.search(&q).await }, async move {
|results| Message::ResultsReady(Arc::new(results)), tokio::time::sleep(std::time::Duration::from_millis(50)).await;
(epoch, engine.search(&q).await)
},
|(epoch, results)| Message::ResultsReady(epoch, Arc::new(results)),
) )
} }
Message::ResultsReady(results) => { Message::ResultsReady(epoch, results) => {
state.results = results; if epoch == state.search_epoch {
state.results = results;
}
Task::none() Task::none()
} }
Message::KeyPressed(event) => { Message::KeyPressed(event) => {