@@ -177,7 +177,6 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
177177 _ => unimplemented ! ( ) ,
178178 } ;
179179
180- #[ cfg( any( windows, target_os = "linux" ) ) ]
181180 let out_dir = {
182181 let out_dir = std:: env:: var ( "OUT_DIR" )
183182 . map_err ( |_| EmbeddedAssetsError :: OutDir )
@@ -193,12 +192,20 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
193192 // handle default window icons for Windows targets
194193 #[ cfg( windows) ]
195194 let default_window_icon = {
196- let icon_path = find_icon (
195+ let mut icon_path = find_icon (
197196 & config,
198197 & config_parent,
199198 |i| i. ends_with ( ".ico" ) ,
200199 "icons/icon.ico" ,
201200 ) ;
201+ if !icon_path. exists ( ) {
202+ icon_path = find_icon (
203+ & config,
204+ & config_parent,
205+ |i| i. ends_with ( ".png" ) ,
206+ "icons/icon.png" ,
207+ ) ;
208+ }
202209 ico_icon ( & root, & out_dir, icon_path) ?
203210 } ;
204211 #[ cfg( target_os = "linux" ) ]
@@ -234,49 +241,22 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
234241 }
235242 ) ;
236243
237- #[ cfg( target_os = "linux" ) ]
238244 let system_tray_icon = if let Some ( tray) = & config. tauri . system_tray {
239- let mut system_tray_icon_path = tray. icon_path . clone ( ) ;
240- system_tray_icon_path. set_extension ( "png" ) ;
241- if dev {
242- let system_tray_icon_path = config_parent
243- . join ( system_tray_icon_path)
244- . display ( )
245- . to_string ( ) ;
246- quote ! ( Some ( #root:: TrayIcon :: File ( :: std:: path:: PathBuf :: from( #system_tray_icon_path) ) ) )
245+ let system_tray_icon_path = tray. icon_path . clone ( ) ;
246+ let ext = system_tray_icon_path. extension ( ) ;
247+ if ext. map_or ( false , |e| e == "ico" ) {
248+ ico_icon ( & root, & out_dir, system_tray_icon_path) ?
249+ } else if ext. map_or ( false , |e| e == "png" ) {
250+ png_icon ( & root, & out_dir, system_tray_icon_path) ?
247251 } else {
248- let system_tray_icon_file_path = system_tray_icon_path. to_string_lossy ( ) . to_string ( ) ;
249- quote ! (
250- Some (
251- #root:: TrayIcon :: File (
252- #root:: api:: path:: resolve_path(
253- & #config,
254- & #package_info,
255- & Default :: default ( ) ,
256- #system_tray_icon_file_path,
257- Some ( #root:: api:: path:: BaseDirectory :: Resource )
258- ) . expect( "failed to resolve resource dir" )
259- )
260- )
261- )
252+ quote ! ( compile_error!(
253+ "The tray icon extension must be either `.ico` or `.png`."
254+ ) )
262255 }
263256 } else {
264257 quote ! ( None )
265258 } ;
266259
267- #[ cfg( not( target_os = "linux" ) ) ]
268- let system_tray_icon = if let Some ( tray) = & config. tauri . system_tray {
269- let mut system_tray_icon_path = tray. icon_path . clone ( ) ;
270- system_tray_icon_path. set_extension ( if cfg ! ( windows) { "ico" } else { "png" } ) ;
271- let system_tray_icon_path = config_parent
272- . join ( system_tray_icon_path)
273- . display ( )
274- . to_string ( ) ;
275- quote ! ( Some ( #root:: TrayIcon :: Raw ( include_bytes!( #system_tray_icon_path) . to_vec( ) ) ) )
276- } else {
277- quote ! ( None )
278- } ;
279-
280260 #[ cfg( target_os = "macos" ) ]
281261 let info_plist = {
282262 if dev {
@@ -367,7 +347,6 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
367347 ) ) )
368348}
369349
370- #[ cfg( windows) ]
371350fn ico_icon < P : AsRef < Path > > (
372351 root : & TokenStream ,
373352 out_dir : & Path ,
@@ -378,14 +357,14 @@ fn ico_icon<P: AsRef<Path>>(
378357
379358 let path = path. as_ref ( ) ;
380359 let bytes = std:: fs:: read ( & path)
381- . unwrap_or_else ( |_| panic ! ( "failed to read window icon {}" , path. display( ) ) )
360+ . unwrap_or_else ( |_| panic ! ( "failed to read icon {}" , path. display( ) ) )
382361 . to_vec ( ) ;
383362 let icon_dir = ico:: IconDir :: read ( std:: io:: Cursor :: new ( bytes) )
384- . unwrap_or_else ( |_| panic ! ( "failed to parse window icon {}" , path. display( ) ) ) ;
363+ . unwrap_or_else ( |_| panic ! ( "failed to parse icon {}" , path. display( ) ) ) ;
385364 let entry = & icon_dir. entries ( ) [ 0 ] ;
386365 let rgba = entry
387366 . decode ( )
388- . unwrap_or_else ( |_| panic ! ( "failed to decode window icon {}" , path. display( ) ) )
367+ . unwrap_or_else ( |_| panic ! ( "failed to decode icon {}" , path. display( ) ) )
389368 . rgba_data ( )
390369 . to_vec ( ) ;
391370 let width = entry. width ( ) ;
@@ -410,7 +389,6 @@ fn ico_icon<P: AsRef<Path>>(
410389 Ok ( icon)
411390}
412391
413- #[ cfg( target_os = "linux" ) ]
414392fn png_icon < P : AsRef < Path > > (
415393 root : & TokenStream ,
416394 out_dir : & Path ,
@@ -421,12 +399,12 @@ fn png_icon<P: AsRef<Path>>(
421399
422400 let path = path. as_ref ( ) ;
423401 let bytes = std:: fs:: read ( & path)
424- . unwrap_or_else ( |_| panic ! ( "failed to read window icon {}" , path. display( ) ) )
402+ . unwrap_or_else ( |_| panic ! ( "failed to read icon {}" , path. display( ) ) )
425403 . to_vec ( ) ;
426404 let decoder = png:: Decoder :: new ( std:: io:: Cursor :: new ( bytes) ) ;
427405 let mut reader = decoder
428406 . read_info ( )
429- . unwrap_or_else ( |_| panic ! ( "failed to read window icon {}" , path. display( ) ) ) ;
407+ . unwrap_or_else ( |_| panic ! ( "failed to read icon {}" , path. display( ) ) ) ;
430408 let mut buffer: Vec < u8 > = Vec :: new ( ) ;
431409 while let Ok ( Some ( row) ) = reader. next_row ( ) {
432410 buffer. extend ( row. data ( ) ) ;
@@ -459,7 +437,7 @@ fn find_icon<F: Fn(&&String) -> bool>(
459437 config_parent : & Path ,
460438 predicate : F ,
461439 default : & str ,
462- ) -> String {
440+ ) -> PathBuf {
463441 let icon_path = config
464442 . tauri
465443 . bundle
@@ -468,7 +446,7 @@ fn find_icon<F: Fn(&&String) -> bool>(
468446 . find ( |i| predicate ( i) )
469447 . cloned ( )
470448 . unwrap_or_else ( || default. to_string ( ) ) ;
471- config_parent. join ( icon_path) . display ( ) . to_string ( )
449+ config_parent. join ( icon_path)
472450}
473451
474452#[ cfg( feature = "shell-scope" ) ]
0 commit comments