Feat: Module updater

This commit is contained in:
wingio 2023-03-18 12:30:54 -04:00
parent 1c10f338b3
commit c9bf49d395
10 changed files with 28 additions and 16 deletions

View File

@ -14,8 +14,8 @@ android {
applicationId = "dev.beefers.vendetta.manager" applicationId = "dev.beefers.vendetta.manager"
minSdk = 24 minSdk = 24
targetSdk = 33 targetSdk = 33
versionCode = 1012 versionCode = 1020
versionName = "1.0.12" versionName = "1.0.2"
buildConfigField("String", "GIT_BRANCH", "\"${getCurrentBranch()}\"") buildConfigField("String", "GIT_BRANCH", "\"${getCurrentBranch()}\"")
buildConfigField("String", "GIT_COMMIT", "\"${getLatestCommit()}\"") buildConfigField("String", "GIT_COMMIT", "\"${getLatestCommit()}\"")

View File

@ -11,8 +11,8 @@
"type": "SINGLE", "type": "SINGLE",
"filters": [], "filters": [],
"attributes": [], "attributes": [],
"versionCode": 1011, "versionCode": 1020,
"versionName": "1.0.11", "versionName": "1.0.2",
"outputFile": "app-release.apk" "outputFile": "app-release.apk"
} }
], ],

View File

@ -16,6 +16,8 @@ class PreferenceManager(private val context: Context) :
var discordVersion by stringPreference("discord_version", "") var discordVersion by stringPreference("discord_version", "")
var moduleVersion by stringPreference("module_version", "")
var patchIcon by booleanPreference("patch_icon", true) var patchIcon by booleanPreference("patch_icon", true)
var debuggable by booleanPreference("debuggable", false) var debuggable by booleanPreference("debuggable", false)

View File

@ -8,7 +8,7 @@ class RestRepository(
private val service: RestService private val service: RestService
) { ) {
suspend fun getLatestRelease() = service.getLatestRelease() suspend fun getLatestRelease(repo: String) = service.getLatestRelease(repo)
suspend fun getLatestDiscordVersions() = service.getLatestDiscordVersions().transform { suspend fun getLatestDiscordVersions() = service.getLatestDiscordVersions().transform {
mapOf( mapOf(

View File

@ -26,14 +26,14 @@ class InstallService : Service(), KoinComponent {
} }
PackageInstaller.STATUS_SUCCESS -> { PackageInstaller.STATUS_SUCCESS -> {
if(isInstall) showToast(R.string.installer_success) if (isInstall) showToast(R.string.installer_success)
installManager.getInstalled() 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 -> { else -> {
if(isInstall) showToast(R.string.installer_failed, statusCode) if (isInstall) showToast(R.string.installer_failed, statusCode)
} }
} }

View File

@ -5,6 +5,6 @@ import kotlinx.serialization.Serializable
@Serializable @Serializable
data class Release( data class Release(
@SerialName("tag_name") val versionCode: Int, @SerialName("tag_name") val tagName: String,
@SerialName("name") val versionName: String @SerialName("name") val versionName: String
) )

View File

@ -10,9 +10,9 @@ class RestService(
private val httpService: HttpService private val httpService: HttpService
) { ) {
suspend fun getLatestRelease() = withContext(Dispatchers.IO) { suspend fun getLatestRelease(repo: String) = withContext(Dispatchers.IO) {
httpService.request<Release> { 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")
} }
} }

View File

@ -43,7 +43,7 @@ class MainScreen : Screen {
modifier = Modifier.fillMaxSize() modifier = Modifier.fillMaxSize()
) { pv -> ) { pv ->
viewModel.release?.let { viewModel.release?.let {
if (it.versionCode > BuildConfig.VERSION_CODE) { if (it.tagName.toInt() > BuildConfig.VERSION_CODE) {
UpdateDialog(release = it) { UpdateDialog(release = it) {
viewModel.downloadAndInstallUpdate() viewModel.downloadAndInstallUpdate()
} }

View File

@ -247,7 +247,7 @@ class InstallerViewModel(
// Download vendetta apk // Download vendetta apk
val vendetta = step(InstallStep.DL_VD) { 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") logger.i("Checking if vendetta.apk is cached")
if (file.exists()) { if (file.exists()) {
logger.i("vendetta.apk is cached") logger.i("vendetta.apk is cached")

View File

@ -7,19 +7,22 @@ import androidx.compose.runtime.setValue
import cafe.adriel.voyager.core.model.ScreenModel import cafe.adriel.voyager.core.model.ScreenModel
import cafe.adriel.voyager.core.model.coroutineScope import cafe.adriel.voyager.core.model.coroutineScope
import dev.beefers.vendetta.manager.domain.manager.DownloadManager 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.domain.repository.RestRepository
import dev.beefers.vendetta.manager.installer.util.installApks import dev.beefers.vendetta.manager.installer.util.installApks
import dev.beefers.vendetta.manager.network.dto.Release import dev.beefers.vendetta.manager.network.dto.Release
import dev.beefers.vendetta.manager.network.utils.dataOrNull import dev.beefers.vendetta.manager.network.utils.dataOrNull
import dev.beefers.vendetta.manager.network.utils.ifSuccessful
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.io.File import java.io.File
class MainViewModel( class MainViewModel(
private val repo: RestRepository, private val repo: RestRepository,
private val downloadManager: DownloadManager, private val downloadManager: DownloadManager,
private val preferenceManager: PreferenceManager,
private val context: Context private val context: Context
) : ScreenModel { ) : ScreenModel {
private val downloadDir = context.externalCacheDir private val cacheDir = context.externalCacheDir
var release by mutableStateOf<Release?>(null) var release by mutableStateOf<Release?>(null)
private set private set
@ -29,13 +32,20 @@ class MainViewModel(
private fun checkForUpdate() { private fun checkForUpdate() {
coroutineScope.launch { 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() { fun downloadAndInstallUpdate() {
coroutineScope.launch { coroutineScope.launch {
val update = File(downloadDir, "update.apk") val update = File(cacheDir, "update.apk")
downloadManager.downloadUpdate(update) downloadManager.downloadUpdate(update)
context.installApks(false, update) context.installApks(false, update)
} }