Feat: Module updater
This commit is contained in:
parent
1c10f338b3
commit
c9bf49d395
10 changed files with 28 additions and 16 deletions
|
@ -14,8 +14,8 @@ android {
|
|||
applicationId = "dev.beefers.vendetta.manager"
|
||||
minSdk = 24
|
||||
targetSdk = 33
|
||||
versionCode = 1012
|
||||
versionName = "1.0.12"
|
||||
versionCode = 1020
|
||||
versionName = "1.0.2"
|
||||
|
||||
buildConfigField("String", "GIT_BRANCH", "\"${getCurrentBranch()}\"")
|
||||
buildConfigField("String", "GIT_COMMIT", "\"${getLatestCommit()}\"")
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"attributes": [],
|
||||
"versionCode": 1011,
|
||||
"versionName": "1.0.11",
|
||||
"versionCode": 1020,
|
||||
"versionName": "1.0.2",
|
||||
"outputFile": "app-release.apk"
|
||||
}
|
||||
],
|
||||
|
|
|
@ -16,6 +16,8 @@ class PreferenceManager(private val context: Context) :
|
|||
|
||||
var discordVersion by stringPreference("discord_version", "")
|
||||
|
||||
var moduleVersion by stringPreference("module_version", "")
|
||||
|
||||
var patchIcon by booleanPreference("patch_icon", true)
|
||||
|
||||
var debuggable by booleanPreference("debuggable", false)
|
||||
|
|
|
@ -8,7 +8,7 @@ class RestRepository(
|
|||
private val service: RestService
|
||||
) {
|
||||
|
||||
suspend fun getLatestRelease() = service.getLatestRelease()
|
||||
suspend fun getLatestRelease(repo: String) = service.getLatestRelease(repo)
|
||||
|
||||
suspend fun getLatestDiscordVersions() = service.getLatestDiscordVersions().transform {
|
||||
mapOf(
|
||||
|
|
|
@ -26,14 +26,14 @@ class InstallService : Service(), KoinComponent {
|
|||
}
|
||||
|
||||
PackageInstaller.STATUS_SUCCESS -> {
|
||||
if(isInstall) showToast(R.string.installer_success)
|
||||
if (isInstall) showToast(R.string.installer_success)
|
||||
installManager.getInstalled()
|
||||
}
|
||||
|
||||
PackageInstaller.STATUS_FAILURE_ABORTED -> if(isInstall) showToast(R.string.installer_aborted)
|
||||
PackageInstaller.STATUS_FAILURE_ABORTED -> if (isInstall) showToast(R.string.installer_aborted)
|
||||
|
||||
else -> {
|
||||
if(isInstall) showToast(R.string.installer_failed, statusCode)
|
||||
if (isInstall) showToast(R.string.installer_failed, statusCode)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,6 @@ import kotlinx.serialization.Serializable
|
|||
|
||||
@Serializable
|
||||
data class Release(
|
||||
@SerialName("tag_name") val versionCode: Int,
|
||||
@SerialName("tag_name") val tagName: String,
|
||||
@SerialName("name") val versionName: String
|
||||
)
|
|
@ -10,9 +10,9 @@ class RestService(
|
|||
private val httpService: HttpService
|
||||
) {
|
||||
|
||||
suspend fun getLatestRelease() = withContext(Dispatchers.IO) {
|
||||
suspend fun getLatestRelease(repo: String) = withContext(Dispatchers.IO) {
|
||||
httpService.request<Release> {
|
||||
url("https://api.github.com/repos/vendetta-mod/VendettaManager/releases/latest")
|
||||
url("https://api.github.com/repos/vendetta-mod/$repo/releases/latest")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ class MainScreen : Screen {
|
|||
modifier = Modifier.fillMaxSize()
|
||||
) { pv ->
|
||||
viewModel.release?.let {
|
||||
if (it.versionCode > BuildConfig.VERSION_CODE) {
|
||||
if (it.tagName.toInt() > BuildConfig.VERSION_CODE) {
|
||||
UpdateDialog(release = it) {
|
||||
viewModel.downloadAndInstallUpdate()
|
||||
}
|
||||
|
|
|
@ -247,7 +247,7 @@ class InstallerViewModel(
|
|||
|
||||
// Download vendetta apk
|
||||
val vendetta = step(InstallStep.DL_VD) {
|
||||
discordCacheDir.resolve("vendetta.apk").let { file ->
|
||||
cacheDir.resolve("vendetta.apk").let { file ->
|
||||
logger.i("Checking if vendetta.apk is cached")
|
||||
if (file.exists()) {
|
||||
logger.i("vendetta.apk is cached")
|
||||
|
|
|
@ -7,19 +7,22 @@ import androidx.compose.runtime.setValue
|
|||
import cafe.adriel.voyager.core.model.ScreenModel
|
||||
import cafe.adriel.voyager.core.model.coroutineScope
|
||||
import dev.beefers.vendetta.manager.domain.manager.DownloadManager
|
||||
import dev.beefers.vendetta.manager.domain.manager.PreferenceManager
|
||||
import dev.beefers.vendetta.manager.domain.repository.RestRepository
|
||||
import dev.beefers.vendetta.manager.installer.util.installApks
|
||||
import dev.beefers.vendetta.manager.network.dto.Release
|
||||
import dev.beefers.vendetta.manager.network.utils.dataOrNull
|
||||
import dev.beefers.vendetta.manager.network.utils.ifSuccessful
|
||||
import kotlinx.coroutines.launch
|
||||
import java.io.File
|
||||
|
||||
class MainViewModel(
|
||||
private val repo: RestRepository,
|
||||
private val downloadManager: DownloadManager,
|
||||
private val preferenceManager: PreferenceManager,
|
||||
private val context: Context
|
||||
) : ScreenModel {
|
||||
private val downloadDir = context.externalCacheDir
|
||||
private val cacheDir = context.externalCacheDir
|
||||
var release by mutableStateOf<Release?>(null)
|
||||
private set
|
||||
|
||||
|
@ -29,13 +32,20 @@ class MainViewModel(
|
|||
|
||||
private fun checkForUpdate() {
|
||||
coroutineScope.launch {
|
||||
release = repo.getLatestRelease().dataOrNull
|
||||
release = repo.getLatestRelease("VendettaManager").dataOrNull
|
||||
repo.getLatestRelease("VendettaXposed").ifSuccessful {
|
||||
if (preferenceManager.moduleVersion != it.tagName) {
|
||||
preferenceManager.moduleVersion = it.tagName
|
||||
val module = File(cacheDir, "vendetta.apk")
|
||||
if (module.exists()) module.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun downloadAndInstallUpdate() {
|
||||
coroutineScope.launch {
|
||||
val update = File(downloadDir, "update.apk")
|
||||
val update = File(cacheDir, "update.apk")
|
||||
downloadManager.downloadUpdate(update)
|
||||
context.installApks(false, update)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue