@@ -40,6 +40,7 @@ use tokio::sync::oneshot::Sender as OneshotSender;
4040// have to keep it.
4141const FIELD_APP_NAME : & str = "app_name" ;
4242
43+ const FIELD_APP_NAME_IN_SYSTEM_LANG : & str = "app_name_in_system_lang" ;
4344const FIELD_APP_NAME_ZH : & str = "app_name_zh" ;
4445const FIELD_APP_NAME_EN : & str = "app_name_en" ;
4546const FIELD_ICON_PATH : & str = "icon_path" ;
@@ -131,6 +132,19 @@ async fn get_app_name_en(app: &App) -> String {
131132 app. name . clone ( )
132133}
133134
135+ /// Helper function to return `app`'s name in system language.
136+ async fn get_app_name_in_system_lang ( app : & App ) -> String {
137+ let system_lang = crate :: util:: system_lang:: get_system_lang ( ) ;
138+
139+ // First try en_US
140+ if let Some ( name) = app. localized_app_names . get ( & system_lang) {
141+ name. clone ( )
142+ } else {
143+ // Fall back to base name
144+ app. name . clone ( )
145+ }
146+ }
147+
134148/// Helper function to return an absolute path to `app`'s icon.
135149///
136150/// On macOS/Windows, we cache icons in our data directory using the `icon()` function.
@@ -232,6 +246,10 @@ async fn index_applications_if_not_indexed(
232246 schema
233247 . add_property ( FIELD_APP_NAME_EN , field_app_name_en)
234248 . expect ( "no collision could happen" ) ;
249+ let field_app_name_in_system_lang = Property :: builder ( FieldType :: Text ) . build ( ) ;
250+ schema
251+ . add_property ( FIELD_APP_NAME_IN_SYSTEM_LANG , field_app_name_in_system_lang)
252+ . expect ( "no collision could happen" ) ;
235253 let property_icon = Property :: builder ( FieldType :: Text ) . index ( false ) . build ( ) ;
236254 schema
237255 . add_property ( FIELD_ICON_PATH , property_icon)
@@ -277,13 +295,17 @@ async fn index_applications_if_not_indexed(
277295 let app_path = get_app_path ( app) ;
278296 let app_name_zh = get_app_name_zh ( app) . await ;
279297 let app_name_en = get_app_name_en ( app) . await ;
298+ let app_name_in_system_lang = get_app_name_in_system_lang ( app) . await ;
280299 let app_icon_path = get_app_icon_path ( & tauri_app_handle, app)
281300 . await
282301 . map_err ( |str| anyhow:: anyhow!( str ) ) ?;
283302 let app_alias = get_app_alias ( & tauri_app_handle, & app_path) . unwrap_or ( String :: new ( ) ) ;
284303
285- // Skip if both names are empty
286- if app_name_zh. is_empty ( ) && app_name_en. is_empty ( ) {
304+ // Skip if all names are empty
305+ if app_name_zh. is_empty ( )
306+ && app_name_en. is_empty ( )
307+ && app_name_in_system_lang. is_empty ( )
308+ {
287309 continue ;
288310 }
289311
@@ -298,10 +320,12 @@ async fn index_applications_if_not_indexed(
298320 // You cannot write `app_name.clone()` within the `doc!()` macro, we should fix this.
299321 let app_name_zh_clone = app_name_zh. clone ( ) ;
300322 let app_name_en_clone = app_name_en. clone ( ) ;
323+ let app_name_in_system_lang = app_name_in_system_lang. clone ( ) ;
301324 let app_path_clone = app_path. clone ( ) ;
302325 let document = doc ! ( app_path_clone, {
303326 FIELD_APP_NAME_ZH => app_name_zh_clone,
304327 FIELD_APP_NAME_EN => app_name_en_clone,
328+ FIELD_APP_NAME_IN_SYSTEM_LANG => app_name_in_system_lang,
305329 FIELD_ICON_PATH => app_icon_path,
306330 FIELD_APP_ALIAS => app_alias,
307331 }
@@ -444,7 +468,9 @@ impl Task for SearchApplicationsTask {
444468 // In order to be backward compatible, we still do match and prefix queries to the
445469 // app_name field.
446470 let dsl = format ! (
447- "{{ \" query\" : {{ \" bool\" : {{ \" should\" : [ {{ \" match\" : {{ \" {FIELD_APP_NAME_ZH}\" : {:?} }} }}, {{ \" prefix\" : {{ \" {FIELD_APP_NAME_ZH}\" : {:?} }} }}, {{ \" match\" : {{ \" {FIELD_APP_NAME_EN}\" : {:?} }} }}, {{ \" prefix\" : {{ \" {FIELD_APP_NAME_EN}\" : {:?} }} }}, {{ \" match\" : {{ \" {FIELD_APP_NAME}\" : {:?} }} }}, {{ \" prefix\" : {{ \" {FIELD_APP_NAME}\" : {:?} }} }} ] }} }} }}" ,
471+ "{{ \" query\" : {{ \" bool\" : {{ \" should\" : [ {{ \" match\" : {{ \" {FIELD_APP_NAME_ZH}\" : {:?} }} }}, {{ \" prefix\" : {{ \" {FIELD_APP_NAME_ZH}\" : {:?} }} }}, {{ \" match\" : {{ \" {FIELD_APP_NAME_EN}\" : {:?} }} }}, {{ \" prefix\" : {{ \" {FIELD_APP_NAME_EN}\" : {:?} }} }}, {{ \" match\" : {{ \" {FIELD_APP_NAME_IN_SYSTEM_LANG}\" : {:?} }} }}, {{ \" prefix\" : {{ \" {FIELD_APP_NAME_IN_SYSTEM_LANG}\" : {:?} }} }}, {{ \" match\" : {{ \" {FIELD_APP_NAME}\" : {:?} }} }}, {{ \" prefix\" : {{ \" {FIELD_APP_NAME}\" : {:?} }} }} ] }} }} }}" ,
472+ self . query_string,
473+ self . query_string,
448474 self . query_string,
449475 self . query_string,
450476 self . query_string,
0 commit comments