Handle CancellationException
This commit is contained in:
@@ -14,6 +14,7 @@ import timber.log.Timber
|
|||||||
import java.net.HttpURLConnection
|
import java.net.HttpURLConnection
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
|
import java.util.concurrent.CancellationException
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
|
|
||||||
@@ -56,6 +57,8 @@ object UpdateChecker {
|
|||||||
putLong(KEY_PUBLISHED, published)
|
putLong(KEY_PUBLISHED, published)
|
||||||
}
|
}
|
||||||
emit(if (myVersion == version) null else GitHubUpdate(version, published))
|
emit(if (myVersion == version) null else GitHubUpdate(version, published))
|
||||||
|
} catch (e: CancellationException) {
|
||||||
|
return@flow
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.w(e)
|
Timber.w(e)
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import kotlinx.coroutines.flow.collect
|
|||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
import java.net.Inet4Address
|
import java.net.Inet4Address
|
||||||
|
import java.util.concurrent.CancellationException
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity(), NavigationBarView.OnItemSelectedListener {
|
class MainActivity : AppCompatActivity(), NavigationBarView.OnItemSelectedListener {
|
||||||
lateinit var binding: ActivityMainBinding
|
lateinit var binding: ActivityMainBinding
|
||||||
@@ -65,6 +66,7 @@ class MainActivity : AppCompatActivity(), NavigationBarView.OnItemSelectedListen
|
|||||||
onAppUpdateAvailable(null)
|
onAppUpdateAvailable(null)
|
||||||
try {
|
try {
|
||||||
UpdateChecker.check().collect(this@MainActivity::onAppUpdateAvailable)
|
UpdateChecker.check().collect(this@MainActivity::onAppUpdateAvailable)
|
||||||
|
} catch (_: CancellationException) {
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.w(e)
|
Timber.w(e)
|
||||||
SmartSnackbar.make(e).show()
|
SmartSnackbar.make(e).show()
|
||||||
|
|||||||
Reference in New Issue
Block a user