@@ -41,40 +41,17 @@ pub fn file_chooser_save_file(title: &str, default_path: Option<&str>, filter: &
4141 . save_file ( )
4242}
4343
44- pub fn load_icon < P : AsRef < std:: path:: Path > > ( path : P ) -> std:: io:: Result < tray_icon:: Icon > {
45- let ( icon_rgba, icon_width, icon_height) = {
46- let image = image:: open ( path)
47- . map_err ( |e| std:: io:: Error :: other ( format ! ( "Failed to open icon path {e}" ) ) ) ?
48- . into_rgba8 ( ) ;
49- let ( width, height) = image. dimensions ( ) ;
50- let rgba = image. into_raw ( ) ;
51- ( rgba, width, height)
52- } ;
53- tray_icon:: Icon :: from_rgba ( icon_rgba, icon_width, icon_height)
54- . map_err ( |e| std:: io:: Error :: other ( format ! ( "Failed to create tray icon: {e}" ) ) )
44+ pub fn load_icon_from_bytes ( bytes : & [ u8 ] ) -> std:: io:: Result < tray_icon:: Icon > {
45+ let image = image:: load_from_memory ( bytes)
46+ . map_err ( |e| std:: io:: Error :: other ( format ! ( "Failed to load icon from memory: {e}" ) ) ) ?
47+ . into_rgba8 ( ) ;
48+ let ( width, height) = image. dimensions ( ) ;
49+ let rgba = image. into_raw ( ) ;
50+ tray_icon:: Icon :: from_rgba ( rgba, width, height) . map_err ( |e| std:: io:: Error :: other ( format ! ( "Failed to create tray icon: {e}" ) ) )
5551}
5652
57- /// Get the path to the application icon (assets/main.png) relative to the executable.
58- pub fn get_main_icon_path ( ) -> std:: io:: Result < PathBuf > {
59- let exe_path = std:: env:: current_exe ( ) ?;
60- let exe_dir = exe_path
61- . parent ( )
62- . ok_or_else ( || std:: io:: Error :: other ( "Failed to get executable directory" ) ) ?;
63- let icon_path = exe_dir. join ( "assets" ) . join ( "main.png" ) ;
64- if icon_path. exists ( ) {
65- Ok ( icon_path)
66- } else {
67- Err ( std:: io:: Error :: other ( format ! ( "Icon file not found at {icon_path:?}" ) ) )
68- }
69- }
53+ pub const MAIN_ICON_BYTES : & [ u8 ] = include_bytes ! ( "../assets/main.png" ) ;
7054
71- pub fn set_window_icon < P : AsRef < std:: path:: Path > > ( window : & mut fltk:: window:: Window , icon_path : P ) -> std:: io:: Result < ( ) > {
72- let mut f = std:: fs:: File :: open ( icon_path. as_ref ( ) ) ?;
73- use std:: io:: Read ;
74- let mut buf = Vec :: new ( ) ;
75- f. read_to_end ( & mut buf) ?;
76- let png = fltk:: image:: PngImage :: from_data ( & buf) . map_err ( |e| std:: io:: Error :: other ( format ! ( "Failed to load icon data: {e}" ) ) ) ?;
77- use fltk:: prelude:: WindowExt ;
78- window. set_icon ( Some ( png) ) ;
79- Ok ( ( ) )
55+ pub fn get_embedded_main_icon ( ) -> std:: io:: Result < fltk:: image:: PngImage > {
56+ fltk:: image:: PngImage :: from_data ( MAIN_ICON_BYTES ) . map_err ( |e| std:: io:: Error :: other ( format ! ( "Failed to load embedded icon: {e}" ) ) )
8057}
0 commit comments