Better APK cleanup

This commit is contained in:
Imran Remtulla
2023-05-12 17:53:07 -04:00
parent 65ab72ba90
commit 0673e90dff

View File

@@ -122,10 +122,13 @@ class AppsProvider with ChangeNotifier {
// Load Apps into memory (in background, this is done later instead of in the constructor) // Load Apps into memory (in background, this is done later instead of in the constructor)
await loadApps(); await loadApps();
// Delete any partial APKs // Delete any partial APKs
var cutoff = DateTime.now().subtract(const Duration(days: 7));
(await getExternalCacheDirectories()) (await getExternalCacheDirectories())
?.first ?.first
.listSync() .listSync()
.where((element) => element.path.endsWith('.apk.part')) .where((element) =>
element.path.endsWith('.part') ||
element.statSync().modified.isBefore(cutoff))
.forEach((partialApk) { .forEach((partialApk) {
partialApk.delete(); partialApk.delete();
}); });
@@ -786,11 +789,18 @@ class AppsProvider with ChangeNotifier {
} }
Future<void> removeApps(List<String> appIds) async { Future<void> removeApps(List<String> appIds) async {
var apkFiles = (await getExternalCacheDirectories())?.first.listSync();
for (var appId in appIds) { for (var appId in appIds) {
File file = File('${(await getAppsDir()).path}/$appId.json'); File file = File('${(await getAppsDir()).path}/$appId.json');
if (file.existsSync()) { if (file.existsSync()) {
file.deleteSync(); file.deleteSync();
} }
apkFiles
?.where(
(element) => element.path.split('/').last.startsWith('$appId-'))
.forEach((element) {
element.delete();
});
if (apps.containsKey(appId)) { if (apps.containsKey(appId)) {
apps.remove(appId); apps.remove(appId);
} }