Skip to content

Commit d37d3e4

Browse files
committed
Improve bloatware list loading and form initialization
Refactored bloatware list loading to handle user declining downloads and prevent repeated initialization. Changed form event from Shown to Load for better initialization timing. Improved error handling and user feedback when the bloatware list is missing.
1 parent e3385b8 commit d37d3e4

File tree

3 files changed

+36
-28
lines changed

3 files changed

+36
-28
lines changed

ATA-GUI/Classes/ATA.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace ATA_GUI.Classes
1111
{
1212
internal class ATA
1313
{
14-
public static readonly string CURRENTVERSION = "v3.14.3";
14+
public static readonly string CURRENTVERSION = "v3.15.0";
1515
public static readonly string IPFileName = "IPList.txt";
1616

1717
public HashSet<string> IPList { get; } = new HashSet<string>();

ATA-GUI/Forms/BloatwareRemoverForm.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ATA-GUI/Forms/BloatwareRemoverForm.cs

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)