@@ -14,18 +14,28 @@ use tauri_plugin_fs_pro::{icon, name};
1414
1515#[ tauri:: command]
1616pub fn get_default_search_paths ( ) -> Vec < String > {
17- let paths = applications:: get_default_search_paths ( ) ;
18- let mut ret = Vec :: with_capacity ( paths. len ( ) ) ;
19- for search_path in paths {
20- let path_string = search_path
21- . into_os_string ( )
22- . into_string ( )
23- . expect ( "path should be UTF-8 encoded" ) ;
24-
25- ret. push ( path_string) ;
26- }
17+ #[ cfg( target_os = "macos" ) ]
18+ return vec ! [
19+ "/Applications" . into( ) ,
20+ "/System/Applications" . into( ) ,
21+ "/System/Library/CoreServices" . into( ) ,
22+ ] ;
23+
24+ #[ cfg( not( target_os = "macos" ) ) ]
25+ {
26+ let paths = applications:: get_default_search_paths ( ) ;
27+ let mut ret = Vec :: with_capacity ( paths. len ( ) ) ;
28+ for search_path in paths {
29+ let path_string = search_path
30+ . into_os_string ( )
31+ . into_string ( )
32+ . expect ( "path should be UTF-8 encoded" ) ;
33+
34+ ret. push ( path_string) ;
35+ }
2736
28- ret
37+ ret
38+ }
2939}
3040
3141/// List apps that are in the `search_path`.
@@ -35,27 +45,24 @@ fn list_app_in(search_path: Vec<String>) -> Result<Vec<App>, String> {
3545 . into_iter ( )
3646 . map ( PathBuf :: from)
3747 . collect :: < Vec < _ > > ( ) ;
48+
3849 let apps = applications:: get_all_apps ( & search_path) . map_err ( |err| err. to_string ( ) ) ?;
3950
4051 Ok ( apps
4152 . into_iter ( )
42- . filter ( |app| app. icon_path . is_none ( ) )
53+ . filter ( |app| ! app. icon_path . is_none ( ) )
4354 . collect ( ) )
4455}
4556
4657#[ derive( serde:: Serialize ) ]
58+ #[ serde( rename_all = "camelCase" ) ]
4759pub struct AppMetadata {
48- #[ serde( rename = "Name" ) ]
4960 name : String ,
50- #[ serde( rename = "Where" ) ]
5161 r#where : PathBuf ,
52- #[ serde( rename = "Size" ) ]
5362 size : u64 ,
54- # [ serde ( rename = "Created" ) ]
63+ icon : PathBuf ,
5564 created : u128 ,
56- #[ serde( rename = "Modified" ) ]
5765 modified : u128 ,
58- #[ serde( rename = "Last opened" ) ]
5966 last_opened : u128 ,
6067}
6168
@@ -65,16 +72,18 @@ pub struct AppMetadata {
6572///
6673/// ```json
6774/// {
68- /// "Name": "Finder",
69- /// "Where": "/System/Library/CoreServices",
70- /// "Size": 49283072,
71- /// "Created": 1744625204,
72- /// "Modified": 1744625204,
73- /// "Last opened": 1744625250
75+ /// "name": "Finder",
76+ /// "where": "/System/Library/CoreServices",
77+ /// "size": 49283072,
78+ /// "icon": "/xxx.png",
79+ /// "created": 1744625204,
80+ /// "modified": 1744625204,
81+ /// "lastOpened": 1744625250
7482/// }
7583/// ```
7684#[ tauri:: command]
77- pub async fn list_app_with_metadata_in (
85+ pub async fn list_app_with_metadata_in < R : Runtime > (
86+ app_handle : AppHandle < R > ,
7887 search_path : Vec < String > ,
7988) -> Result < Vec < AppMetadata > , String > {
8089 let apps = list_app_in ( search_path) ?;
@@ -101,12 +110,21 @@ pub async fn list_app_with_metadata_in(
101110 app_path_clone
102111 } ;
103112
113+ let icon = if cfg ! ( target_os = "linux" ) {
114+ app. icon_path . clone ( ) . unwrap_or ( PathBuf :: from ( "" ) )
115+ } else {
116+ icon ( app_handle. clone ( ) , app_path. clone ( ) , Some ( 256 ) )
117+ . await
118+ . map_err ( |err| err. to_string ( ) ) ?
119+ } ;
120+
104121 let raw_app_metadata = tauri_plugin_fs_pro:: metadata ( app_path. clone ( ) , None ) . await ?;
105122
106123 let app_metadata = AppMetadata {
107124 name : app_name,
108125 r#where : app_path_where,
109126 size : raw_app_metadata. size ,
127+ icon,
110128 created : raw_app_metadata. created_at ,
111129 modified : raw_app_metadata. modified_at ,
112130 last_opened : raw_app_metadata. accessed_at ,
@@ -132,11 +150,7 @@ impl ApplicationSearchSource {
132150 let application_paths = Trie :: new ( ) ;
133151 let mut icons = HashMap :: new ( ) ;
134152
135- let default_search_path = if cfg ! ( target_os = "macos" ) {
136- vec ! [ "/Applications" . into( ) , "/System/Applications" . into( ) , "/System/Library/CoreServices" . into( ) ]
137- } else {
138- applications:: get_default_search_paths ( )
139- } ;
153+ let default_search_path = applications:: get_default_search_paths ( ) ;
140154 let mut ctx = AppInfoContext :: new ( default_search_path) ;
141155 ctx. refresh_apps ( ) . map_err ( |err| err. to_string ( ) ) ?; // must refresh apps before getting them
142156 let apps = ctx. get_all_apps ( ) ;
0 commit comments