feat: custom injector selection
This commit is contained in:
parent
9864dd9db8
commit
04413c84aa
2 changed files with 47 additions and 4 deletions
|
|
@ -59,9 +59,14 @@ class PathManager(context: Context) {
|
|||
/**
|
||||
* Resolve a specific path for a cached injector.
|
||||
*/
|
||||
fun cachedInjectorDex(aliucordHash: SemVer) = externalCacheDir
|
||||
fun cachedInjectorDex(version: SemVer, custom: Boolean = false) = externalCacheDir
|
||||
.resolve("injector").apply { mkdirs() }
|
||||
.resolve("$aliucordHash.dex")
|
||||
.resolve("$version${if (custom) ".custom" else ""}.dex")
|
||||
|
||||
/**
|
||||
* Get all the versions of custom injector builds.
|
||||
*/
|
||||
fun customInjectorDexs() = listCustomFiles(externalCacheDir.resolve("injector"))
|
||||
|
||||
/**
|
||||
* Resolve a specific path for a versioned cached Aliuhook build
|
||||
|
|
|
|||
|
|
@ -1,14 +1,17 @@
|
|||
package com.aliucord.manager.patcher.steps.download
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.Stable
|
||||
import com.aliucord.manager.BuildConfig
|
||||
import com.aliucord.manager.R
|
||||
import com.aliucord.manager.manager.OverlayManager
|
||||
import com.aliucord.manager.manager.PathManager
|
||||
import com.aliucord.manager.network.utils.SemVer
|
||||
import com.aliucord.manager.patcher.StepRunner
|
||||
import com.aliucord.manager.patcher.steps.base.DownloadStep
|
||||
import com.aliucord.manager.patcher.steps.base.IDexProvider
|
||||
import com.aliucord.manager.patcher.steps.base.*
|
||||
import com.aliucord.manager.patcher.steps.patch.ReorganizeDexStep
|
||||
import com.aliucord.manager.patcher.steps.prepare.FetchInfoStep
|
||||
import com.aliucord.manager.ui.components.dialogs.CustomComponentVersionPicker
|
||||
import org.koin.core.component.KoinComponent
|
||||
import org.koin.core.component.inject
|
||||
|
||||
|
|
@ -19,10 +22,12 @@ import org.koin.core.component.inject
|
|||
@Stable
|
||||
class DownloadInjectorStep : DownloadStep(), IDexProvider, KoinComponent {
|
||||
private val paths: PathManager by inject()
|
||||
private val overlays: OverlayManager by inject()
|
||||
|
||||
/**
|
||||
* This is populated right before the download starts (ref: [execute])
|
||||
*/
|
||||
private var isCustomVersion: Boolean = false
|
||||
lateinit var targetVersion: SemVer
|
||||
private set
|
||||
|
||||
|
|
@ -32,6 +37,39 @@ class DownloadInjectorStep : DownloadStep(), IDexProvider, KoinComponent {
|
|||
get() = paths.cachedInjectorDex(targetVersion)
|
||||
|
||||
override suspend fun execute(container: StepRunner) {
|
||||
var customVersions = mutableListOf<SemVer>()
|
||||
.apply { addAll(paths.customInjectorDexs()) }
|
||||
|
||||
// Prompt to select or manage custom versions instead of downloading
|
||||
if (customVersions.isNotEmpty()) {
|
||||
val selectedVersion = overlays.startComposableForResult { callback ->
|
||||
CustomComponentVersionPicker(
|
||||
componentTitle = "Injector",
|
||||
versions = customVersions,
|
||||
onConfirm = { version -> callback(version) },
|
||||
onDelete = { version ->
|
||||
try {
|
||||
paths.cachedInjectorDex(version, custom = true).delete()
|
||||
customVersions.remove(version)
|
||||
|
||||
// Dismiss if no custom versions left
|
||||
if (customVersions.isEmpty())
|
||||
callback(null)
|
||||
} catch (t: Throwable) {
|
||||
Log.e(BuildConfig.TAG, "Failed to delete custom component", t)
|
||||
}
|
||||
},
|
||||
onCancel = { callback(null) },
|
||||
)
|
||||
}
|
||||
if (selectedVersion != null) {
|
||||
isCustomVersion = true
|
||||
targetVersion = selectedVersion
|
||||
state = StepState.Skipped
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
targetVersion = container.getStep<FetchInfoStep>()
|
||||
.data.injectorVersion
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue