Don't assume installed version matches app

This commit is contained in:
vvb2060 2021-12-05 17:11:09 +08:00 committed by John Wu
parent bb7a74e4b4
commit 571b8986a4
2 changed files with 34 additions and 24 deletions

View File

@ -1,38 +1,48 @@
package com.topjohnwu.magisk.events.dialog
import androidx.lifecycle.lifecycleScope
import com.topjohnwu.magisk.BuildConfig
import com.topjohnwu.magisk.R
import com.topjohnwu.magisk.core.Info
import com.topjohnwu.magisk.core.base.BaseActivity
import com.topjohnwu.magisk.core.tasks.MagiskInstaller
import com.topjohnwu.magisk.ui.home.HomeViewModel
import com.topjohnwu.magisk.view.MagiskDialog
import kotlinx.coroutines.launch
class EnvFixDialog : DialogEvent() {
class EnvFixDialog(private val vm: HomeViewModel) : DialogEvent() {
override fun build(dialog: MagiskDialog) = dialog
.applyTitle(R.string.env_fix_title)
.applyMessage(R.string.env_fix_msg)
.applyButton(MagiskDialog.ButtonType.POSITIVE) {
titleRes = android.R.string.ok
preventDismiss = true
onClick {
dialog.applyTitle(R.string.setup_title)
.applyMessage(R.string.setup_msg)
.resetButtons()
.cancellable(false)
(dialog.ownerActivity as BaseActivity).lifecycleScope.launch {
MagiskInstaller.FixEnv {
dialog.dismiss()
}.exec()
override fun build(dialog: MagiskDialog) {
dialog.applyTitle(R.string.env_fix_title)
.applyMessage(R.string.env_fix_msg)
.applyButton(MagiskDialog.ButtonType.POSITIVE) {
titleRes = android.R.string.ok
preventDismiss = true
onClick {
dialog.applyTitle(R.string.setup_title)
.applyMessage(R.string.setup_msg)
.resetButtons()
.cancellable(false)
(dialog.ownerActivity as BaseActivity).lifecycleScope.launch {
MagiskInstaller.FixEnv {
dialog.dismiss()
}.exec()
}
}
}
.applyButton(MagiskDialog.ButtonType.NEGATIVE) {
titleRes = android.R.string.cancel
}
if (Info.env.versionCode != BuildConfig.VERSION_CODE ||
Info.env.versionString != BuildConfig.VERSION_NAME) {
dialog.applyButton(MagiskDialog.ButtonType.POSITIVE) {
titleRes = android.R.string.ok
onClick {
vm.onMagiskPressed()
dialog.dismiss()
}
}
}
.applyButton(MagiskDialog.ButtonType.NEGATIVE) {
titleRes = android.R.string.cancel
}
.let { }
companion object {
const val DISMISS = "com.topjohnwu.magisk.ENV_DONE"
}
}

View File

@ -140,7 +140,7 @@ class HomeViewModel(
val cmd = "env_check ${Info.env.versionString} ${Info.env.versionCode}"
if (!Shell.su(cmd).await().isSuccess) {
shownDialog = true
EnvFixDialog().publish()
EnvFixDialog(this).publish()
}
}