Skip to content

Commit

Permalink
Fixed magisk version
Browse files Browse the repository at this point in the history
Added refreshing versions before and after the request to remote
  • Loading branch information
diareuse committed Aug 22, 2019
1 parent 021994c commit 39e9622
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject


abstract class MagiskViewModel : LoadingViewModel() {
abstract class MagiskViewModel(
initialState: State = State.LOADING
) : LoadingViewModel(initialState) {

val isConnected = KObservableField(true)

Expand Down
24 changes: 14 additions & 10 deletions app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ enum class MagiskItem {

class HomeViewModel(
private val magiskRepo: MagiskRepository
) : MagiskViewModel() {
) : MagiskViewModel(State.LOADED) {

val hasGMS = runCatching {
get<PackageManager>().getPackageInfo("com.google.android.gms", 0); true
Expand Down Expand Up @@ -177,14 +177,7 @@ class HomeViewModel(
}

fun refresh() {
magiskCurrentVersion.value = if (magiskState.value != MagiskState.NOT_INSTALLED) {
version.format(Info.magiskVersionString, Info.magiskVersionCode)
} else {
""
}

managerCurrentVersion.value = version
.format(BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE)
refreshVersions()

magiskRepo.fetchUpdate()
.applyViewModel(this)
Expand All @@ -198,13 +191,24 @@ class HomeViewModel(
.subscribeK {
updateSelf()
ensureEnv()
refreshVersions()
}

hasRoot.value = Shell.rootAccess()
}

private fun refreshVersions() {
magiskCurrentVersion.value = if (magiskState.value != MagiskState.NOT_INSTALLED) {
version.format(Info.magiskVersionString, Info.magiskVersionCode)
} else {
""
}

managerCurrentVersion.value = version
.format(BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE)
}

private fun updateSelf() {
state = State.LOADED
_magiskState.value = when (Info.magiskVersionCode) {
in Int.MIN_VALUE until 0 -> MagiskState.NOT_INSTALLED
!in Info.remote.magisk.versionCode..Int.MAX_VALUE -> MagiskState.OBSOLETE
Expand Down

0 comments on commit 39e9622

Please sign in to comment.