@@ -428,7 +428,9 @@ impl Task for IndexNewApplicationsTask {
428428pub struct ApplicationSearchSource ;
429429
430430impl ApplicationSearchSource {
431- pub async fn init < R : Runtime > ( app_handle : AppHandle < R > ) -> Result < ( ) , String > {
431+ pub async fn prepare_index_and_store < R : Runtime > (
432+ app_handle : AppHandle < R > ,
433+ ) -> Result < ( ) , String > {
432434 let ( tx, rx) = tokio:: sync:: oneshot:: channel ( ) ;
433435 let index_applications_task = IndexAllApplicationsTask {
434436 tauri_app_handle : app_handle. clone ( ) ,
@@ -472,8 +474,6 @@ impl ApplicationSearchSource {
472474 . set ( TAURI_STORE_KEY_SEARCH_PATH , default_search_path) ;
473475 }
474476
475- register_app_hotkey_upon_start ( app_handle. clone ( ) ) ?;
476-
477477 Ok ( ( ) )
478478 }
479479}
@@ -638,28 +638,69 @@ fn app_hotkey_handler<R: Runtime>(
638638 }
639639}
640640
641- fn register_app_hotkey_upon_start < R : Runtime > (
642- tauri_app_handle : AppHandle < R > ,
643- ) -> Result < ( ) , String > {
641+ /// For all the applications, if it is enabled & has hotkey set, then set it up.
642+ pub ( crate ) fn set_apps_hotkey < R : Runtime > ( tauri_app_handle : & AppHandle < R > ) -> Result < ( ) , String > {
644643 let app_hotkey_store = tauri_app_handle
645644 . store ( TAURI_STORE_APP_HOTKEY )
646645 . unwrap_or_else ( |_| panic ! ( "store [{}] not found/loaded" , TAURI_STORE_APP_HOTKEY ) ) ;
647646
647+ let disabled_app_list = get_disabled_app_list ( & tauri_app_handle) ;
648+
648649 for ( app_path, hotkey) in app_hotkey_store. entries ( ) {
650+ if disabled_app_list. contains ( & app_path) {
651+ continue ;
652+ }
653+
654+ let hotkey = match hotkey {
655+ Json :: String ( str) => str,
656+ _ => unreachable ! ( "hotkey should be stored in a string" ) ,
657+ } ;
658+
659+ set_app_hotkey ( & tauri_app_handle, & app_path, & hotkey) ?;
660+ }
661+
662+ Ok ( ( ) )
663+ }
664+
665+ /// For all the applications, if it is enabled & has hotkey set, then unset it.
666+ pub ( crate ) fn unset_apps_hotkey < R : Runtime > ( tauri_app_handle : & AppHandle < R > ) -> Result < ( ) , String > {
667+ let app_hotkey_store = tauri_app_handle
668+ . store ( TAURI_STORE_APP_HOTKEY )
669+ . unwrap_or_else ( |_| panic ! ( "store [{}] not found/loaded" , TAURI_STORE_APP_HOTKEY ) ) ;
670+
671+ let disabled_app_list = get_disabled_app_list ( & tauri_app_handle) ;
672+
673+ for ( app_path, hotkey) in app_hotkey_store. entries ( ) {
674+ if disabled_app_list. contains ( & app_path) {
675+ continue ;
676+ }
677+
649678 let hotkey = match hotkey {
650679 Json :: String ( str) => str,
651680 _ => unreachable ! ( "hotkey should be stored in a string" ) ,
652681 } ;
653682
654683 tauri_app_handle
655684 . global_shortcut ( )
656- . on_shortcut ( hotkey. as_str ( ) , app_hotkey_handler ( app_path ) )
685+ . unregister ( hotkey. as_str ( ) )
657686 . map_err ( |e| e. to_string ( ) ) ?;
658687 }
659688
660689 Ok ( ( ) )
661690}
662691
692+ /// Set the hotkey but won't persist this settings change.
693+ pub ( crate ) fn set_app_hotkey < R : Runtime > (
694+ tauri_app_handle : & AppHandle < R > ,
695+ app_path : & str ,
696+ hotkey : & str ,
697+ ) -> Result < ( ) , String > {
698+ tauri_app_handle
699+ . global_shortcut ( )
700+ . on_shortcut ( hotkey, app_hotkey_handler ( app_path. into ( ) ) )
701+ . map_err ( |e| e. to_string ( ) )
702+ }
703+
663704pub fn register_app_hotkey < R : Runtime > (
664705 tauri_app_handle : & AppHandle < R > ,
665706 app_path : & str ,
@@ -671,13 +712,9 @@ pub fn register_app_hotkey<R: Runtime>(
671712 let app_hotkey_store = tauri_app_handle
672713 . store ( TAURI_STORE_APP_HOTKEY )
673714 . unwrap_or_else ( |_| panic ! ( "store [{}] not found/loaded" , TAURI_STORE_APP_HOTKEY ) ) ;
674-
675715 app_hotkey_store. set ( app_path, hotkey) ;
676716
677- tauri_app_handle
678- . global_shortcut ( )
679- . on_shortcut ( hotkey, app_hotkey_handler ( app_path. into ( ) ) )
680- . map_err ( |e| e. to_string ( ) ) ?;
717+ set_app_hotkey ( tauri_app_handle, app_path, hotkey) ?;
681718
682719 Ok ( ( ) )
683720}
@@ -789,6 +826,21 @@ pub fn disable_app_search<R: Runtime>(
789826
790827 store. set ( TAURI_STORE_KEY_DISABLED_APP_LIST , disabled_app_list) ;
791828
829+ let app_hotkey_store = tauri_app_handle
830+ . store ( TAURI_STORE_APP_HOTKEY )
831+ . unwrap_or_else ( |_| panic ! ( "store [{}] not found/loaded" , TAURI_STORE_APP_HOTKEY ) ) ;
832+ let opt_hokey = app_hotkey_store. get ( app_path) . map ( |json| match json {
833+ Json :: String ( s) => s,
834+ _ => panic ! ( "hotkey should be stored in a string" ) ,
835+ } ) ;
836+
837+ if let Some ( hotkey) = opt_hokey {
838+ tauri_app_handle
839+ . global_shortcut ( )
840+ . unregister ( hotkey. as_str ( ) )
841+ . map_err ( |e| e. to_string ( ) ) ?;
842+ }
843+
792844 Ok ( ( ) )
793845}
794846
@@ -815,6 +867,18 @@ pub fn enable_app_search<R: Runtime>(
815867 disabled_app_list. remove ( index) ;
816868 store. set ( TAURI_STORE_KEY_DISABLED_APP_LIST , disabled_app_list) ;
817869
870+ let app_hotkey_store = tauri_app_handle
871+ . store ( TAURI_STORE_APP_HOTKEY )
872+ . unwrap_or_else ( |_| panic ! ( "store [{}] not found/loaded" , TAURI_STORE_APP_HOTKEY ) ) ;
873+ let opt_hokey = app_hotkey_store. get ( app_path) . map ( |json| match json {
874+ Json :: String ( s) => s,
875+ _ => panic ! ( "hotkey should be stored in a string" ) ,
876+ } ) ;
877+
878+ if let Some ( hotkey) = opt_hokey {
879+ set_app_hotkey ( tauri_app_handle, app_path, & hotkey) ?;
880+ }
881+
818882 Ok ( ( ) )
819883 }
820884 None => Err ( format ! (
0 commit comments