mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-18 04:38:10 +02:00
Better APK cleanup
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user