revanced-manager/lib/utils/check_for_supported_patch.dart

62 lines
1.9 KiB
Dart
Raw Normal View History

2023-04-18 21:51:08 +02:00
import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/models/patch.dart';
import 'package:revanced_manager/models/patched_application.dart';
2023-10-12 02:00:39 +02:00
import 'package:revanced_manager/services/manager_api.dart';
2023-04-18 21:51:08 +02:00
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
bool isPatchSupported(Patch patch) {
final PatchedApplication app = locator<PatcherViewModel>().selectedApp!;
return patch.compatiblePackages.isEmpty ||
patch.compatiblePackages.any(
(pack) =>
pack.name == app.packageName &&
(pack.versions.isEmpty || pack.versions.contains(app.version)),
);
}
2023-10-12 02:00:39 +02:00
bool hasUnsupportedRequiredOption(List<Option> options, Patch patch) {
final List<String> requiredOptionsType = [];
final List<String> supportedOptionsType = [
'String',
'Boolean',
'Int',
'StringArray',
'IntArray',
'LongArray',
2023-10-12 02:00:39 +02:00
];
for (final Option option in options) {
if (option.required &&
option.value == null &&
locator<ManagerAPI>()
.getPatchOption(
locator<PatcherViewModel>().selectedApp!.packageName,
patch.name,
option.key,
) == null) {
requiredOptionsType.add(option.valueType);
2023-10-12 02:00:39 +02:00
}
}
for (final String optionType in requiredOptionsType) {
if (!supportedOptionsType.contains(optionType)) {
return true;
}
}
return false;
}
List<Option> getNullRequiredOptions(List<Patch> patches, String packageName) {
final List<Option> requiredNullOptions = [];
for (final patch in patches) {
for (final patchOption in patch.options) {
if (!patch.excluded &&
patchOption.required &&
patchOption.value == null &&
locator<ManagerAPI>()
.getPatchOption(packageName, patch.name, patchOption.key) == null) {
requiredNullOptions.add(patchOption);
}
}
}
return requiredNullOptions;
}