check_for_supported_patch.dart 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import 'package:revanced_manager/app/app.locator.dart';
  2. import 'package:revanced_manager/models/patch.dart';
  3. import 'package:revanced_manager/models/patched_application.dart';
  4. import 'package:revanced_manager/services/manager_api.dart';
  5. import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
  6. bool isPatchSupported(Patch patch) {
  7. final PatchedApplication app = locator<PatcherViewModel>().selectedApp!;
  8. return patch.compatiblePackages.isEmpty ||
  9. patch.compatiblePackages.any(
  10. (pack) =>
  11. pack.name == app.packageName &&
  12. (pack.versions.isEmpty || pack.versions.contains(app.version)),
  13. );
  14. }
  15. bool hasUnsupportedRequiredOption(List<Option> options, Patch patch) {
  16. final List<String> requiredOptionsType = [];
  17. final List<String> supportedOptionsType = [
  18. 'String',
  19. 'Boolean',
  20. 'Int',
  21. 'StringArray',
  22. 'IntArray',
  23. 'LongArray',
  24. ];
  25. for (final Option option in options) {
  26. if (option.required &&
  27. option.value == null &&
  28. locator<ManagerAPI>().getPatchOption(
  29. locator<PatcherViewModel>().selectedApp!.packageName,
  30. patch.name,
  31. option.key,
  32. ) ==
  33. null) {
  34. requiredOptionsType.add(option.type);
  35. }
  36. }
  37. for (final String optionType in requiredOptionsType) {
  38. if (!supportedOptionsType.contains(optionType)) {
  39. return true;
  40. }
  41. }
  42. return false;
  43. }
  44. List<Option> getNullRequiredOptions(List<Patch> patches, String packageName) {
  45. final List<Option> requiredNullOptions = [];
  46. for (final patch in patches) {
  47. for (final patchOption in patch.options) {
  48. if (!patch.excluded &&
  49. patchOption.required &&
  50. patchOption.value == null &&
  51. locator<ManagerAPI>()
  52. .getPatchOption(packageName, patch.name, patchOption.key) ==
  53. null) {
  54. requiredNullOptions.add(patchOption);
  55. }
  56. }
  57. }
  58. return requiredNullOptions;
  59. }