Handle CancellationException

This commit is contained in:
Mygod
2021-10-25 01:11:53 -04:00
parent 7fa39e9994
commit dd0d58af67
2 changed files with 5 additions and 0 deletions

View File

@@ -14,6 +14,7 @@ import timber.log.Timber
import java.net.HttpURLConnection
import java.net.URL
import java.time.Instant
import java.util.concurrent.CancellationException
import java.util.concurrent.TimeUnit
import kotlin.math.max
@@ -56,6 +57,8 @@ object UpdateChecker {
putLong(KEY_PUBLISHED, published)
}
emit(if (myVersion == version) null else GitHubUpdate(version, published))
} catch (e: CancellationException) {
return@flow
} catch (e: Exception) {
Timber.w(e)
} finally {

View File

@@ -26,6 +26,7 @@ import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import timber.log.Timber
import java.net.Inet4Address
import java.util.concurrent.CancellationException
class MainActivity : AppCompatActivity(), NavigationBarView.OnItemSelectedListener {
lateinit var binding: ActivityMainBinding
@@ -65,6 +66,7 @@ class MainActivity : AppCompatActivity(), NavigationBarView.OnItemSelectedListen
onAppUpdateAvailable(null)
try {
UpdateChecker.check().collect(this@MainActivity::onAppUpdateAvailable)
} catch (_: CancellationException) {
} catch (e: Exception) {
Timber.w(e)
SmartSnackbar.make(e).show()