1- use std:: collections:: HashSet ;
21use std:: env;
3- use std:: hash:: { Hash , Hasher } ;
42use std:: path:: PathBuf ;
53use std:: process:: { Command , Stdio } ;
64use std:: sync:: LazyLock ;
@@ -14,7 +12,7 @@ use crate::config::Config;
1412
1513#[ derive( Debug ) ]
1614pub struct Application {
17- pub id : String ,
15+ pub id : SharedString ,
1816 pub name : SharedString ,
1917 pub description : Option < SharedString > ,
2018 pub icon : Option < Resource > ,
@@ -56,59 +54,54 @@ impl Application {
5654 }
5755 }
5856 }
59- }
60-
61- impl Hash for Application {
62- fn hash < H : Hasher > ( & self , state : & mut H ) {
63- self . id . hash ( state) ;
64- }
65- }
66-
67- impl PartialEq for Application {
68- fn eq ( & self , other : & Self ) -> bool {
69- self . id == other. id
70- }
71- }
72-
73- impl Eq for Application { }
7457
75- pub fn load_applications ( ) -> Vec < Application > {
76- let locales = get_languages_from_env ( ) ;
58+ pub fn load ( ) -> Vec < Self > {
59+ let locales = get_languages_from_env ( ) ;
7760
78- Iter :: new ( default_paths ( ) )
79- . entries ( Some ( & locales) )
80- . filter_map ( |entry| {
61+ let mut applications = Vec :: new ( ) ;
62+ for entry in Iter :: new ( default_paths ( ) ) . entries ( Some ( & locales) ) {
8163 if entry. no_display ( ) || entry. hidden ( ) {
82- return None ;
64+ continue ;
8365 }
8466
85- let name = SharedString :: from ( entry. name ( & locales) ?. into_owned ( ) ) ;
67+ let id = SharedString :: from ( entry. id ( ) . to_string ( ) ) ;
68+ if applications. iter ( ) . any ( |a : & Application | a. id == id) {
69+ continue ;
70+ }
71+
72+ let Ok ( exec) = entry. parse_exec_with_uris ( & [ ] , & locales) else {
73+ continue ;
74+ } ;
75+ let name = match entry. name ( & locales) {
76+ Some ( name) => SharedString :: from ( name. into_owned ( ) ) ,
77+ None => continue ,
78+ } ;
8679 let description = entry
8780 . comment ( & locales)
88- . map ( |c | SharedString :: from ( c . into_owned ( ) ) ) ;
81+ . map ( |description | SharedString :: from ( description . into_owned ( ) ) ) ;
8982 let icon = entry
9083 . icon ( )
91- . and_then ( |i | lookup ( i ) . with_cache ( ) . with_size ( 28 ) . find ( ) )
92- . map ( |i| i . into ( ) ) ;
84+ . and_then ( |icon | lookup ( icon ) . with_cache ( ) . with_size ( 28 ) . find ( ) )
85+ . map ( |path| Resource :: Path ( path . into ( ) ) ) ;
9386 let searchable = Utf32String :: from ( match description {
9487 Some ( ref d) => name. to_string ( ) + " " + d. as_str ( ) ,
9588 None => name. to_string ( ) ,
9689 } ) ;
9790
98- Some ( Application {
99- id : entry . id ( ) . to_string ( ) ,
91+ applications . push ( Application {
92+ id,
10093 name,
10194 description,
10295 icon,
10396 searchable,
104- exec : entry . parse_exec_with_uris ( & [ ] , & locales ) . ok ( ) ? ,
97+ exec,
10598 working_dir : entry. path ( ) . and_then ( |entry| entry. parse ( ) . ok ( ) ) ,
10699 open_in_terminal : entry. terminal ( ) ,
107- } )
108- } )
109- . collect :: < HashSet < Application > > ( )
110- . into_iter ( )
111- . collect ( )
100+ } ) ;
101+ }
102+
103+ applications
104+ }
112105}
113106
114107static TERMINAL : LazyLock < & str > = LazyLock :: new ( || {
0 commit comments