Skip to content

Commit

Permalink
build: Bump dependencies to support patch option values (#1431)
Browse files Browse the repository at this point in the history
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
  • Loading branch information
TheAabedKhan and oSumAtrIX committed Nov 4, 2023
1 parent dde402a commit ba44fa6
Show file tree
Hide file tree
Showing 8 changed files with 377 additions and 172 deletions.
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

// ReVanced
implementation "app.revanced:revanced-patcher:17.0.0"
implementation "app.revanced:revanced-patcher:19.0.0"

// Signing & aligning
implementation("org.bouncycastle:bcpkix-jdk15on:1.70")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import app.revanced.patcher.patch.PatchResult
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugin.common.MethodChannel
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.runBlocking
import org.json.JSONArray
import org.json.JSONObject
Expand All @@ -25,6 +27,7 @@ import java.io.StringWriter
import java.util.logging.LogRecord
import java.util.logging.Logger


class MainActivity : FlutterActivity() {
private val handler = Handler(Looper.getMainLooper())
private lateinit var installerChannel: MethodChannel
Expand Down Expand Up @@ -131,24 +134,34 @@ class MainActivity : FlutterActivity() {
})
put("options", JSONArray().apply {
it.options.values.forEach { option ->
val optionJson = JSONObject().apply option@{
JSONObject().apply {
put("key", option.key)
put("title", option.title)
put("description", option.description)
put("required", option.required)

when (val value = option.value) {
null -> put("value", null)
is Array<*> -> put("value", JSONArray().apply {

fun JSONObject.putValue(
value: Any?,
key: String = "value"
) = if (value is Array<*>) put(
key,
JSONArray().apply {
value.forEach { put(it) }
})
else -> put("value", option.value)
}

put("optionClassType", option::class.simpleName)
}
put(optionJson)
else put(key, value)

putValue(option.default)

option.values?.let { values ->
put("values",
JSONObject().apply {
values.forEach { (key, value) ->
putValue(value, key)
}
})
} ?: put("values", null)
put("valueType", option.valueType)
}.let(::put)
}
})
}.let(::put)
Expand All @@ -161,6 +174,7 @@ class MainActivity : FlutterActivity() {
}
}

@OptIn(InternalCoroutinesApi::class)
private fun runPatcher(
result: MethodChannel.Result,
originalFilePath: String,
Expand Down Expand Up @@ -283,12 +297,12 @@ class MainActivity : FlutterActivity() {
acceptPatches(patches)

runBlocking {
apply(false).collect { patchResult: PatchResult ->
apply(false).collect(FlowCollector { patchResult: PatchResult ->
if (cancel) {
handler.post { stopResult!!.success(null) }
this.cancel()
this@apply.close()
return@collect
return@FlowCollector
}

val msg = patchResult.exception?.let {
Expand All @@ -301,7 +315,7 @@ class MainActivity : FlutterActivity() {

updateProgress(progress, "", msg)
progress += progressStep
}
})
}
}

Expand Down
1 change: 1 addition & 0 deletions assets/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
"setRequiredOption": "Some patches require options to be set:\n\n{patches}\n\nPlease set them before continuing."
},
"patchOptionsView": {
"customValue": "Custom value",
"resetOptionsTooltip": "Reset patch options",
"viewTitle": "Patch options",
"saveOptions": "Save",
Expand Down
33 changes: 26 additions & 7 deletions lib/models/patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ class Patch {
});

factory Patch.fromJson(Map<String, dynamic> json) {
// See: https://github.com/ReVanced/revanced-manager/issues/1364#issuecomment-1760414618
_migrateV16ToV17(json);

return _$PatchFromJson(json);
}

static void _migrateV16ToV17(Map<String, dynamic> json) {
if (json['options'] == null) {
json['options'] = [];
}

return _$PatchFromJson(json);
}

final String name;
Expand Down Expand Up @@ -57,18 +60,34 @@ class Option {
required this.title,
required this.description,
required this.value,
required this.values,
required this.required,
required this.optionClassType,
required this.valueType,
});

factory Option.fromJson(Map<String, dynamic> json) => _$OptionFromJson(json);
factory Option.fromJson(Map<String, dynamic> json) {
_migrateV17ToV19(json);

return _$OptionFromJson(json);
}

static void _migrateV17ToV19(Map<String, dynamic> json) {
if (json['valueType'] == null) {
json['valueType'] = json['optionClassType']
.replace('PatchOption', '')
.replace('List', 'Array');

json['optionClassType'] = null;
}
}

final String key;
final String title;
final String description;
dynamic value;
final dynamic value;
final Map<String, dynamic>? values;
final bool required;
final String optionClassType;
final String valueType;

Map toJson() => _$OptionToJson(this);
}
14 changes: 7 additions & 7 deletions lib/ui/views/patch_options/patch_options_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class PatchOptionsView extends StatelessWidget {
child: Column(
children: [
for (final Option option in model.visibleOptions)
if (option.optionClassType == 'StringPatchOption' ||
option.optionClassType == 'IntPatchOption')
if (option.valueType == 'String' ||
option.valueType == 'Int')
IntAndStringPatchOption(
patchOption: option,
removeOption: (option) {
Expand All @@ -72,7 +72,7 @@ class PatchOptionsView extends StatelessWidget {
model.modifyOptions(value, option);
},
)
else if (option.optionClassType == 'BooleanPatchOption')
else if (option.valueType == 'Boolean')
BooleanPatchOption(
patchOption: option,
removeOption: (option) {
Expand All @@ -82,10 +82,10 @@ class PatchOptionsView extends StatelessWidget {
model.modifyOptions(value, option);
},
)
else if (option.optionClassType ==
'StringListPatchOption' ||
option.optionClassType == 'IntListPatchOption' ||
option.optionClassType == 'LongListPatchOption')
else if (option.valueType ==
'StringArray' ||
option.valueType == 'IntArray' ||
option.valueType == 'LongArray')
IntStringLongListPatchOption(
patchOption: option,
removeOption: (option) {
Expand Down
55 changes: 36 additions & 19 deletions lib/ui/views/patch_options/patch_options_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,21 @@ class PatchOptionsViewModel extends BaseViewModel {
for (final Option option in options) {
if (!visibleOptions.any((vOption) => vOption.key == option.key)) {
_managerAPI.clearPatchOption(
selectedApp, _managerAPI.selectedPatch!.name, option.key);
selectedApp,
_managerAPI.selectedPatch!.name,
option.key,
);
}
}
for (final Option option in visibleOptions) {
if (option.required && option.value == null) {
requiredNullOptions.add(option);
} else {
_managerAPI.setPatchOption(
option, _managerAPI.selectedPatch!.name, selectedApp);
option,
_managerAPI.selectedPatch!.name,
selectedApp,
);
}
}
if (requiredNullOptions.isNotEmpty) {
Expand All @@ -89,7 +95,8 @@ class PatchOptionsViewModel extends BaseViewModel {
final Option modifiedOption = Option(
title: option.title,
description: option.description,
optionClassType: option.optionClassType,
values: option.values,
valueType: option.valueType,
value: value,
required: option.required,
key: option.key,
Expand All @@ -107,7 +114,8 @@ class PatchOptionsViewModel extends BaseViewModel {
final Option defaultOption = Option(
title: option.title,
description: option.description,
optionClassType: option.optionClassType,
values: option.values,
valueType: option.valueType,
value: option.value is List ? option.value.toList() : option.value,
required: option.required,
key: option.key,
Expand Down Expand Up @@ -172,21 +180,27 @@ class PatchOptionsViewModel extends BaseViewModel {
},
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
child: Row(
children: [
Text(
e.title,
style: const TextStyle(
fontSize: 16,
),
),
const SizedBox(height: 4),
Text(
e.description,
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurface,
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
e.title,
style: const TextStyle(
fontSize: 16,
),
),
const SizedBox(height: 4),
Text(
e.description,
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurface,
),
),
],
),
),
],
Expand Down Expand Up @@ -229,7 +243,10 @@ Future<void> showRequiredOptionNullDialog(
locator<PatcherViewModel>().notifyListeners();
for (final option in options) {
managerAPI.clearPatchOption(
selectedApp, managerAPI.selectedPatch!.name, option.key);
selectedApp,
managerAPI.selectedPatch!.name,
option.key,
);
}
Navigator.of(context)
..pop()
Expand Down

0 comments on commit ba44fa6

Please sign in to comment.