Feat: Improved updater
This commit is contained in:
parent
0865784c1c
commit
f11ee11b5f
14 changed files with 67 additions and 97 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -38,6 +38,7 @@ captures/
|
|||
|
||||
# IntelliJ
|
||||
*.iml
|
||||
.idea
|
||||
.idea/workspace.xml
|
||||
.idea/tasks.xml
|
||||
.idea/gradle.xml
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
Vendetta Manager
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="me.schlaubi.intellij_gradle_version_checker.settings.ProjectPersistentGradleVersionSettings">
|
||||
<option name="ignoreOutdatedVersion" value="true" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="17" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DiscordProjectSettings">
|
||||
<option name="show" value="PROJECT_FILES" />
|
||||
<option name="description" value="" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,35 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Maven Central repository" />
|
||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="jboss.community" />
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="MavenRepo" />
|
||||
<option name="name" value="MavenRepo" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="maven" />
|
||||
<option name="name" value="maven" />
|
||||
<option name="url" value="https://maven.aliucord.com/snapshots" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="Google" />
|
||||
<option name="name" value="Google" />
|
||||
<option name="url" value="https://dl.google.com/dl/android/maven2/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="maven2" />
|
||||
<option name="name" value="maven2" />
|
||||
<option name="url" value="https://jitpack.io" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="KotlinJpsPluginSettings">
|
||||
<option name="version" value="1.7.20" />
|
||||
</component>
|
||||
</project>
|
|
@ -1,5 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK" />
|
||||
</project>
|
1
app/.gitignore
vendored
1
app/.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
/build
|
||||
/release
|
|
@ -14,8 +14,8 @@ android {
|
|||
applicationId = "dev.beefers.vendetta.manager"
|
||||
minSdk = 24
|
||||
targetSdk = 33
|
||||
versionCode = 1030
|
||||
versionName = "1.0.3"
|
||||
versionCode = 1040
|
||||
versionName = "1.0.4"
|
||||
|
||||
buildConfigField("String", "GIT_BRANCH", "\"${getCurrentBranch()}\"")
|
||||
buildConfigField("String", "GIT_COMMIT", "\"${getLatestCommit()}\"")
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
{
|
||||
"version": 3,
|
||||
"artifactType": {
|
||||
"type": "APK",
|
||||
"kind": "Directory"
|
||||
},
|
||||
"applicationId": "dev.beefers.vendetta.manager",
|
||||
"variantName": "release",
|
||||
"elements": [
|
||||
{
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"attributes": [],
|
||||
"versionCode": 1030,
|
||||
"versionName": "1.0.3",
|
||||
"outputFile": "app-release.apk"
|
||||
}
|
||||
],
|
||||
"elementType": "File"
|
||||
}
|
|
@ -42,12 +42,15 @@ class MainScreen : Screen {
|
|||
topBar = { TitleBar() },
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) { pv ->
|
||||
viewModel.release?.let {
|
||||
if (it.tagName.toInt() > BuildConfig.VERSION_CODE) {
|
||||
UpdateDialog(release = it) {
|
||||
if (viewModel.showUpdateDialog && viewModel.release != null) {
|
||||
UpdateDialog(
|
||||
release = viewModel.release!!,
|
||||
isUpdating = viewModel.isUpdating,
|
||||
onDismiss = { viewModel.showUpdateDialog = false },
|
||||
onConfirm = {
|
||||
viewModel.downloadAndInstallUpdate()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
HorizontalPager(
|
||||
|
|
|
@ -6,6 +6,7 @@ import androidx.compose.runtime.mutableStateOf
|
|||
import androidx.compose.runtime.setValue
|
||||
import cafe.adriel.voyager.core.model.ScreenModel
|
||||
import cafe.adriel.voyager.core.model.coroutineScope
|
||||
import dev.beefers.vendetta.manager.BuildConfig
|
||||
import dev.beefers.vendetta.manager.domain.manager.DownloadManager
|
||||
import dev.beefers.vendetta.manager.domain.manager.PreferenceManager
|
||||
import dev.beefers.vendetta.manager.domain.repository.RestRepository
|
||||
|
@ -26,6 +27,10 @@ class MainViewModel(
|
|||
var release by mutableStateOf<Release?>(null)
|
||||
private set
|
||||
|
||||
var showUpdateDialog by mutableStateOf(false)
|
||||
|
||||
var isUpdating by mutableStateOf(false)
|
||||
|
||||
init {
|
||||
checkForUpdate()
|
||||
}
|
||||
|
@ -33,6 +38,9 @@ class MainViewModel(
|
|||
private fun checkForUpdate() {
|
||||
coroutineScope.launch {
|
||||
release = repo.getLatestRelease("VendettaManager").dataOrNull
|
||||
release?.let {
|
||||
showUpdateDialog = it.tagName.toInt() > BuildConfig.VERSION_CODE
|
||||
}
|
||||
repo.getLatestRelease("VendettaXposed").ifSuccessful {
|
||||
if (preferenceManager.moduleVersion != it.tagName) {
|
||||
preferenceManager.moduleVersion = it.tagName
|
||||
|
@ -46,7 +54,10 @@ class MainViewModel(
|
|||
fun downloadAndInstallUpdate() {
|
||||
coroutineScope.launch {
|
||||
val update = File(cacheDir, "update.apk")
|
||||
if(update.exists()) update.delete()
|
||||
isUpdating = true
|
||||
downloadManager.downloadUpdate(update)
|
||||
isUpdating = false
|
||||
context.installApks(false, update)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,33 +1,73 @@
|
|||
package dev.beefers.vendetta.manager.ui.widgets.updater
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.SystemUpdate
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.FilledTonalButton
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.LocalContentColor
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import dev.beefers.vendetta.manager.R
|
||||
import dev.beefers.vendetta.manager.network.dto.Release
|
||||
|
||||
@Composable
|
||||
fun UpdateDialog(
|
||||
release: Release,
|
||||
isUpdating: Boolean,
|
||||
onDismiss: () -> Unit,
|
||||
onConfirm: () -> Unit
|
||||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = {},
|
||||
properties = DialogProperties(
|
||||
dismissOnBackPress = true,
|
||||
dismissOnClickOutside = true
|
||||
),
|
||||
onDismissRequest = {
|
||||
onDismiss()
|
||||
},
|
||||
confirmButton = {
|
||||
FilledTonalButton(onClick = onConfirm) {
|
||||
Text(stringResource(R.string.action_start_update))
|
||||
FilledTonalButton(
|
||||
onClick = onConfirm,
|
||||
enabled = !isUpdating
|
||||
) {
|
||||
Box {
|
||||
Text(
|
||||
text = stringResource(R.string.action_start_update),
|
||||
color = if(isUpdating) Color.Transparent else LocalContentColor.current
|
||||
)
|
||||
if(isUpdating) {
|
||||
CircularProgressIndicator(
|
||||
strokeWidth = 3.dp,
|
||||
modifier = Modifier
|
||||
.size(24.dp)
|
||||
.align(Alignment.Center)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
title = {
|
||||
Text(stringResource(R.string.title_update))
|
||||
},
|
||||
text = {
|
||||
Text(stringResource(R.string.update_description, release.versionName))
|
||||
Text(
|
||||
text = stringResource(R.string.update_description, release.versionName),
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
},
|
||||
icon = {
|
||||
Icon(
|
||||
|
|
Loading…
Reference in a new issue