Skip to content

Commit

Permalink
feat: custom injector selection
Browse files Browse the repository at this point in the history
  • Loading branch information
rushiiMachine committed Dec 25, 2024
1 parent 9864dd9 commit 04413c8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 04413c8

Please sign in to comment.