feat: add bootstrap
This commit is contained in:
parent
7dfe592cb3
commit
a6039a53d6
5 changed files with 38 additions and 0 deletions
|
|
@ -38,6 +38,9 @@ class DownloadManager(
|
|||
suspend fun downloadKotlinDex(out: File): File =
|
||||
download(AliucordGithubService.KOTLIN_DEX_URL, out)
|
||||
|
||||
suspend fun downloadBootstrap(out: File): File =
|
||||
download(AliucordGithubService.BOOTSTRAP_URL, out)
|
||||
|
||||
suspend fun download(url: String, out: File): File {
|
||||
out.parentFile?.mkdirs()
|
||||
|
||||
|
|
|
|||
|
|
@ -16,4 +16,5 @@ class GithubRepository(
|
|||
suspend fun getHermesRelease() = service.getLatestHermesRelease()
|
||||
suspend fun getAliucordNativeRelease() = service.getLatestAliucordNativeRelease()
|
||||
suspend fun getManagerReleases() = service.getManagerReleases()
|
||||
suspend fun getLatestBootstrapCommit() = service.getLatestBootstrapCommit()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
package com.aliucord.manager.network.service
|
||||
|
||||
import com.aliucord.manager.network.dto.Commit
|
||||
import com.aliucord.manager.network.dto.Version
|
||||
import com.aliucord.manager.network.utils.ApiResponse
|
||||
import com.aliucord.manager.network.utils.transform
|
||||
import io.ktor.client.request.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
|
@ -18,6 +20,16 @@ class AliucordGithubService(
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun getLatestBootstrapCommit(): ApiResponse<String> {
|
||||
return withContext(Dispatchers.IO) {
|
||||
http.request<List<Commit>> {
|
||||
url("https://api.github.com/repos/$ORG/$RN_REPO/commits?sha=builds&path=bootstrap.js&per_page=1")
|
||||
}.transform {
|
||||
it.single().sha
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getCommits(page: Int = 0) = github.getCommits(ORG, MAIN_REPO, page)
|
||||
suspend fun getLatestHermesRelease() = github.getLatestRelease(ORG, HERMES_REPO)
|
||||
suspend fun getLatestAliucordNativeRelease() = github.getLatestRelease(ORG, ALIUNATIVE_REPO)
|
||||
|
|
@ -27,10 +39,12 @@ class AliucordGithubService(
|
|||
companion object {
|
||||
private const val ORG = "Aliucord"
|
||||
private const val MAIN_REPO = "Aliucord"
|
||||
private const val RN_REPO = "AliucordRN"
|
||||
private const val HERMES_REPO = "Hermes"
|
||||
private const val ALIUNATIVE_REPO = "AliucordNative"
|
||||
private const val MANAGER_REPO = "AliucordManager"
|
||||
|
||||
const val BOOTSTRAP_URL = "https://raw.githubusercontent.com/$ORG/$RN_REPO/builds/bootstrap.js"
|
||||
const val KT_INJECTOR_URL = "https://raw.githubusercontent.com/$ORG/$MAIN_REPO/builds/Injector.dex"
|
||||
const val KOTLIN_DEX_URL = "https://raw.githubusercontent.com/$ORG/$MAIN_REPO/main/installer/android/app/src/main/assets/kotlin/classes.dex"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,6 +153,7 @@ class InstallViewModel(
|
|||
InstallStep.DL_RESC_APK,
|
||||
InstallStep.DL_HERMES,
|
||||
InstallStep.DL_ALIUNATIVE,
|
||||
InstallStep.DL_BOOTSTRAP,
|
||||
if (preferences.replaceIcon) InstallStep.PATCH_APP_ICON else null,
|
||||
InstallStep.PATCH_MANIFEST,
|
||||
InstallStep.PATCH_DEX,
|
||||
|
|
@ -292,6 +293,20 @@ class InstallViewModel(
|
|||
}
|
||||
}
|
||||
|
||||
// Download AliucordRN bootstrap
|
||||
val aliucordBootstrap = step(InstallStep.DL_BOOTSTRAP) {
|
||||
// Fetch latest commit for bootstrap.js
|
||||
val commit = githubRepository.getLatestBootstrapCommit().getOrThrow()
|
||||
cacheDir.resolve("bootstrap-$commit.js").also {
|
||||
if (it.exists()) {
|
||||
cached = true
|
||||
return@also
|
||||
}
|
||||
|
||||
downloadManager.downloadBootstrap(it)
|
||||
}
|
||||
}
|
||||
|
||||
val apks = arrayOf(baseApkFile, libsApkFile, localeApkFile, resApkFile)
|
||||
|
||||
// Replace app icons
|
||||
|
|
@ -360,6 +375,9 @@ class InstallViewModel(
|
|||
|
||||
// Add Aliucord's .dex and make it load first by being the first .dex
|
||||
zip.writeEntry("classes.dex", aliucordDexFile.readBytes())
|
||||
|
||||
// Add bootstrap
|
||||
zip.writeEntry("bootstrap.js", aliucordBootstrap.readBytes(), ZipCompression.NONE)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -642,6 +660,7 @@ class InstallViewModel(
|
|||
|
||||
DL_HERMES(InstallStepGroup.LIB_DL, R.string.install_step_dl_lib_hermes),
|
||||
DL_ALIUNATIVE(InstallStepGroup.LIB_DL, R.string.install_step_dl_lib_aliunative),
|
||||
DL_BOOTSTRAP(InstallStepGroup.LIB_DL, R.string.install_step_dl_bootstrap),
|
||||
|
||||
// Kotlin
|
||||
FETCH_KT_VERSION(InstallStepGroup.APK_DL, R.string.install_step_fetch_kt_version),
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@
|
|||
<string name="install_step_dl_apk_resource">Downloading resource apk</string>
|
||||
<string name="install_step_dl_lib_hermes">Downloading hermes library</string>
|
||||
<string name="install_step_dl_lib_aliunative">Downloading AliucordNative library</string>
|
||||
<string name="install_step_dl_bootstrap">Downloading bootstrap</string>
|
||||
<string name="install_step_fetch_kt_version">Fetching target Discord version</string>
|
||||
<string name="install_step_dl_kt_apk">Downloading Discord APK</string>
|
||||
<string name="install_step_dl_kotlin">Downloading Kotlin library</string>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue