From da93bbc1fea27e33f958f8d7a34b31fec17f4bd1 Mon Sep 17 00:00:00 2001 From: vvb2060 Date: Tue, 20 Oct 2020 22:36:39 +0800 Subject: [PATCH] Fix network --- .../com/topjohnwu/magisk/core/tasks/RepoUpdater.kt | 4 ++-- .../topjohnwu/magisk/data/repository/NetworkService.kt | 10 ++-------- .../topjohnwu/magisk/ui/install/InstallViewModel.kt | 8 +++++++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/core/tasks/RepoUpdater.kt b/app/src/main/java/com/topjohnwu/magisk/core/tasks/RepoUpdater.kt index 878f10b68..009682b20 100644 --- a/app/src/main/java/com/topjohnwu/magisk/core/tasks/RepoUpdater.kt +++ b/app/src/main/java/com/topjohnwu/magisk/core/tasks/RepoUpdater.kt @@ -20,7 +20,7 @@ class RepoUpdater( val cachedMap = HashMap().also { map -> repoDB.getModuleStubs().forEach { map[it.id] = Date(it.last_update) } }.synchronized() - svc.fetchRepoInfo()?.also { info -> + svc.fetchRepoInfo()?.let { info -> coroutineScope { info.modules.forEach { launch { @@ -36,7 +36,7 @@ class RepoUpdater( } } } + repoDB.removeModules(cachedMap.keys) } - repoDB.removeModules(cachedMap.keys) } } diff --git a/app/src/main/java/com/topjohnwu/magisk/data/repository/NetworkService.kt b/app/src/main/java/com/topjohnwu/magisk/data/repository/NetworkService.kt index e1615ee81..d381febaf 100644 --- a/app/src/main/java/com/topjohnwu/magisk/data/repository/NetworkService.kt +++ b/app/src/main/java/com/topjohnwu/magisk/data/repository/NetworkService.kt @@ -20,7 +20,7 @@ class NetworkService( private val jsd: JSDelivrServices, private val api: GithubApiServices ) { - suspend fun fetchUpdate() = try { + suspend fun fetchUpdate() = safe { var info = when (Config.updateChannel) { DEFAULT_CHANNEL, STABLE_CHANNEL -> fetchStableUpdate() BETA_CHANNEL -> fetchBetaUpdate() @@ -36,12 +36,6 @@ class NetworkService( } Info.remote = info info - } catch (e: IOException) { - Timber.e(e) - null - } catch (e: HttpException) { - Timber.e(e) - null } // UpdateInfo @@ -69,7 +63,7 @@ class NetworkService( private inline fun safe(factory: () -> T): T? { return try { factory() - } catch (e: HttpException) { + } catch (e: Exception) { Timber.e(e) null } diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt index 3c04bfa52..010725a27 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/install/InstallViewModel.kt @@ -18,6 +18,8 @@ import com.topjohnwu.magisk.utils.set import com.topjohnwu.superuser.Shell import kotlinx.coroutines.launch import org.koin.core.get +import timber.log.Timber +import java.io.IOException import kotlin.math.roundToInt class InstallViewModel( @@ -64,7 +66,11 @@ class InstallViewModel( init { viewModelScope.launch { - notes = svc.fetchString(Info.remote.magisk.note) + try { + notes = svc.fetchString(Info.remote.magisk.note) + } catch (e: IOException) { + Timber.e(e) + } } }