Skip to content

Commit daf39a2

Browse files
committed
Remove the stupid multi threading
1 parent e99fdf1 commit daf39a2

1 file changed

Lines changed: 21 additions & 32 deletions

File tree

src/app/tile/update.rs

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -422,18 +422,6 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
422422
tile.query_lc = input.trim().to_lowercase();
423423
tile.query = input;
424424

425-
let query_clone = tile.query.clone();
426-
let query_clone_2 = tile.query.clone();
427-
let query_clone_3 = tile.query.clone();
428-
let query_clone_4 = tile.query_lc.clone();
429-
430-
let is_valid_url = thread::spawn(move || is_valid_url(&query_clone));
431-
let conversions = thread::spawn(move || unit_conversion::convert_query(&query_clone_2));
432-
let expr = thread::spawn(move || Expr::from_str(&query_clone_3));
433-
let web_search = thread::spawn(move || {
434-
query_clone_4.ends_with("?") || query_clone_4.split_whitespace().nth(2).is_some()
435-
});
436-
437425
let prev_size = tile.results.len();
438426

439427
if tile.page == Page::ClipboardHistory && tile.query_lc != "main" {
@@ -499,22 +487,23 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
499487
return Task::batch([zero_item_resize_task(id), task]);
500488
}
501489
}
502-
_ => {}
503-
}
504-
505-
if tile.query_lc.starts_with(">") && tile.page == Page::Main {
506-
let command = tile.query.strip_prefix(">").unwrap_or("");
507-
tile.results = vec![App {
508-
ranking: 20,
509-
open_command: AppCommand::Function(Function::RunShellCommand(
510-
command.to_string(),
511-
)),
512-
display_name: format!("Shell Command: {}", command),
513-
icons: None,
514-
search_name: "".to_string(),
515-
desc: "Shell Command".to_string(),
516-
}];
517-
return single_item_resize_task(id);
490+
query => 'a: {
491+
if !query.starts_with(">") || tile.page != Page::Main {
492+
break 'a
493+
}
494+
let command = tile.query.strip_prefix(">").unwrap_or("");
495+
tile.results = vec![App {
496+
ranking: 20,
497+
open_command: AppCommand::Function(Function::RunShellCommand(
498+
command.to_string(),
499+
)),
500+
display_name: format!("Shell Command: {}", command),
501+
icons: None,
502+
search_name: "".to_string(),
503+
desc: "Shell Command".to_string(),
504+
}];
505+
return single_item_resize_task(id);
506+
}
518507
}
519508

520509
tile.handle_search_query_changed();
@@ -538,7 +527,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
538527
}
539528
}
540529

541-
if is_valid_url.join().unwrap_or(false) {
530+
if is_valid_url(&tile.query) {
542531
tile.results.push(App {
543532
ranking: 0,
544533
open_command: AppCommand::Function(Function::OpenWebsite(tile.query.clone())),
@@ -547,13 +536,13 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
547536
display_name: "Open Website: ".to_string() + &tile.query,
548537
search_name: String::new(),
549538
});
550-
} else if let Some(conversions) = conversions.join().unwrap_or(None) {
539+
} else if let Some(conversions) = unit_conversion::convert_query(&tile.query) {
551540
tile.results = conversions
552541
.into_iter()
553542
.map(|conversion| conversion.to_app())
554543
.collect();
555544
return single_item_resize_task(id);
556-
} else if let Some(res) = expr.join().map(|x| x.ok()).unwrap_or(None) {
545+
} else if let Some(res) = Expr::from_str(&tile.query).ok() {
557546
tile.results.push(App {
558547
ranking: 0,
559548
open_command: AppCommand::Function(Function::Calculate(res.clone())),
@@ -563,7 +552,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
563552
search_name: "".to_string(),
564553
});
565554
return single_item_resize_task(id);
566-
} else if web_search.join().unwrap_or(false) {
555+
} else if tile.query.ends_with("?") || tile.query.split_whitespace().nth(2).is_some() {
567556
tile.results = vec![App {
568557
ranking: 0,
569558
open_command: AppCommand::Function(Function::GoogleSearch(tile.query.clone())),

0 commit comments

Comments
 (0)