chore: bump patcher

This commit is contained in:
Ax333l 2023-11-06 19:33:06 +01:00
parent 1dc41badd9
commit 59daceef99
No known key found for this signature in database
GPG key ID: D2B4D85271127D23
5 changed files with 64 additions and 62 deletions

View file

@ -1,7 +1,9 @@
package app.revanced.manager.domain.bundles
import android.util.Log
import androidx.compose.runtime.Stable
import app.revanced.manager.patcher.patch.PatchBundle
import app.revanced.manager.util.tag
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.flowOf
@ -40,6 +42,7 @@ sealed class PatchBundleSource(val name: String, val uid: Int, directory: File)
return try {
State.Loaded(PatchBundle(patchesFile, integrationsFile.takeIf(File::exists)))
} catch (t: Throwable) {
Log.e(tag, "Failed to load patch bundle $name", t)
State.Failed(t)
}
}

View file

@ -56,15 +56,15 @@ data class Option(
val key: String,
val description: String,
val required: Boolean,
val type: Class<out PatchOption<*>>,
val defaultValue: Any?
val type: String,
val default: Any?
) {
constructor(option: PatchOption<*>) : this(
option.title ?: option.key,
option.key,
option.description.orEmpty(),
option.required,
option::class.java,
option.value
option.valueType,
option.default,
)
}

View file

@ -29,7 +29,6 @@ import app.revanced.manager.R
import app.revanced.manager.data.platform.Filesystem
import app.revanced.manager.patcher.patch.Option
import app.revanced.manager.util.toast
import app.revanced.patcher.patch.options.types.*
import org.koin.compose.rememberKoinInject
// Composable functions do not support function references, so we have to use composable lambdas instead.
@ -136,69 +135,69 @@ private fun StringOptionDialog(
)
}
private val StringOption: OptionImpl = { option, value, setValue ->
var showInputDialog by rememberSaveable { mutableStateOf(false) }
fun showInputDialog() {
showInputDialog = true
}
fun dismissInputDialog() {
showInputDialog = false
}
if (showInputDialog) {
StringOptionDialog(
name = option.title,
value = value as? String,
onSubmit = {
dismissInputDialog()
setValue(it)
},
onDismissRequest = ::dismissInputDialog
)
}
OptionListItem(
option = option,
onClick = ::showInputDialog
) {
IconButton(onClick = ::showInputDialog) {
Icon(
Icons.Outlined.Edit,
contentDescription = stringResource(R.string.string_option_icon_description)
)
}
}
}
private val BooleanOption: OptionImpl = { option, value, setValue ->
val current = (value as? Boolean) ?: false
OptionListItem(
option = option,
onClick = { setValue(!current) }
) {
Switch(checked = current, onCheckedChange = setValue)
}
}
private val UnknownOption: OptionImpl = { option, _, _ ->
private val unknownOption: OptionImpl = { option, _, _ ->
val context = LocalContext.current
OptionListItem(
option = option,
onClick = { context.toast("Unknown type: ${option.type.name}") },
onClick = { context.toast("Unknown type: ${option.type}") },
trailingContent = {})
}
private val optionImplementations = mapOf<String, OptionImpl>(
// These are the only two types that are currently used by the official patches
"Boolean" to { option, value, setValue ->
val current = (value as? Boolean) ?: false
OptionListItem(
option = option,
onClick = { setValue(!current) }
) {
Switch(checked = current, onCheckedChange = setValue)
}
},
"String" to { option, value, setValue ->
var showInputDialog by rememberSaveable { mutableStateOf(false) }
fun showInputDialog() {
showInputDialog = true
}
fun dismissInputDialog() {
showInputDialog = false
}
if (showInputDialog) {
StringOptionDialog(
name = option.title,
value = value as? String,
onSubmit = {
dismissInputDialog()
setValue(it)
},
onDismissRequest = ::dismissInputDialog
)
}
OptionListItem(
option = option,
onClick = ::showInputDialog
) {
IconButton(onClick = ::showInputDialog) {
Icon(
Icons.Outlined.Edit,
contentDescription = stringResource(R.string.string_option_icon_description)
)
}
}
}
)
@Composable
fun OptionItem(option: Option, value: Any?, setValue: (Any?) -> Unit) {
val implementation = remember(option.type) {
when (option.type) {
// These are the only two types that are currently used by the official patches.
StringPatchOption::class.java -> StringOption
BooleanPatchOption::class.java -> BooleanOption
else -> UnknownOption
}
optionImplementations.getOrDefault(
option.type,
unknownOption
)
}
implementation(option, value, setValue)

View file

@ -571,7 +571,7 @@ fun OptionsDialog(
items(patch.options, key = { it.key }) { option ->
val key = option.key
val value =
if (values == null || !values.contains(key)) option.defaultValue else values[key]
if (values == null || !values.contains(key)) option.default else values[key]
OptionItem(option = option, value = value, setValue = { set(key, it) })
}

View file

@ -11,8 +11,8 @@ accompanist = "0.30.1"
serialization = "1.6.0"
collection = "0.3.5"
room-version = "2.5.2"
revanced-patcher = "17.0.0"
revanced-library = "1.1.4"
revanced-patcher = "19.0.0"
revanced-library = "1.2.0"
koin-version = "3.4.3"
koin-version-compose = "3.4.6"
reimagined-navigation = "1.5.0"