mirror of
https://github.com/ReVanced/revanced-manager.git
synced 2024-11-12 18:04:28 +01:00
chore: bump patcher
This commit is contained in:
parent
1dc41badd9
commit
59daceef99
5 changed files with 64 additions and 62 deletions
|
@ -1,7 +1,9 @@
|
||||||
package app.revanced.manager.domain.bundles
|
package app.revanced.manager.domain.bundles
|
||||||
|
|
||||||
|
import android.util.Log
|
||||||
import androidx.compose.runtime.Stable
|
import androidx.compose.runtime.Stable
|
||||||
import app.revanced.manager.patcher.patch.PatchBundle
|
import app.revanced.manager.patcher.patch.PatchBundle
|
||||||
|
import app.revanced.manager.util.tag
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.flowOf
|
import kotlinx.coroutines.flow.flowOf
|
||||||
|
@ -40,6 +42,7 @@ sealed class PatchBundleSource(val name: String, val uid: Int, directory: File)
|
||||||
return try {
|
return try {
|
||||||
State.Loaded(PatchBundle(patchesFile, integrationsFile.takeIf(File::exists)))
|
State.Loaded(PatchBundle(patchesFile, integrationsFile.takeIf(File::exists)))
|
||||||
} catch (t: Throwable) {
|
} catch (t: Throwable) {
|
||||||
|
Log.e(tag, "Failed to load patch bundle $name", t)
|
||||||
State.Failed(t)
|
State.Failed(t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,15 +56,15 @@ data class Option(
|
||||||
val key: String,
|
val key: String,
|
||||||
val description: String,
|
val description: String,
|
||||||
val required: Boolean,
|
val required: Boolean,
|
||||||
val type: Class<out PatchOption<*>>,
|
val type: String,
|
||||||
val defaultValue: Any?
|
val default: Any?
|
||||||
) {
|
) {
|
||||||
constructor(option: PatchOption<*>) : this(
|
constructor(option: PatchOption<*>) : this(
|
||||||
option.title ?: option.key,
|
option.title ?: option.key,
|
||||||
option.key,
|
option.key,
|
||||||
option.description.orEmpty(),
|
option.description.orEmpty(),
|
||||||
option.required,
|
option.required,
|
||||||
option::class.java,
|
option.valueType,
|
||||||
option.value
|
option.default,
|
||||||
)
|
)
|
||||||
}
|
}
|
|
@ -29,7 +29,6 @@ import app.revanced.manager.R
|
||||||
import app.revanced.manager.data.platform.Filesystem
|
import app.revanced.manager.data.platform.Filesystem
|
||||||
import app.revanced.manager.patcher.patch.Option
|
import app.revanced.manager.patcher.patch.Option
|
||||||
import app.revanced.manager.util.toast
|
import app.revanced.manager.util.toast
|
||||||
import app.revanced.patcher.patch.options.types.*
|
|
||||||
import org.koin.compose.rememberKoinInject
|
import org.koin.compose.rememberKoinInject
|
||||||
|
|
||||||
// Composable functions do not support function references, so we have to use composable lambdas instead.
|
// 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 ->
|
private val unknownOption: OptionImpl = { option, _, _ ->
|
||||||
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, _, _ ->
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
OptionListItem(
|
OptionListItem(
|
||||||
option = option,
|
option = option,
|
||||||
onClick = { context.toast("Unknown type: ${option.type.name}") },
|
onClick = { context.toast("Unknown type: ${option.type}") },
|
||||||
trailingContent = {})
|
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
|
@Composable
|
||||||
fun OptionItem(option: Option, value: Any?, setValue: (Any?) -> Unit) {
|
fun OptionItem(option: Option, value: Any?, setValue: (Any?) -> Unit) {
|
||||||
val implementation = remember(option.type) {
|
val implementation = remember(option.type) {
|
||||||
when (option.type) {
|
optionImplementations.getOrDefault(
|
||||||
// These are the only two types that are currently used by the official patches.
|
option.type,
|
||||||
StringPatchOption::class.java -> StringOption
|
unknownOption
|
||||||
BooleanPatchOption::class.java -> BooleanOption
|
)
|
||||||
else -> UnknownOption
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
implementation(option, value, setValue)
|
implementation(option, value, setValue)
|
||||||
|
|
|
@ -571,7 +571,7 @@ fun OptionsDialog(
|
||||||
items(patch.options, key = { it.key }) { option ->
|
items(patch.options, key = { it.key }) { option ->
|
||||||
val key = option.key
|
val key = option.key
|
||||||
val value =
|
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) })
|
OptionItem(option = option, value = value, setValue = { set(key, it) })
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,8 @@ accompanist = "0.30.1"
|
||||||
serialization = "1.6.0"
|
serialization = "1.6.0"
|
||||||
collection = "0.3.5"
|
collection = "0.3.5"
|
||||||
room-version = "2.5.2"
|
room-version = "2.5.2"
|
||||||
revanced-patcher = "17.0.0"
|
revanced-patcher = "19.0.0"
|
||||||
revanced-library = "1.1.4"
|
revanced-library = "1.2.0"
|
||||||
koin-version = "3.4.3"
|
koin-version = "3.4.3"
|
||||||
koin-version-compose = "3.4.6"
|
koin-version-compose = "3.4.6"
|
||||||
reimagined-navigation = "1.5.0"
|
reimagined-navigation = "1.5.0"
|
||||||
|
|
Loading…
Reference in a new issue