@@ -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 ;
@@ -4038,16 +4058,70 @@ impl Application for App {
40384058 widget:: button:: standard ( fl ! ( "cancel" ) ) . on_press ( Message :: DialogCancel ) ,
40394059 )
40404060 }
4041- DialogPage :: Uninstall ( _backend_name, _id, info) => widget:: dialog ( )
4042- . title ( fl ! ( "uninstall-app" , name = info. name. as_str( ) ) )
4043- . body ( fl ! ( "uninstall-app-warning" , name = info. name. as_str( ) ) )
4044- . icon ( widget:: icon:: from_name ( Self :: APP_ID ) . size ( 64 ) )
4045- . primary_action (
4046- widget:: button:: destructive ( fl ! ( "uninstall" ) ) . on_press ( Message :: DialogConfirm ) ,
4047- )
4048- . secondary_action (
4049- widget:: button:: standard ( fl ! ( "cancel" ) ) . on_press ( Message :: DialogCancel ) ,
4050- ) ,
4061+ DialogPage :: Uninstall ( backend_name, _id, info) => {
4062+ let is_flatpak = backend_name. starts_with ( "flatpak" ) ;
4063+ let mut dialog = widget:: dialog ( )
4064+ . title ( fl ! ( "uninstall-app" , name = info. name. as_str( ) ) )
4065+ . body ( if is_flatpak {
4066+ fl ! ( "uninstall-app-flatpak-warning" )
4067+ } else {
4068+ fl ! ( "uninstall-app-warning" , name = info. name. as_str( ) )
4069+ } )
4070+ . icon ( widget:: icon:: from_name ( Self :: APP_ID ) . size ( 64 ) ) ;
4071+
4072+ // Only show data options for Flatpak apps
4073+ if is_flatpak {
4074+ dialog = dialog. control (
4075+ widget:: column:: with_capacity ( 4 )
4076+ . spacing ( 12 )
4077+ . push ( widget:: text:: heading ( fl ! ( "app-settings-data" ) ) )
4078+ . push (
4079+ widget:: column:: with_capacity ( 2 )
4080+ . spacing ( 4 )
4081+ . push (
4082+ widget:: radio (
4083+ widget:: text:: body ( fl ! ( "keep-app-data" ) ) ,
4084+ false ,
4085+ Some ( self . uninstall_purge_data ) ,
4086+ Message :: ToggleUninstallPurgeData ,
4087+ )
4088+ )
4089+ . push (
4090+ widget:: container (
4091+ widget:: text:: caption ( fl ! ( "keep-app-data-description" ) )
4092+ )
4093+ . padding ( [ 0 , 0 , 0 , 24 ] )
4094+ )
4095+ )
4096+ . push (
4097+ widget:: column:: with_capacity ( 2 )
4098+ . spacing ( 4 )
4099+ . push (
4100+ widget:: radio (
4101+ widget:: text:: body ( fl ! ( "delete-app-data" ) ) ,
4102+ true ,
4103+ Some ( self . uninstall_purge_data ) ,
4104+ Message :: ToggleUninstallPurgeData ,
4105+ )
4106+ )
4107+ . push (
4108+ widget:: container (
4109+ widget:: text:: caption ( fl ! ( "delete-app-data-description" ) )
4110+ )
4111+ . padding ( [ 0 , 0 , 0 , 24 ] )
4112+ )
4113+ )
4114+ ) ;
4115+ }
4116+
4117+ dialog
4118+ . primary_action (
4119+ widget:: button:: destructive ( fl ! ( "uninstall" ) ) . on_press ( Message :: DialogConfirm ) ,
4120+ )
4121+ . secondary_action (
4122+ widget:: button:: standard ( fl ! ( "cancel" ) ) . on_press ( Message :: DialogCancel ) ,
4123+ )
4124+ }
40514125 DialogPage :: Place ( id) => widget:: dialog ( )
40524126 . title ( fl ! ( "place-applet" ) )
40534127 . body ( fl ! ( "place-applet-desc" ) )
0 commit comments