@@ -3,6 +3,7 @@ use iced::widget::{
33} ;
44use iced:: { Alignment , Center , Element , Fill , Task } ;
55use plume_utils:: { Package , PlistInfoTrait , SignerInstallMode , SignerMode , SignerOptions } ;
6+ use std:: path:: PathBuf ;
67
78use crate :: appearance;
89
@@ -37,13 +38,29 @@ pub enum Message {
3738pub struct PackageScreen {
3839 pub selected_package : Option < Package > ,
3940 pub options : SignerOptions ,
41+ package_icon_handle : Option < image:: Handle > ,
42+ custom_icon_path : Option < PathBuf > ,
43+ custom_icon_handle : Option < image:: Handle > ,
4044}
4145
4246impl PackageScreen {
4347 pub fn new ( package : Option < Package > , options : SignerOptions ) -> Self {
48+ let package_icon_handle = package
49+ . as_ref ( )
50+ . and_then ( |p| p. app_icon_data . as_ref ( ) )
51+ . map ( |data| image:: Handle :: from_bytes ( data. clone ( ) ) ) ;
52+
53+ let custom_icon_path = options. custom_icon . clone ( ) ;
54+ let custom_icon_handle = custom_icon_path
55+ . as_ref ( )
56+ . map ( |path| image:: Handle :: from_path ( path. clone ( ) ) ) ;
57+
4458 Self {
4559 selected_package : package,
4660 options,
61+ package_icon_handle,
62+ custom_icon_path,
63+ custom_icon_handle,
4764 }
4865 }
4966
@@ -183,13 +200,17 @@ impl PackageScreen {
183200 . pick_file ( ) ;
184201
185202 if let Some ( path) = path {
186- self . options . custom_icon = Some ( path) ;
203+ self . options . custom_icon = Some ( path. clone ( ) ) ;
204+ self . custom_icon_path = Some ( path. clone ( ) ) ;
205+ self . custom_icon_handle = Some ( image:: Handle :: from_path ( path) ) ;
187206 }
188207
189208 Task :: none ( )
190209 }
191210 Message :: ClearCustomIcon => {
192211 self . options . custom_icon = None ;
212+ self . custom_icon_path = None ;
213+ self . custom_icon_handle = None ;
193214 Task :: none ( )
194215 }
195216 Message :: SetCustomEntitlements => {
@@ -417,7 +438,7 @@ impl PackageScreen {
417438 }
418439
419440 fn view_custom_icon ( & self ) -> Element < ' _ , Message > {
420- let has_custom = self . options . custom_icon . is_some ( ) ;
441+ let has_custom = self . custom_icon_path . is_some ( ) ;
421442
422443 const ICON_SIZE : f32 = 56.0 ;
423444
@@ -427,23 +448,19 @@ impl PackageScreen {
427448 . align_x ( Center )
428449 . align_y ( Center ) ;
429450
430- let preview: Element < ' _ , Message > = if let Some ( path ) = & self . options . custom_icon {
451+ let preview: Element < ' _ , Message > = if let Some ( handle ) = & self . custom_icon_handle {
431452 stack ! [
432453 loading_indicator,
433- image( image :: Handle :: from_path ( path ) )
454+ image( handle . clone ( ) )
434455 . width( ICON_SIZE )
435456 . height( ICON_SIZE )
436457 . border_radius( appearance:: THEME_CORNER_RADIUS )
437458 ]
438459 . into ( )
439- } else if let Some ( data) = self
440- . selected_package
441- . as_ref ( )
442- . and_then ( |p| p. app_icon_data . as_deref ( ) )
443- {
460+ } else if let Some ( handle) = & self . package_icon_handle {
444461 stack ! [
445462 loading_indicator,
446- image( image :: Handle :: from_bytes ( data . to_vec ( ) ) )
463+ image( handle . clone ( ) )
447464 . width( ICON_SIZE )
448465 . height( ICON_SIZE )
449466 . border_radius( appearance:: THEME_CORNER_RADIUS )
0 commit comments