From 04413c84aa01c5483a441617c89b8fd16a83f098 Mon Sep 17 00:00:00 2001 From: rushiiMachine <33725716+rushiiMachine@users.noreply.github.com> Date: Tue, 24 Dec 2024 17:22:21 -0800 Subject: [PATCH] feat: custom injector selection --- .../aliucord/manager/manager/PathManager.kt | 9 +++- .../steps/download/DownloadInjectorStep.kt | 42 ++++++++++++++++++- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/com/aliucord/manager/manager/PathManager.kt b/app/src/main/kotlin/com/aliucord/manager/manager/PathManager.kt index fc9f018..aca9ed7 100644 --- a/app/src/main/kotlin/com/aliucord/manager/manager/PathManager.kt +++ b/app/src/main/kotlin/com/aliucord/manager/manager/PathManager.kt @@ -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 diff --git a/app/src/main/kotlin/com/aliucord/manager/patcher/steps/download/DownloadInjectorStep.kt b/app/src/main/kotlin/com/aliucord/manager/patcher/steps/download/DownloadInjectorStep.kt index ba6d121..e561815 100644 --- a/app/src/main/kotlin/com/aliucord/manager/patcher/steps/download/DownloadInjectorStep.kt +++ b/app/src/main/kotlin/com/aliucord/manager/patcher/steps/download/DownloadInjectorStep.kt @@ -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() + .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() .data.injectorVersion