From c9bf49d3958323b3bf1215b4ebdba07d804c4968 Mon Sep 17 00:00:00 2001 From: wingio Date: Sat, 18 Mar 2023 12:30:54 -0400 Subject: [PATCH] Feat: Module updater --- app/build.gradle.kts | 4 ++-- app/release/output-metadata.json | 4 ++-- .../manager/domain/manager/PreferenceManager.kt | 2 ++ .../manager/domain/repository/RestRepository.kt | 2 +- .../manager/installer/service/InstallService.kt | 6 +++--- .../vendetta/manager/network/dto/Release.kt | 2 +- .../manager/network/service/RestService.kt | 4 ++-- .../manager/ui/screen/main/MainScreen.kt | 2 +- .../ui/viewmodel/installer/InstallerViewModel.kt | 2 +- .../manager/ui/viewmodel/main/MainViewModel.kt | 16 +++++++++++++--- 10 files changed, 28 insertions(+), 16 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 43a646a..accc489 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -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()}\"") diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json index 5decd45..b57fa20 100644 --- a/app/release/output-metadata.json +++ b/app/release/output-metadata.json @@ -11,8 +11,8 @@ "type": "SINGLE", "filters": [], "attributes": [], - "versionCode": 1011, - "versionName": "1.0.11", + "versionCode": 1020, + "versionName": "1.0.2", "outputFile": "app-release.apk" } ], diff --git a/app/src/main/java/dev/beefers/vendetta/manager/domain/manager/PreferenceManager.kt b/app/src/main/java/dev/beefers/vendetta/manager/domain/manager/PreferenceManager.kt index 75ff376..cc84d3f 100644 --- a/app/src/main/java/dev/beefers/vendetta/manager/domain/manager/PreferenceManager.kt +++ b/app/src/main/java/dev/beefers/vendetta/manager/domain/manager/PreferenceManager.kt @@ -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) diff --git a/app/src/main/java/dev/beefers/vendetta/manager/domain/repository/RestRepository.kt b/app/src/main/java/dev/beefers/vendetta/manager/domain/repository/RestRepository.kt index d433235..2617665 100644 --- a/app/src/main/java/dev/beefers/vendetta/manager/domain/repository/RestRepository.kt +++ b/app/src/main/java/dev/beefers/vendetta/manager/domain/repository/RestRepository.kt @@ -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( diff --git a/app/src/main/java/dev/beefers/vendetta/manager/installer/service/InstallService.kt b/app/src/main/java/dev/beefers/vendetta/manager/installer/service/InstallService.kt index 8508480..7207548 100644 --- a/app/src/main/java/dev/beefers/vendetta/manager/installer/service/InstallService.kt +++ b/app/src/main/java/dev/beefers/vendetta/manager/installer/service/InstallService.kt @@ -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) } } diff --git a/app/src/main/java/dev/beefers/vendetta/manager/network/dto/Release.kt b/app/src/main/java/dev/beefers/vendetta/manager/network/dto/Release.kt index d13dd56..5ac480c 100644 --- a/app/src/main/java/dev/beefers/vendetta/manager/network/dto/Release.kt +++ b/app/src/main/java/dev/beefers/vendetta/manager/network/dto/Release.kt @@ -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 ) \ No newline at end of file diff --git a/app/src/main/java/dev/beefers/vendetta/manager/network/service/RestService.kt b/app/src/main/java/dev/beefers/vendetta/manager/network/service/RestService.kt index 03dde5e..faf62f7 100644 --- a/app/src/main/java/dev/beefers/vendetta/manager/network/service/RestService.kt +++ b/app/src/main/java/dev/beefers/vendetta/manager/network/service/RestService.kt @@ -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 { - url("https://api.github.com/repos/vendetta-mod/VendettaManager/releases/latest") + url("https://api.github.com/repos/vendetta-mod/$repo/releases/latest") } } diff --git a/app/src/main/java/dev/beefers/vendetta/manager/ui/screen/main/MainScreen.kt b/app/src/main/java/dev/beefers/vendetta/manager/ui/screen/main/MainScreen.kt index 81aa667..7649203 100644 --- a/app/src/main/java/dev/beefers/vendetta/manager/ui/screen/main/MainScreen.kt +++ b/app/src/main/java/dev/beefers/vendetta/manager/ui/screen/main/MainScreen.kt @@ -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() } diff --git a/app/src/main/java/dev/beefers/vendetta/manager/ui/viewmodel/installer/InstallerViewModel.kt b/app/src/main/java/dev/beefers/vendetta/manager/ui/viewmodel/installer/InstallerViewModel.kt index 27c51a2..fdb7c7a 100644 --- a/app/src/main/java/dev/beefers/vendetta/manager/ui/viewmodel/installer/InstallerViewModel.kt +++ b/app/src/main/java/dev/beefers/vendetta/manager/ui/viewmodel/installer/InstallerViewModel.kt @@ -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") diff --git a/app/src/main/java/dev/beefers/vendetta/manager/ui/viewmodel/main/MainViewModel.kt b/app/src/main/java/dev/beefers/vendetta/manager/ui/viewmodel/main/MainViewModel.kt index 57d3091..212eea1 100644 --- a/app/src/main/java/dev/beefers/vendetta/manager/ui/viewmodel/main/MainViewModel.kt +++ b/app/src/main/java/dev/beefers/vendetta/manager/ui/viewmodel/main/MainViewModel.kt @@ -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(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) }