Commit e799918a authored by topjohnwu's avatar topjohnwu

Update update check service

parent 86c4928e
...@@ -4,7 +4,6 @@ import androidx.work.ListenableWorker ...@@ -4,7 +4,6 @@ import androidx.work.ListenableWorker
import com.topjohnwu.magisk.BuildConfig import com.topjohnwu.magisk.BuildConfig
import com.topjohnwu.magisk.Config import com.topjohnwu.magisk.Config
import com.topjohnwu.magisk.data.repository.MagiskRepository import com.topjohnwu.magisk.data.repository.MagiskRepository
import com.topjohnwu.magisk.model.entity.MagiskConfig
import com.topjohnwu.magisk.model.worker.DelegateWorker import com.topjohnwu.magisk.model.worker.DelegateWorker
import com.topjohnwu.magisk.utils.inject import com.topjohnwu.magisk.utils.inject
import com.topjohnwu.magisk.view.Notifications import com.topjohnwu.magisk.view.Notifications
...@@ -14,18 +13,15 @@ class UpdateCheckService : DelegateWorker() { ...@@ -14,18 +13,15 @@ class UpdateCheckService : DelegateWorker() {
private val magiskRepo: MagiskRepository by inject() private val magiskRepo: MagiskRepository by inject()
override fun doWork(): ListenableWorker.Result { override fun doWork(): ListenableWorker.Result {
val config = runCatching { magiskRepo.fetchConfig().blockingGet() } return runCatching {
config.getOrNull()?.let { checkUpdates(it) } magiskRepo.fetchConfig().blockingGet()
return when { if (BuildConfig.VERSION_CODE < Config.remoteManagerVersionCode)
config.isFailure -> ListenableWorker.Result.failure() Notifications.managerUpdate()
else -> ListenableWorker.Result.success() else if (Config.magiskVersionCode < Config.remoteManagerVersionCode)
} Notifications.magiskUpdate()
} ListenableWorker.Result.success()
}.getOrElse {
private fun checkUpdates(config: MagiskConfig) { ListenableWorker.Result.failure()
when {
BuildConfig.VERSION_CODE < config.app.versionCode.toIntOrNull() ?: -1 -> Notifications.managerUpdate()
Config.magiskVersionCode < config.magisk.versionCode.toIntOrNull() ?: -1 -> Notifications.magiskUpdate()
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment