Commit 50edb8d0 authored by topjohnwu's avatar topjohnwu

Better network detection and invalidation

parent 515f8194
......@@ -10,7 +10,6 @@ import com.topjohnwu.magisk.core.repository.NetworkService
import com.topjohnwu.magisk.core.utils.net.NetworkObserver
import com.topjohnwu.magisk.ktx.getProperty
import com.topjohnwu.superuser.ShellUtils.fastCmd
import com.topjohnwu.superuser.internal.UiThreadHandler
val isRunningAsStub get() = Info.stub != null
......@@ -47,7 +46,8 @@ object Info {
val isConnected: LiveData<Boolean> by lazy {
MutableLiveData(false).also { field ->
NetworkObserver.observe(AppContext) {
UiThreadHandler.run { field.value = it }
remote = EMPTY_REMOTE
field.postValue(it)
}
}
}
......
......@@ -46,7 +46,10 @@ class NetworkService(
private inline fun <T> safe(factory: () -> T): T? {
return try {
if (Info.isConnected.value == true)
factory()
else
null
} catch (e: Exception) {
Timber.e(e)
null
......
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