@@ -245,8 +245,29 @@ async fn index_applications_if_not_indexed<R: Runtime>(
245245 let mut writer = pizza_engine. acquire_writer ( ) ;
246246
247247 if !index_exists {
248- let default_search_path = get_default_search_paths ( ) ;
249- let apps = list_app_in ( default_search_path) . map_err ( |str| anyhow:: anyhow!( str ) ) ?;
248+ let search_path = {
249+ let disabled_app_list_and_search_path_store = tauri_app_handle
250+ . store ( TAURI_STORE_DISABLED_APP_LIST_AND_SEARCH_PATH ) ?;
251+ let search_path_json = disabled_app_list_and_search_path_store
252+ . get ( TAURI_STORE_KEY_SEARCH_PATH )
253+ . unwrap_or_else ( || {
254+ panic ! ( "search path should be persisted in the store, but it is not, plz ensure that the store gets initialized before calling this function" )
255+ } ) ;
256+
257+ let search_path: Vec < String > = match search_path_json {
258+ Json :: Array ( array) => array
259+ . into_iter ( )
260+ . map ( |json| match json {
261+ Json :: String ( str) => str,
262+ _ => unreachable ! ( "search path is stored in a string" ) ,
263+ } )
264+ . collect ( ) ,
265+ _ => unreachable ! ( "search path is stored in an array" ) ,
266+ } ;
267+
268+ search_path
269+ } ;
270+ let apps = list_app_in ( search_path) . map_err ( |str| anyhow:: anyhow!( str ) ) ?;
250271
251272 for app in apps. iter ( ) {
252273 let app_path = get_app_path ( app) ;
@@ -489,26 +510,6 @@ impl ApplicationSearchSource {
489510 pub async fn prepare_index_and_store < R : Runtime > (
490511 app_handle : AppHandle < R > ,
491512 ) -> Result < ( ) , String > {
492- let ( tx, rx) = tokio:: sync:: oneshot:: channel ( ) ;
493- let index_applications_task = IndexAllApplicationsTask {
494- tauri_app_handle : app_handle. clone ( ) ,
495- callback : Some ( tx) ,
496- } ;
497-
498- RUNTIME_TX
499- . get ( )
500- . unwrap ( )
501- . send ( Box :: new ( index_applications_task) )
502- . unwrap ( ) ;
503-
504- let indexing_applications_result = rx. await . unwrap ( ) ;
505- if let Err ( ref e) = indexing_applications_result {
506- error ! (
507- "indexing local applications failed, app search won't work, error [{}]" ,
508- e
509- )
510- }
511-
512513 app_handle
513514 . store ( TAURI_STORE_APP_HOTKEY )
514515 . map_err ( |e| e. to_string ( ) ) ?;
@@ -523,6 +524,9 @@ impl ApplicationSearchSource {
523524 . set ( TAURI_STORE_KEY_DISABLED_APP_LIST , Json :: Array ( Vec :: new ( ) ) ) ;
524525 }
525526
527+ // IndexAllApplicationsTask will read the apps installed in search paths and
528+ // index them, so it depends on this configuration entry. Init this entry
529+ // before indexing apps.
526530 if disabled_app_list_and_search_path_store
527531 . get ( TAURI_STORE_KEY_SEARCH_PATH )
528532 . is_none ( )
@@ -532,6 +536,28 @@ impl ApplicationSearchSource {
532536 . set ( TAURI_STORE_KEY_SEARCH_PATH , default_search_path) ;
533537 }
534538
539+
540+ let ( tx, rx) = tokio:: sync:: oneshot:: channel ( ) ;
541+ let index_applications_task = IndexAllApplicationsTask {
542+ tauri_app_handle : app_handle. clone ( ) ,
543+ callback : Some ( tx) ,
544+ } ;
545+
546+ RUNTIME_TX
547+ . get ( )
548+ . unwrap ( )
549+ . send ( Box :: new ( index_applications_task) )
550+ . unwrap ( ) ;
551+
552+ let indexing_applications_result = rx. await . unwrap ( ) ;
553+ if let Err ( ref e) = indexing_applications_result {
554+ error ! (
555+ "indexing local applications failed, app search won't work, error [{}]" ,
556+ e
557+ )
558+ }
559+
560+
535561 Ok ( ( ) )
536562 }
537563}
0 commit comments