mirror of
https://github.com/revanced/revanced-manager
synced 2024-05-14 13:56:57 +02:00
fix: Load installed apps
This commit is contained in:
parent
6bdc0c7bb2
commit
36c86e22b1
@ -94,7 +94,6 @@ class MainActivity : FlutterActivity() {
|
|||||||
val patchBundleFilePath = call.argument<String>("patchBundleFilePath")!!
|
val patchBundleFilePath = call.argument<String>("patchBundleFilePath")!!
|
||||||
val cacheDirPath = call.argument<String>("cacheDirPath")!!
|
val cacheDirPath = call.argument<String>("cacheDirPath")!!
|
||||||
|
|
||||||
|
|
||||||
JSONArray().apply {
|
JSONArray().apply {
|
||||||
try {
|
try {
|
||||||
PatchBundleLoader.Dex(
|
PatchBundleLoader.Dex(
|
||||||
|
@ -42,12 +42,14 @@ class ManagerAPI {
|
|||||||
String defaultManagerRepo = 'revanced/revanced-manager';
|
String defaultManagerRepo = 'revanced/revanced-manager';
|
||||||
String? patchesVersion = '';
|
String? patchesVersion = '';
|
||||||
String? integrationsVersion = '';
|
String? integrationsVersion = '';
|
||||||
|
|
||||||
bool isDefaultPatchesRepo() {
|
bool isDefaultPatchesRepo() {
|
||||||
return getPatchesRepo().toLowerCase() == 'revanced/revanced-patches';
|
return getPatchesRepo().toLowerCase() == 'revanced/revanced-patches';
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isDefaultIntegrationsRepo() {
|
bool isDefaultIntegrationsRepo() {
|
||||||
return getIntegrationsRepo().toLowerCase() == 'revanced/revanced-integrations';
|
return getIntegrationsRepo().toLowerCase() ==
|
||||||
|
'revanced/revanced-integrations';
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> initialize() async {
|
Future<void> initialize() async {
|
||||||
@ -309,7 +311,7 @@ class ManagerAPI {
|
|||||||
final Directory appCache = await getTemporaryDirectory();
|
final Directory appCache = await getTemporaryDirectory();
|
||||||
Directory('${appCache.path}/cache').createSync();
|
Directory('${appCache.path}/cache').createSync();
|
||||||
final Directory workDir =
|
final Directory workDir =
|
||||||
Directory('${appCache.path}/cache').createTempSync('tmp-');
|
Directory('${appCache.path}/cache').createTempSync('tmp-');
|
||||||
final Directory cacheDir = Directory('${workDir.path}/cache');
|
final Directory cacheDir = Directory('${workDir.path}/cache');
|
||||||
cacheDir.createSync();
|
cacheDir.createSync();
|
||||||
|
|
||||||
@ -324,7 +326,9 @@ class ManagerAPI {
|
|||||||
);
|
);
|
||||||
|
|
||||||
final List<dynamic> patchesJsonList = jsonDecode(patchesJson);
|
final List<dynamic> patchesJsonList = jsonDecode(patchesJson);
|
||||||
patches = patchesJsonList.map((patchJson) => Patch.fromJson(patchJson)).toList();
|
patches = patchesJsonList
|
||||||
|
.map((patchJson) => Patch.fromJson(patchJson))
|
||||||
|
.toList();
|
||||||
return patches;
|
return patches;
|
||||||
} on Exception catch (e) {
|
} on Exception catch (e) {
|
||||||
if (kDebugMode) {
|
if (kDebugMode) {
|
||||||
@ -501,48 +505,18 @@ class ManagerAPI {
|
|||||||
return toRemove;
|
return toRemove;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<PatchedApplication>> getUnsavedApps(
|
Future<List<PatchedApplication>> getMountedApps() async {
|
||||||
List<PatchedApplication> patchedApps,
|
final List<PatchedApplication> mountedApps = [];
|
||||||
) async {
|
|
||||||
final List<PatchedApplication> unsavedApps = [];
|
|
||||||
final bool hasRootPermissions = await _rootAPI.hasRootPermissions();
|
final bool hasRootPermissions = await _rootAPI.hasRootPermissions();
|
||||||
if (hasRootPermissions) {
|
if (hasRootPermissions) {
|
||||||
final List<String> installedApps = await _rootAPI.getInstalledApps();
|
final List<String> installedApps = await _rootAPI.getInstalledApps();
|
||||||
for (final String packageName in installedApps) {
|
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(
|
|
||||||
PatchedApplication(
|
|
||||||
name: application.appName,
|
|
||||||
packageName: application.packageName,
|
|
||||||
originalPackageName: application.packageName,
|
|
||||||
version: application.versionName!,
|
|
||||||
apkFilePath: application.apkFilePath,
|
|
||||||
icon: application.icon,
|
|
||||||
patchDate: DateTime.now(),
|
|
||||||
isRooted: true,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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(
|
final ApplicationWithIcon? application = await DeviceApps.getApp(
|
||||||
app.packageName,
|
packageName,
|
||||||
true,
|
true,
|
||||||
) as ApplicationWithIcon?;
|
) as ApplicationWithIcon?;
|
||||||
if (application != null) {
|
if (application != null) {
|
||||||
unsavedApps.add(
|
mountedApps.add(
|
||||||
PatchedApplication(
|
PatchedApplication(
|
||||||
name: application.appName,
|
name: application.appName,
|
||||||
packageName: application.packageName,
|
packageName: application.packageName,
|
||||||
@ -551,12 +525,14 @@ class ManagerAPI {
|
|||||||
apkFilePath: application.apkFilePath,
|
apkFilePath: application.apkFilePath,
|
||||||
icon: application.icon,
|
icon: application.icon,
|
||||||
patchDate: DateTime.now(),
|
patchDate: DateTime.now(),
|
||||||
|
isRooted: true,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return unsavedApps;
|
|
||||||
|
return mountedApps;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> showPatchesChangeWarningDialog(BuildContext context) {
|
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 {
|
Future<bool> isAppUninstalled(PatchedApplication app) async {
|
||||||
bool existsRoot = false;
|
bool existsRoot = false;
|
||||||
final bool existsNonRoot = await DeviceApps.isAppInstalled(app.packageName);
|
final bool existsNonRoot = await DeviceApps.isAppInstalled(app.packageName);
|
||||||
|
@ -81,7 +81,8 @@ class HomeViewModel extends BaseViewModel {
|
|||||||
_toast.showBottom('homeView.errorDownloadMessage');
|
_toast.showBottom('homeView.errorDownloadMessage');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_getPatchedApps();
|
|
||||||
|
_managerAPI.reAssessSavedApps().then((_) => _getPatchedApps());
|
||||||
}
|
}
|
||||||
|
|
||||||
void navigateToAppInfo(PatchedApplication app) {
|
void navigateToAppInfo(PatchedApplication app) {
|
||||||
|
Loading…
Reference in New Issue
Block a user