revanced-manager/lib/utils/check_for_supported_patch.dart
aAbed ba44fa620f
build: Bump dependencies to support patch option values (#1431)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
2023-11-04 22:08:19 +01:00

62 lines
1.9 KiB
Dart

import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/models/patch.dart';
import 'package:revanced_manager/models/patched_application.dart';
import 'package:revanced_manager/services/manager_api.dart';
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)),
);
}
bool hasUnsupportedRequiredOption(List<Option> options, Patch patch) {
final List<String> requiredOptionsType = [];
final List<String> supportedOptionsType = [
'String',
'Boolean',
'Int',
'StringArray',
'IntArray',
'LongArray',
];
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);
}
}
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;
}