@@ -23,6 +23,9 @@ public partial class BloatwareRemoverForm : Form
2323
2424 public string CurrentDevice { get ; set ; }
2525
26+ private bool initializationComplete = false ;
27+ private bool userDeclinedDownload = false ;
28+
2629 public BloatwareRemoverForm ( List < string > nonSystemApp , List < string > systemApp )
2730 {
2831 InitializeComponent ( ) ;
@@ -70,19 +73,6 @@ private bool IsValidPackageName(string packageName)
7073 return true ;
7174 }
7275
73- private async void BloatwareRemover_Shown ( object sender , EventArgs e )
74- {
75- comboBoxActionMode . SelectedIndex = 0 ;
76- comboBoxScanLevel . SelectedIndex = 0 ;
77-
78- // Configure the DataGridView for optimal display
79- ConfigureDataGridView ( ) ;
80-
81- await LoadAppAsync ( ) ;
82- MainForm . MessageShowBox ( "Warning: Be careful before disabling/removing any system app or service. You must ensure that the package is not used by system " +
83- "to function. Disabling a critical system app may result in bricking your phone. So always double check before disabling/removing any system app." , 1 ) ;
84- }
85-
8676 private void ConfigureDataGridView ( )
8777 {
8878 // Set up the DataGridView for better display of multiline content
@@ -102,15 +92,19 @@ private void ConfigureDataGridView()
10292 }
10393
10494
105- private async Task LoadAppAsync ( )
95+ private async Task < bool > LoadAppAsync ( )
10696 {
97+ if ( initializationComplete )
98+ return true ;
99+
100+ if ( userDeclinedDownload )
101+ return false ;
102+
107103 string jsonFilePath = Path . Combine ( Application . StartupPath , "uad_lists.json" ) ;
108104 JObject json = null ;
109105
110- // Check if the file exists locally
111106 if ( ! File . Exists ( jsonFilePath ) )
112107 {
113- // Ask user if they want to download the file using a simple dialog
114108 DialogResult result = MessageBox . Show (
115109 "The bloatware list file was not found. Would you like to download it from the Universal Android Debloater repository?" ,
116110 "Download Bloatware List" ,
@@ -119,18 +113,16 @@ private async Task LoadAppAsync()
119113
120114 if ( result == DialogResult . Yes )
121115 {
122- // Download the file
123116 await DownloadBloatwareListAsync ( jsonFilePath ) ;
124117 }
125118 else
126119 {
127- // If user declines, show error message
128120 MainForm . MessageShowBox ( "Cannot proceed without bloatware list. Please ensure the file is available or allow download." , 0 ) ;
129- return ;
121+ userDeclinedDownload = true ;
122+ return false ;
130123 }
131124 }
132125
133- // If we haven't loaded JSON yet (because file was downloaded or user declined download)
134126 if ( json == null && File . Exists ( jsonFilePath ) )
135127 {
136128 string jsonString = File . ReadAllText ( jsonFilePath ) ;
@@ -139,12 +131,12 @@ private async Task LoadAppAsync()
139131
140132 if ( json == null || ! File . Exists ( jsonFilePath ) )
141133 {
142- // If still no JSON, show error and return
143134 MainForm . MessageShowBox ( "Could not load bloatware list. The application may not function properly." , 0 ) ;
144- return ;
135+ return false ;
145136 }
146137
147- // Run the rest of the processing on a background thread
138+ initializationComplete = true ;
139+
148140 await Task . Run ( ( ) =>
149141 {
150142 try
@@ -208,7 +200,7 @@ await Task.Run(() =>
208200 {
209201 MainForm . MessageShowBox ( "Error, this value can't be set" , 0 ) ;
210202 } ) ) ;
211- return ;
203+ return ; // This return is for the anonymous method, not the main method
212204 }
213205
214206 if ( includePackage &&
@@ -296,6 +288,7 @@ await Task.Run(() =>
296288 } ) ) ;
297289 }
298290 } ) ;
291+ return true ;
299292 }
300293
301294 private async Task DownloadBloatwareListAsync ( string filePath )
@@ -403,7 +396,10 @@ private void buttonAction_Click(object sender, EventArgs e)
403396 private async void comboBoxScanLevel_SelectedIndexChanged ( object sender , EventArgs e )
404397 {
405398 checkBoxSelectAll . Checked = false ;
406- await LoadAppAsync ( ) ;
399+ if ( await LoadAppAsync ( ) == false )
400+ {
401+ this . Close ( ) ;
402+ }
407403 }
408404
409405 private void checkBoxSelectAll_CheckedChanged ( object sender , EventArgs e )
@@ -459,12 +455,24 @@ private void textBoxSearch_TextChanged(object sender, EventArgs e)
459455
460456 public async void RefreshList ( )
461457 {
462- await LoadAppAsync ( ) ;
458+ if ( await LoadAppAsync ( ) == false )
459+ {
460+ this . Close ( ) ;
461+ }
463462 }
464463
465464 private void dataGridViewBloatwareList_SelectionChanged ( object sender , EventArgs e )
466465 {
467466 setWantedRows ( ) ;
468467 }
468+
469+ private void BloatwareRemoverForm_Load ( object sender , EventArgs e )
470+ {
471+ comboBoxActionMode . SelectedIndex = 0 ;
472+ comboBoxScanLevel . SelectedIndex = 0 ;
473+
474+ // Configure the DataGridView for optimal display
475+ ConfigureDataGridView ( ) ;
476+ }
469477 }
470478}
0 commit comments