mirror of
https://github.com/ReVanced/revanced-manager.git
synced 2024-11-13 02:14:31 +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 Directory _tmpDir;
|
||||||
late File _keyStoreFile;
|
late File _keyStoreFile;
|
||||||
List<Patch> _patches = [];
|
List<Patch> _patches = [];
|
||||||
|
List<Patch> _universalPatches = [];
|
||||||
|
List<String> _compatiblePackages = [];
|
||||||
Map filteredPatches = <String, List<Patch>>{};
|
Map filteredPatches = <String, List<Patch>>{};
|
||||||
File? _outFile;
|
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 {
|
Future<void> _loadPatches() async {
|
||||||
try {
|
try {
|
||||||
if (_patches.isEmpty) {
|
if (_patches.isEmpty) {
|
||||||
|
@ -56,6 +76,9 @@ class PatcherAPI {
|
||||||
}
|
}
|
||||||
_patches = List.empty();
|
_patches = List.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_compatiblePackages = getCompatiblePackages();
|
||||||
|
_universalPatches = getUniversalPatches();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<ApplicationWithIcon>> getFilteredInstalledApps(
|
Future<List<ApplicationWithIcon>> getFilteredInstalledApps(
|
||||||
|
@ -63,48 +86,43 @@ class PatcherAPI {
|
||||||
) async {
|
) async {
|
||||||
final List<ApplicationWithIcon> filteredApps = [];
|
final List<ApplicationWithIcon> filteredApps = [];
|
||||||
final bool allAppsIncluded =
|
final bool allAppsIncluded =
|
||||||
_patches.any((patch) => patch.compatiblePackages.isEmpty) &&
|
_universalPatches.isNotEmpty &&
|
||||||
showUniversalPatches;
|
showUniversalPatches;
|
||||||
if (allAppsIncluded) {
|
if (allAppsIncluded) {
|
||||||
final allPackages = await DeviceApps.getInstalledApplications(
|
final appList = await DeviceApps.getInstalledApplications(
|
||||||
includeAppIcons: true,
|
includeAppIcons: true,
|
||||||
onlyAppsWithLaunchIntent: true,
|
onlyAppsWithLaunchIntent: true,
|
||||||
);
|
);
|
||||||
for (final pkg in allPackages) {
|
|
||||||
if (!filteredApps.any((app) => app.packageName == pkg.packageName)) {
|
for(final app in appList) {
|
||||||
final appInfo = await DeviceApps.getApp(
|
filteredApps.add(app as ApplicationWithIcon);
|
||||||
pkg.packageName,
|
|
||||||
true,
|
|
||||||
) as ApplicationWithIcon?;
|
|
||||||
if (appInfo != null) {
|
|
||||||
filteredApps.add(appInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (final Patch patch in _patches) {
|
for (final packageName in _compatiblePackages) {
|
||||||
for (final Package package in patch.compatiblePackages) {
|
try {
|
||||||
try {
|
if (!filteredApps.any((app) => app.packageName == packageName)) {
|
||||||
if (!filteredApps.any((app) => app.packageName == package.name)) {
|
final ApplicationWithIcon? app = await DeviceApps.getApp(
|
||||||
final ApplicationWithIcon? app = await DeviceApps.getApp(
|
packageName,
|
||||||
package.name,
|
true,
|
||||||
true,
|
) as ApplicationWithIcon?;
|
||||||
) as ApplicationWithIcon?;
|
if (app != null) {
|
||||||
if (app != null) {
|
filteredApps.add(app);
|
||||||
filteredApps.add(app);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} on Exception catch (e) {
|
|
||||||
if (kDebugMode) {
|
|
||||||
print(e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} on Exception catch (e) {
|
||||||
|
if (kDebugMode) {
|
||||||
|
print(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return filteredApps;
|
return filteredApps;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Patch> getFilteredPatches(String packageName) {
|
List<Patch> getFilteredPatches(String packageName) {
|
||||||
|
if (!_compatiblePackages.contains(packageName)) {
|
||||||
|
return _universalPatches;
|
||||||
|
}
|
||||||
|
|
||||||
final List<Patch> patches = _patches
|
final List<Patch> patches = _patches
|
||||||
.where(
|
.where(
|
||||||
(patch) =>
|
(patch) =>
|
||||||
|
|
Loading…
Reference in a new issue