@@ -69,6 +69,24 @@ fn dock_icon(icon_path: PathBuf, name: String) -> Element {
6969 Color :: TRANSPARENT
7070 } ;
7171
72+ let is_svg = icon_path
73+ . extension ( )
74+ . is_some_and ( |ext| ext. eq_ignore_ascii_case ( "svg" ) ) ;
75+
76+ let icon_element: Element = if is_svg {
77+ let svg_data = use_hook ( || {
78+ std:: fs:: read ( & icon_path)
79+ . map ( Bytes :: from)
80+ . unwrap_or_default ( )
81+ } ) ;
82+ svg ( svg_data) . width ( Size :: px ( 40. ) ) . height ( Size :: px ( 40. ) ) . into ( )
83+ } else {
84+ ImageViewer :: new ( icon_path)
85+ . width ( Size :: px ( 40. ) )
86+ . height ( Size :: px ( 40. ) )
87+ . into ( )
88+ } ;
89+
7290 rect ( )
7391 . center ( )
7492 . padding ( Gaps :: new_all ( 4. ) )
@@ -79,11 +97,7 @@ fn dock_icon(icon_path: PathBuf, name: String) -> Element {
7997 . on_mouse_up ( move |_| {
8098 println ! ( "Clicked: {}" , name) ;
8199 } )
82- . child (
83- ImageViewer :: new ( icon_path)
84- . width ( Size :: px ( 40. ) )
85- . height ( Size :: px ( 40. ) ) ,
86- )
100+ . child ( icon_element)
87101 . into ( )
88102}
89103
@@ -183,28 +197,40 @@ fn find_icon_path(icon_name: &str) -> Option<PathBuf> {
183197 Some ( PathBuf :: from ( "/usr/share/pixmaps" ) ) ,
184198 ] ;
185199
186- // Prefer larger icons
200+ // Prefer larger icons, and PNG over SVG (ImageViewer handles PNG better)
187201 let sizes = [ "256x256" , "128x128" , "96x96" , "64x64" , "48x48" , "scalable" ] ;
188- let extensions = [ "png" , "svg" ] ;
189202
190- for dir in icon_dirs. into_iter ( ) . flatten ( ) {
203+ // First pass: look for PNG files only
204+ for dir in icon_dirs. iter ( ) . flatten ( ) {
191205 for size in & sizes {
192- for ext in & extensions {
193- let icon_path = dir. join ( size) . join ( "apps" ) . join ( format ! ( "{}.{}" , icon_name, ext) ) ;
194- if icon_path. exists ( ) {
195- return Some ( icon_path) ;
196- }
206+ let icon_path = dir. join ( size) . join ( "apps" ) . join ( format ! ( "{}.png" , icon_name) ) ;
207+ if icon_path. exists ( ) {
208+ return Some ( icon_path) ;
197209 }
198210 }
199211 }
200212
201- // Check pixmaps directory (flat structure)
202- for ext in & extensions {
203- let pixmap_path = PathBuf :: from ( "/usr/share/pixmaps" ) . join ( format ! ( "{}.{}" , icon_name, ext) ) ;
204- if pixmap_path. exists ( ) {
205- return Some ( pixmap_path) ;
213+ // Check pixmaps for PNG
214+ let pixmap_path = PathBuf :: from ( "/usr/share/pixmaps" ) . join ( format ! ( "{}.png" , icon_name) ) ;
215+ if pixmap_path. exists ( ) {
216+ return Some ( pixmap_path) ;
217+ }
218+
219+ // Second pass: fall back to SVG if no PNG found
220+ for dir in icon_dirs. into_iter ( ) . flatten ( ) {
221+ for size in & sizes {
222+ let icon_path = dir. join ( size) . join ( "apps" ) . join ( format ! ( "{}.svg" , icon_name) ) ;
223+ if icon_path. exists ( ) {
224+ return Some ( icon_path) ;
225+ }
206226 }
207227 }
208228
229+ // Check pixmaps for SVG
230+ let pixmap_path = PathBuf :: from ( "/usr/share/pixmaps" ) . join ( format ! ( "{}.svg" , icon_name) ) ;
231+ if pixmap_path. exists ( ) {
232+ return Some ( pixmap_path) ;
233+ }
234+
209235 None
210236}
0 commit comments