mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-30 21:45:27 +00:00
Added env fix prompt
This commit is contained in:
parent
147264822c
commit
6b045eadef
@ -12,3 +12,4 @@ class ManagerChangelogEvent : ViewEvent()
|
||||
class MagiskChangelogEvent : ViewEvent()
|
||||
|
||||
class UninstallEvent : ViewEvent()
|
||||
class EnvFixEvent : ViewEvent()
|
||||
|
@ -10,6 +10,7 @@ import com.topjohnwu.magisk.ui.base.MagiskViewModel
|
||||
import com.topjohnwu.magisk.utils.Event
|
||||
import com.topjohnwu.magisk.utils.toggle
|
||||
import com.topjohnwu.net.Networking
|
||||
import com.topjohnwu.superuser.Shell
|
||||
|
||||
|
||||
class HomeViewModel(
|
||||
@ -65,6 +66,7 @@ class HomeViewModel(
|
||||
""
|
||||
}
|
||||
|
||||
private var shownDialog = false
|
||||
private val current = resources.getString(R.string.current_installed)
|
||||
private val latest = resources.getString(R.string.latest_version)
|
||||
|
||||
@ -73,7 +75,11 @@ class HomeViewModel(
|
||||
refresh()
|
||||
}
|
||||
|
||||
override fun onEvent(event: Int) = updateSelf()
|
||||
override fun onEvent(event: Int) {
|
||||
updateSelf()
|
||||
ensureEnv()
|
||||
}
|
||||
|
||||
override fun getListeningEvents(): IntArray = intArrayOf(Event.UPDATE_CHECK_DONE)
|
||||
|
||||
fun paypalPressed() = OpenLinkEvent(Const.Url.PAYPAL_URL).publish()
|
||||
@ -96,6 +102,7 @@ class HomeViewModel(
|
||||
}
|
||||
|
||||
fun refresh() {
|
||||
shownDialog = false
|
||||
state = State.LOADING
|
||||
magiskState.value = MagiskState.LOADING
|
||||
managerState.value = MagiskState.LOADING
|
||||
@ -139,6 +146,18 @@ class HomeViewModel(
|
||||
.let { latest.format(it) }
|
||||
}
|
||||
|
||||
private fun ensureEnv() {
|
||||
val invalidStates = listOf(MagiskState.NOT_INSTALLED, MagiskState.NO_ROOT, MagiskState.LOADING)
|
||||
|
||||
// Don't bother checking env when magisk is not installed, loading or already has been shown
|
||||
if (invalidStates.any { it == magiskState.value } || shownDialog) return
|
||||
|
||||
if (!Shell.su("env_check").exec().isSuccess) {
|
||||
shownDialog = true
|
||||
EnvFixEvent().publish()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val version = "%s (%d)"
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import com.topjohnwu.magisk.R
|
||||
import com.topjohnwu.magisk.model.events.*
|
||||
import com.topjohnwu.magisk.utils.Event
|
||||
import com.topjohnwu.magisk.view.MarkDownWindow
|
||||
import com.topjohnwu.magisk.view.dialogs.EnvFixDialog
|
||||
import com.topjohnwu.magisk.view.dialogs.ManagerInstallDialog
|
||||
import com.topjohnwu.magisk.view.dialogs.UninstallDialog
|
||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||
@ -61,6 +62,7 @@ class MagiskFragment : NewMagiskFragment<HomeViewModel, com.topjohnwu.magisk.dat
|
||||
is MagiskInstallEvent -> installMagisk()
|
||||
is UninstallEvent -> uninstall()
|
||||
is ManagerChangelogEvent -> changelogManager()
|
||||
is EnvFixEvent -> fixEnv()
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,17 +77,11 @@ class MagiskFragment : NewMagiskFragment<HomeViewModel, com.topjohnwu.magisk.dat
|
||||
}
|
||||
|
||||
private fun installManager() = ManagerInstallDialog(requireActivity()).show()
|
||||
private fun uninstall() = UninstallDialog(requireActivity()).show()
|
||||
private fun fixEnv() = EnvFixDialog(requireActivity()).show()
|
||||
|
||||
private fun uninstall() {
|
||||
UninstallDialog(requireActivity()).show()
|
||||
}
|
||||
|
||||
private fun changelogManager() {
|
||||
MarkDownWindow.show(
|
||||
requireActivity(), null,
|
||||
resources.openRawResource(R.raw.changelog)
|
||||
)
|
||||
}
|
||||
private fun changelogManager() = MarkDownWindow
|
||||
.show(requireActivity(), null, resources.openRawResource(R.raw.changelog))
|
||||
|
||||
/*override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
|
Loading…
Reference in New Issue
Block a user