fix: Load installed apps

This commit is contained in:
oSumAtrIX 2023-09-30 19:59:31 +02:00
parent 6bdc0c7bb2
commit 36c86e22b1
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
3 changed files with 35 additions and 40 deletions

View File

@ -94,7 +94,6 @@ class MainActivity : FlutterActivity() {
val patchBundleFilePath = call.argument<String>("patchBundleFilePath")!!
val cacheDirPath = call.argument<String>("cacheDirPath")!!
JSONArray().apply {
try {
PatchBundleLoader.Dex(

View File

@ -42,12 +42,14 @@ class ManagerAPI {
String defaultManagerRepo = 'revanced/revanced-manager';
String? patchesVersion = '';
String? integrationsVersion = '';
bool isDefaultPatchesRepo() {
return getPatchesRepo().toLowerCase() == 'revanced/revanced-patches';
}
bool isDefaultIntegrationsRepo() {
return getIntegrationsRepo().toLowerCase() == 'revanced/revanced-integrations';
return getIntegrationsRepo().toLowerCase() ==
'revanced/revanced-integrations';
}
Future<void> initialize() async {
@ -324,7 +326,9 @@ class ManagerAPI {
);
final List<dynamic> patchesJsonList = jsonDecode(patchesJson);
patches = patchesJsonList.map((patchJson) => Patch.fromJson(patchJson)).toList();
patches = patchesJsonList
.map((patchJson) => Patch.fromJson(patchJson))
.toList();
return patches;
} on Exception catch (e) {
if (kDebugMode) {
@ -501,21 +505,18 @@ class ManagerAPI {
return toRemove;
}
Future<List<PatchedApplication>> getUnsavedApps(
List<PatchedApplication> patchedApps,
) async {
final List<PatchedApplication> unsavedApps = [];
Future<List<PatchedApplication>> getMountedApps() async {
final List<PatchedApplication> mountedApps = [];
final bool hasRootPermissions = await _rootAPI.hasRootPermissions();
if (hasRootPermissions) {
final List<String> installedApps = await _rootAPI.getInstalledApps();
for (final String packageName in installedApps) {
if (!patchedApps.any((app) => app.packageName == packageName)) {
final ApplicationWithIcon? application = await DeviceApps.getApp(
packageName,
true,
) as ApplicationWithIcon?;
if (application != null) {
unsavedApps.add(
mountedApps.add(
PatchedApplication(
name: application.appName,
packageName: application.packageName,
@ -530,33 +531,8 @@ class ManagerAPI {
}
}
}
}
final List<Application> userApps =
await DeviceApps.getInstalledApplications();
for (final Application app in userApps) {
if (app.packageName.startsWith('app.revanced') &&
!app.packageName.startsWith('app.revanced.manager.') &&
!patchedApps.any((uapp) => uapp.packageName == app.packageName)) {
final ApplicationWithIcon? application = await DeviceApps.getApp(
app.packageName,
true,
) as ApplicationWithIcon?;
if (application != null) {
unsavedApps.add(
PatchedApplication(
name: application.appName,
packageName: application.packageName,
originalPackageName: application.packageName,
version: application.versionName!,
apkFilePath: application.apkFilePath,
icon: application.icon,
patchDate: DateTime.now(),
),
);
}
}
}
return unsavedApps;
return mountedApps;
}
Future<void> showPatchesChangeWarningDialog(BuildContext context) {
@ -616,6 +592,25 @@ class ManagerAPI {
);
}
Future<void> reAssessSavedApps() async {
final List<PatchedApplication> patchedApps = getPatchedApps();
// Remove apps that are not installed anymore.
final List<PatchedApplication> toRemove =
await getAppsToRemove(patchedApps);
patchedApps.removeWhere((a) => toRemove.contains(a));
// Determine all apps that are installed by mounting.
final List<PatchedApplication> mountedApps = await getMountedApps();
mountedApps.removeWhere(
(app) => patchedApps
.any((patchedApp) => patchedApp.packageName == app.packageName),
);
patchedApps.addAll(mountedApps);
await setPatchedApps(patchedApps);
}
Future<bool> isAppUninstalled(PatchedApplication app) async {
bool existsRoot = false;
final bool existsNonRoot = await DeviceApps.isAppInstalled(app.packageName);

View File

@ -81,7 +81,8 @@ class HomeViewModel extends BaseViewModel {
_toast.showBottom('homeView.errorDownloadMessage');
}
}
_getPatchedApps();
_managerAPI.reAssessSavedApps().then((_) => _getPatchedApps());
}
void navigateToAppInfo(PatchedApplication app) {