mirror of
https://github.com/ReVanced/revanced-manager.git
synced 2024-11-10 01:01:56 +01:00
fix: improve app list loading speed (#1166)
This commit is contained in:
parent
b525ea1ba4
commit
f4b0a695d6
1 changed files with 45 additions and 27 deletions
|
@ -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,48 +86,43 @@ 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) {
|
||||
try {
|
||||
if (!filteredApps.any((app) => app.packageName == package.name)) {
|
||||
final ApplicationWithIcon? app = await DeviceApps.getApp(
|
||||
package.name,
|
||||
true,
|
||||
) as ApplicationWithIcon?;
|
||||
if (app != null) {
|
||||
filteredApps.add(app);
|
||||
}
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
if (kDebugMode) {
|
||||
print(e);
|
||||
for (final packageName in _compatiblePackages) {
|
||||
try {
|
||||
if (!filteredApps.any((app) => app.packageName == packageName)) {
|
||||
final ApplicationWithIcon? app = await DeviceApps.getApp(
|
||||
packageName,
|
||||
true,
|
||||
) as ApplicationWithIcon?;
|
||||
if (app != null) {
|
||||
filteredApps.add(app);
|
||||
}
|
||||
}
|
||||
} on Exception catch (e) {
|
||||
if (kDebugMode) {
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return filteredApps;
|
||||
}
|
||||
|
||||
List<Patch> getFilteredPatches(String packageName) {
|
||||
if (!_compatiblePackages.contains(packageName)) {
|
||||
return _universalPatches;
|
||||
}
|
||||
|
||||
final List<Patch> patches = _patches
|
||||
.where(
|
||||
(patch) =>
|
||||
|
|
Loading…
Reference in a new issue