mirror of
https://github.com/revanced/revanced-manager
synced 2024-05-14 13:56:57 +02:00
fix: improve app list loading speed (#1166)
This commit is contained in:
parent
b525ea1ba4
commit
f4b0a695d6
@ -25,6 +25,8 @@ class PatcherAPI {
|
||||
late Directory _tmpDir;
|
||||
late File _keyStoreFile;
|
||||
List<Patch> _patches = [];
|
||||
List<Patch> _universalPatches = [];
|
||||
List<String> _compatiblePackages = [];
|
||||
Map filteredPatches = <String, List<Patch>>{};
|
||||
File? _outFile;
|
||||
|
||||
@ -45,6 +47,24 @@ class PatcherAPI {
|
||||
}
|
||||
}
|
||||
|
||||
List<String> getCompatiblePackages() {
|
||||
final List<String> compatiblePackages = [];
|
||||
for (final Patch patch in _patches) {
|
||||
for (final Package package in patch.compatiblePackages) {
|
||||
if (!compatiblePackages.contains(package.name)) {
|
||||
compatiblePackages.add(package.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
return compatiblePackages;
|
||||
}
|
||||
|
||||
List<Patch> getUniversalPatches() {
|
||||
return _patches
|
||||
.where((patch) => patch.compatiblePackages.isEmpty)
|
||||
.toList();
|
||||
}
|
||||
|
||||
Future<void> _loadPatches() async {
|
||||
try {
|
||||
if (_patches.isEmpty) {
|
||||
@ -56,6 +76,9 @@ class PatcherAPI {
|
||||
}
|
||||
_patches = List.empty();
|
||||
}
|
||||
|
||||
_compatiblePackages = getCompatiblePackages();
|
||||
_universalPatches = getUniversalPatches();
|
||||
}
|
||||
|
||||
Future<List<ApplicationWithIcon>> getFilteredInstalledApps(
|
||||
@ -63,31 +86,23 @@ class PatcherAPI {
|
||||
) async {
|
||||
final List<ApplicationWithIcon> filteredApps = [];
|
||||
final bool allAppsIncluded =
|
||||
_patches.any((patch) => patch.compatiblePackages.isEmpty) &&
|
||||
_universalPatches.isNotEmpty &&
|
||||
showUniversalPatches;
|
||||
if (allAppsIncluded) {
|
||||
final allPackages = await DeviceApps.getInstalledApplications(
|
||||
final appList = await DeviceApps.getInstalledApplications(
|
||||
includeAppIcons: true,
|
||||
onlyAppsWithLaunchIntent: true,
|
||||
);
|
||||
for (final pkg in allPackages) {
|
||||
if (!filteredApps.any((app) => app.packageName == pkg.packageName)) {
|
||||
final appInfo = await DeviceApps.getApp(
|
||||
pkg.packageName,
|
||||
true,
|
||||
) as ApplicationWithIcon?;
|
||||
if (appInfo != null) {
|
||||
filteredApps.add(appInfo);
|
||||
|
||||
for(final app in appList) {
|
||||
filteredApps.add(app as ApplicationWithIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final Patch patch in _patches) {
|
||||
for (final Package package in patch.compatiblePackages) {
|
||||
for (final packageName in _compatiblePackages) {
|
||||
try {
|
||||
if (!filteredApps.any((app) => app.packageName == package.name)) {
|
||||
if (!filteredApps.any((app) => app.packageName == packageName)) {
|
||||
final ApplicationWithIcon? app = await DeviceApps.getApp(
|
||||
package.name,
|
||||
packageName,
|
||||
true,
|
||||
) as ApplicationWithIcon?;
|
||||
if (app != null) {
|
||||
@ -100,11 +115,14 @@ class PatcherAPI {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return filteredApps;
|
||||
}
|
||||
|
||||
List<Patch> getFilteredPatches(String packageName) {
|
||||
if (!_compatiblePackages.contains(packageName)) {
|
||||
return _universalPatches;
|
||||
}
|
||||
|
||||
final List<Patch> patches = _patches
|
||||
.where(
|
||||
(patch) =>
|
||||
|
Loading…
Reference in New Issue
Block a user