@@ -172,21 +172,34 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
172172 )
173173 }
174174
175- Message :: OpenFocused => match tile. results . get ( tile. focus_id as usize ) {
176- Some ( App {
177- open_command : AppCommand :: Function ( func) ,
178- ..
179- } ) => Task :: done ( Message :: RunFunction ( func. to_owned ( ) ) ) ,
180- Some ( App {
181- open_command : AppCommand :: Message ( msg) ,
182- ..
183- } ) => Task :: done ( msg. to_owned ( ) ) ,
184- Some ( App {
185- open_command : AppCommand :: Display ,
186- ..
187- } ) => Task :: done ( Message :: ReturnFocus ) ,
188- None => Task :: none ( ) ,
189- } ,
175+ Message :: OpenFocused => {
176+ // TODO: update ranking here
177+ match tile. results . get ( tile. focus_id as usize ) {
178+ Some ( App {
179+ search_name : name,
180+ open_command : AppCommand :: Function ( func) ,
181+ ..
182+ } ) => {
183+ info ! ( "Updating ranking for: {name}" ) ;
184+ tile. options . update_ranking ( name) ;
185+ Task :: done ( Message :: RunFunction ( func. to_owned ( ) ) )
186+ }
187+ Some ( App {
188+ search_name : name,
189+ open_command : AppCommand :: Message ( msg) ,
190+ ..
191+ } ) => {
192+ info ! ( "Updating ranking for: {name}" ) ;
193+ tile. options . update_ranking ( name) ;
194+ Task :: done ( msg. to_owned ( ) )
195+ }
196+ Some ( App {
197+ open_command : AppCommand :: Display ,
198+ ..
199+ } ) => Task :: done ( Message :: ReturnFocus ) ,
200+ None => Task :: none ( ) ,
201+ }
202+ }
190203
191204 Message :: ReloadConfig => {
192205 info ! ( "Reloading config" ) ;
@@ -351,6 +364,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
351364 } else if tile. query_lc == "randomvar" {
352365 let rand_num = rand:: random_range ( 0 ..100 ) ;
353366 tile. results = vec ! [ App {
367+ ranking: 0 ,
354368 open_command: AppCommand :: Function ( Function :: RandomVar ( rand_num) ) ,
355369 desc: "Easter egg" . to_string( ) ,
356370 icons: None ,
@@ -360,6 +374,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
360374 return single_item_resize_task ( id) ;
361375 } else if tile. query_lc == "67" {
362376 tile. results = vec ! [ App {
377+ ranking: 0 ,
363378 open_command: AppCommand :: Function ( Function :: RandomVar ( 67 ) ) ,
364379 desc: "Easter egg" . to_string( ) ,
365380 icons: None ,
@@ -369,6 +384,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
369384 return single_item_resize_task ( id) ;
370385 } else if tile. query_lc . ends_with ( "?" ) {
371386 tile. results = vec ! [ App {
387+ ranking: 0 ,
372388 open_command: AppCommand :: Function ( Function :: GoogleSearch ( tile. query. clone( ) ) ) ,
373389 icons: None ,
374390 desc: "Web Search" . to_string( ) ,
@@ -388,6 +404,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
388404 && let Some ( res) = Expr :: from_str ( & tile. query ) . ok ( )
389405 {
390406 tile. results . push ( App {
407+ ranking : 0 ,
391408 open_command : AppCommand :: Function ( Function :: Calculate ( res. clone ( ) ) ) ,
392409 desc : RUSTCAST_DESC_NAME . to_string ( ) ,
393410 icons : None ,
@@ -411,6 +428,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
411428 conversion. target_unit. name
412429 ) ;
413430 App {
431+ ranking : 0 ,
414432 open_command : AppCommand :: Function ( Function :: CopyToClipboard (
415433 ClipBoardContentType :: Text ( target. clone ( ) ) ,
416434 ) ) ,
@@ -423,6 +441,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
423441 . collect ( ) ;
424442 } else if tile. results . is_empty ( ) && is_valid_url ( & tile. query ) {
425443 tile. results . push ( App {
444+ ranking : 0 ,
426445 open_command : AppCommand :: Function ( Function :: OpenWebsite ( tile. query . clone ( ) ) ) ,
427446 desc : "Web Browsing" . to_string ( ) ,
428447 icons : None ,
@@ -431,6 +450,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
431450 } ) ;
432451 } else if tile. query_lc . split ( ' ' ) . count ( ) > 1 {
433452 tile. results . push ( App {
453+ ranking : 0 ,
434454 open_command : AppCommand :: Function ( Function :: GoogleSearch ( tile. query . clone ( ) ) ) ,
435455 icons : None ,
436456 desc : "Web Search" . to_string ( ) ,
@@ -439,6 +459,7 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
439459 } ) ;
440460 } else if tile. results . is_empty ( ) && tile. query_lc == "lemon" {
441461 tile. results . push ( App {
462+ ranking : 0 ,
442463 open_command : AppCommand :: Display ,
443464 desc : "Easter Egg" . to_string ( ) ,
444465 icons : lemon_icon_handle ( ) ,
@@ -454,6 +475,8 @@ pub fn handle_update(tile: &mut Tile, message: Message) -> Task<Message> {
454475 . collect ( ) ;
455476 }
456477
478+ tile. results . sort_by_key ( |x| -x. ranking ) ;
479+
457480 let new_length = tile. results . len ( ) ;
458481 let max_elem = min ( 5 , new_length) ;
459482
0 commit comments