@@ -16,8 +16,8 @@ use tauri_runtime::{
1616 dpi:: { LogicalPosition , LogicalSize , PhysicalPosition , PhysicalSize , Position , Size } ,
1717 DetachedWindow , JsEventListenerKey , PendingWindow , WindowEvent ,
1818 } ,
19- ClipboardManager , Dispatch , Error , ExitRequestedEventAction , GlobalShortcutManager , Icon , Result ,
20- RunEvent , RunIteration , Runtime , RuntimeHandle , UserAttentionType ,
19+ ClipboardManager , Dispatch , Error , ExitRequestedEventAction , GlobalShortcutManager , Result ,
20+ RunEvent , RunIteration , Runtime , RuntimeHandle , UserAttentionType , WindowIcon ,
2121} ;
2222
2323use tauri_runtime:: window:: MenuEvent ;
@@ -56,7 +56,7 @@ use wry::{
5656 MenuItemAttributes as WryMenuItemAttributes , MenuType ,
5757 } ,
5858 monitor:: MonitorHandle ,
59- window:: { Fullscreen , Icon as WindowIcon , UserAttentionType as WryUserAttentionType } ,
59+ window:: { Fullscreen , Icon as WryWindowIcon , UserAttentionType as WryUserAttentionType } ,
6060 } ,
6161 http:: {
6262 Request as WryHttpRequest , RequestParts as WryRequestParts , Response as WryHttpResponse ,
@@ -84,7 +84,6 @@ use std::{
8484 HashMap , HashSet ,
8585 } ,
8686 fmt,
87- fs:: read,
8887 ops:: Deref ,
8988 path:: PathBuf ,
9089 sync:: {
@@ -482,52 +481,18 @@ impl ClipboardManager for ClipboardManagerWrapper {
482481}
483482
484483/// Wrapper around a [`wry::application::window::Icon`] that can be created from an [`Icon`].
485- pub struct WryIcon ( WindowIcon ) ;
484+ pub struct WryIcon ( WryWindowIcon ) ;
486485
487486fn icon_err < E : std:: error:: Error + Send + ' static > ( e : E ) -> Error {
488487 Error :: InvalidIcon ( Box :: new ( e) )
489488}
490489
491- impl TryFrom < Icon > for WryIcon {
490+ impl TryFrom < WindowIcon > for WryIcon {
492491 type Error = Error ;
493- fn try_from ( icon : Icon ) -> std:: result:: Result < Self , Self :: Error > {
494- let image_bytes = match icon {
495- Icon :: File ( path) => read ( path) . map_err ( icon_err) ?,
496- Icon :: Raw ( raw) => raw,
497- _ => unimplemented ! ( ) ,
498- } ;
499- let extension = infer:: get ( & image_bytes)
500- . expect ( "could not determine icon extension" )
501- . extension ( ) ;
502- match extension {
503- #[ cfg( windows) ]
504- "ico" => {
505- let icon_dir = ico:: IconDir :: read ( std:: io:: Cursor :: new ( image_bytes) ) . map_err ( icon_err) ?;
506- let entry = & icon_dir. entries ( ) [ 0 ] ;
507- let icon = WindowIcon :: from_rgba (
508- entry. decode ( ) . map_err ( icon_err) ?. rgba_data ( ) . to_vec ( ) ,
509- entry. width ( ) ,
510- entry. height ( ) ,
511- )
512- . map_err ( icon_err) ?;
513- Ok ( Self ( icon) )
514- }
515- #[ cfg( target_os = "linux" ) ]
516- "png" => {
517- let decoder = png:: Decoder :: new ( std:: io:: Cursor :: new ( image_bytes) ) ;
518- let ( info, mut reader) = decoder. read_info ( ) . map_err ( icon_err) ?;
519- let mut buffer = Vec :: new ( ) ;
520- while let Ok ( Some ( row) ) = reader. next_row ( ) {
521- buffer. extend ( row) ;
522- }
523- let icon = WindowIcon :: from_rgba ( buffer, info. width , info. height ) . map_err ( icon_err) ?;
524- Ok ( Self ( icon) )
525- }
526- _ => panic ! (
527- "image `{}` extension not supported; please file a Tauri feature request" ,
528- extension
529- ) ,
530- }
492+ fn try_from ( icon : WindowIcon ) -> std:: result:: Result < Self , Self :: Error > {
493+ WryWindowIcon :: from_rgba ( icon. rgba , icon. width , icon. height )
494+ . map ( Self )
495+ . map_err ( icon_err)
531496 }
532497}
533498
@@ -851,7 +816,7 @@ impl WindowBuilder for WindowBuilderWrapper {
851816 self
852817 }
853818
854- fn icon ( mut self , icon : Icon ) -> Result < Self > {
819+ fn icon ( mut self , icon : WindowIcon ) -> Result < Self > {
855820 self . inner = self
856821 . inner
857822 . with_window_icon ( Some ( WryIcon :: try_from ( icon) ?. 0 ) ) ;
@@ -975,7 +940,7 @@ pub enum WindowMessage {
975940 SetPosition ( Position ) ,
976941 SetFullscreen ( bool ) ,
977942 SetFocus ,
978- SetIcon ( WindowIcon ) ,
943+ SetIcon ( WryWindowIcon ) ,
979944 SetSkipTaskbar ( bool ) ,
980945 DragWindow ,
981946 UpdateMenuItem ( u16 , MenuUpdate ) ,
@@ -1001,7 +966,7 @@ pub enum WebviewEvent {
1001966pub enum TrayMessage {
1002967 UpdateItem ( u16 , MenuUpdate ) ,
1003968 UpdateMenu ( SystemTrayMenu ) ,
1004- UpdateIcon ( Icon ) ,
969+ UpdateIcon ( TrayIcon ) ,
1005970 #[ cfg( target_os = "macos" ) ]
1006971 UpdateIconAsTemplate ( bool ) ,
1007972 Close ,
@@ -1392,7 +1357,7 @@ impl Dispatch for WryDispatcher {
13921357 )
13931358 }
13941359
1395- fn set_icon ( & self , icon : Icon ) -> Result < ( ) > {
1360+ fn set_icon ( & self , icon : WindowIcon ) -> Result < ( ) > {
13961361 send_user_message (
13971362 & self . context ,
13981363 Message :: Window (
@@ -1790,7 +1755,7 @@ impl Runtime for Wry {
17901755 let icon = system_tray
17911756 . icon
17921757 . expect ( "tray icon not set" )
1793- . into_tray_icon ( ) ;
1758+ . into_platform_icon ( ) ;
17941759
17951760 let mut items = HashMap :: new ( ) ;
17961761
@@ -2208,7 +2173,7 @@ fn handle_user_message(
22082173 }
22092174 TrayMessage :: UpdateIcon ( icon) => {
22102175 if let Some ( tray) = & * tray_context. tray . lock ( ) . unwrap ( ) {
2211- tray. lock ( ) . unwrap ( ) . set_icon ( icon. into_tray_icon ( ) ) ;
2176+ tray. lock ( ) . unwrap ( ) . set_icon ( icon. into_platform_icon ( ) ) ;
22122177 }
22132178 }
22142179 #[ cfg( target_os = "macos" ) ]
0 commit comments