diff --git a/lib/ui/views/app_selector/app_selector_viewmodel.dart b/lib/ui/views/app_selector/app_selector_viewmodel.dart index 55403b8af6..d59385118a 100644 --- a/lib/ui/views/app_selector/app_selector_viewmodel.dart +++ b/lib/ui/views/app_selector/app_selector_viewmodel.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:device_apps/device_apps.dart'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:revanced_manager/app/app.locator.dart'; import 'package:revanced_manager/models/patched_application.dart'; import 'package:revanced_manager/services/patcher_api.dart'; @@ -45,6 +46,11 @@ class AppSelectorViewModel extends BaseViewModel { ); if (result != null && result.files.single.path != null) { File apkFile = File(result.files.single.path!); + List pathSplit = result.files.single.path!.split("/"); + pathSplit.removeLast(); + Directory filePickerCacheDir = Directory(pathSplit.join("/")); + Iterable deletableFiles = (await filePickerCacheDir.list().toList()).whereType(); + for (var file in deletableFiles) { if (file.path != apkFile.path && file.path.endsWith(".apk")) file.delete(); } ApplicationWithIcon? application = await DeviceApps.getAppFromStorage( apkFile.path, true,