@@ -12,7 +12,7 @@ use cosmic::{
1212 core:: SmolStr ,
1313 event:: { self , Event } ,
1414 futures:: { self , SinkExt } ,
15- keyboard:: { Event as KeyEvent , Key , Modifiers } ,
15+ keyboard:: { Event as KeyEvent , Key , Modifiers , key } ,
1616 stream,
1717 widget:: scrollable,
1818 window:: { self , Event as WindowEvent } ,
@@ -312,6 +312,7 @@ pub enum Message {
312312 SelectedAddonsViewMore ( bool ) ,
313313 SelectedScreenshot ( usize , String , Vec < u8 > ) ,
314314 SelectedScreenshotShown ( usize ) ,
315+ ToggleUninstallPurgeData ( bool ) ,
315316 SelectedSource ( usize ) ,
316317 SystemThemeModeChange ( cosmic_theme:: ThemeMode ) ,
317318 ToggleContextPage ( ContextPage ) ,
@@ -824,6 +825,7 @@ pub struct App {
824825 search_results : Option < ( String , Vec < SearchResult > ) > ,
825826 selected_opt : Option < Selected > ,
826827 applet_placement_buttons : cosmic:: widget:: segmented_button:: SingleSelectModel ,
828+ uninstall_purge_data : bool ,
827829}
828830
829831impl App {
@@ -3041,6 +3043,7 @@ impl Application for App {
30413043 search_results : None ,
30423044 selected_opt : None ,
30433045 applet_placement_buttons,
3046+ uninstall_purge_data : false ,
30443047 } ;
30453048
30463049 if let Some ( subcommand) = flags. subcommand_opt {
@@ -3205,6 +3208,7 @@ impl Application for App {
32053208 }
32063209 Message :: DialogCancel => {
32073210 self . dialog_pages . pop_front ( ) ;
3211+ self . uninstall_purge_data = false ;
32083212 }
32093213 Message :: DialogConfirm => match self . dialog_pages . pop_front ( ) {
32103214 Some ( DialogPage :: RepositoryRemove ( backend_name, repo_rm) ) => {
@@ -3216,8 +3220,10 @@ impl Application for App {
32163220 } ) ;
32173221 }
32183222 Some ( DialogPage :: Uninstall ( backend_name, id, info) ) => {
3223+ let purge_data = self . uninstall_purge_data ;
3224+ self . uninstall_purge_data = false ;
32193225 return self . update ( Message :: Operation (
3220- OperationKind :: Uninstall ,
3226+ OperationKind :: Uninstall { purge_data } ,
32213227 backend_name,
32223228 id,
32233229 info,
@@ -3260,7 +3266,7 @@ impl Application for App {
32603266 ) ;
32613267 if installed != selected. contains ( & i) {
32623268 let kind = if installed {
3263- OperationKind :: Uninstall
3269+ OperationKind :: Uninstall { purge_data : false }
32643270 } else {
32653271 OperationKind :: Install
32663272 } ;
@@ -3325,6 +3331,17 @@ impl Application for App {
33253331 self . installed_results = Some ( installed_results) ;
33263332 }
33273333 Message :: Key ( modifiers, key, text) => {
3334+ // Handle ESC key to close dialogs
3335+ if !self . dialog_pages . is_empty ( )
3336+ && matches ! ( key, Key :: Named ( key:: Named :: Escape ) )
3337+ && !modifiers. logo ( )
3338+ && !modifiers. control ( )
3339+ && !modifiers. alt ( )
3340+ && !modifiers. shift ( )
3341+ {
3342+ return self . update ( Message :: DialogCancel ) ;
3343+ }
3344+
33283345 for ( key_bind, action) in self . key_binds . iter ( ) {
33293346 if key_bind. matches ( modifiers, & key) {
33303347 return self . update ( action. message ( ) ) ;
@@ -3733,6 +3750,9 @@ impl Application for App {
37333750 selected. screenshot_shown = i;
37343751 }
37353752 }
3753+ Message :: ToggleUninstallPurgeData ( value) => {
3754+ self . uninstall_purge_data = value;
3755+ }
37363756 Message :: SelectedSource ( i) => {
37373757 //TODO: show warnings if anything is not found?
37383758 let mut next_ids = None ;
@@ -4041,16 +4061,36 @@ impl Application for App {
40414061 widget:: button:: standard ( fl ! ( "cancel" ) ) . on_press ( Message :: DialogCancel ) ,
40424062 )
40434063 }
4044- DialogPage :: Uninstall ( _backend_name, _id, info) => widget:: dialog ( )
4045- . title ( fl ! ( "uninstall-app" , name = info. name. as_str( ) ) )
4046- . body ( fl ! ( "uninstall-app-warning" , name = info. name. as_str( ) ) )
4047- . icon ( widget:: icon:: from_name ( Self :: APP_ID ) . size ( 64 ) )
4048- . primary_action (
4049- widget:: button:: destructive ( fl ! ( "uninstall" ) ) . on_press ( Message :: DialogConfirm ) ,
4050- )
4051- . secondary_action (
4052- widget:: button:: standard ( fl ! ( "cancel" ) ) . on_press ( Message :: DialogCancel ) ,
4053- ) ,
4064+ DialogPage :: Uninstall ( backend_name, _id, info) => {
4065+ let is_flatpak = backend_name. starts_with ( "flatpak" ) ;
4066+ let mut dialog = widget:: dialog ( )
4067+ . title ( fl ! ( "uninstall-app" , name = info. name. as_str( ) ) )
4068+ . body ( if is_flatpak {
4069+ fl ! ( "uninstall-app-flatpak-warning" , name = info. name. as_str( ) )
4070+ } else {
4071+ fl ! ( "uninstall-app-warning" , name = info. name. as_str( ) )
4072+ } )
4073+ . icon ( widget:: icon:: from_name ( Self :: APP_ID ) . size ( 64 ) ) ;
4074+
4075+ // Only show data deletion option for Flatpak apps
4076+ if is_flatpak {
4077+ dialog = dialog. control (
4078+ widget:: checkbox (
4079+ fl ! ( "delete-app-data" ) ,
4080+ self . uninstall_purge_data ,
4081+ )
4082+ . on_toggle ( Message :: ToggleUninstallPurgeData )
4083+ ) ;
4084+ }
4085+
4086+ dialog
4087+ . primary_action (
4088+ widget:: button:: destructive ( fl ! ( "uninstall" ) ) . on_press ( Message :: DialogConfirm ) ,
4089+ )
4090+ . secondary_action (
4091+ widget:: button:: standard ( fl ! ( "cancel" ) ) . on_press ( Message :: DialogCancel ) ,
4092+ )
4093+ }
40544094 DialogPage :: Place ( id) => widget:: dialog ( )
40554095 . title ( fl ! ( "place-applet" ) )
40564096 . body ( fl ! ( "place-applet-desc" ) )
0 commit comments