Forgot to handle error :P

This commit is contained in:
Pupil
2020-01-15 10:58:53 +09:00
parent 93228459d7
commit e0ccac13c1
6 changed files with 21 additions and 9 deletions

View File

@@ -151,12 +151,25 @@ fun checkUpdate(context: AppCompatActivity, force: Boolean = false) {
priority = NotificationCompat.PRIORITY_LOW
}
CoroutineScope(Dispatchers.IO).launch {
CoroutineScope(Dispatchers.IO).launch io@{
val target = File(getDownloadDirectory(context), "Pupil.apk")
URL(url).download(target) { progress, fileSize ->
builder.setProgress(fileSize.toInt(), progress.toInt(), false)
try {
URL(url).download(target) { progress, fileSize ->
builder.setProgress(fileSize.toInt(), progress.toInt(), false)
notificationManager.notify(UPDATE_NOTIFICATION_ID, builder.build())
}
} catch (e: Exception) {
builder.apply {
setContentText(context.getString(R.string.update_failed))
setMessage(context.getString(R.string.update_failed_message))
setSmallIcon(android.R.drawable.stat_sys_download_done)
}
notificationManager.cancel(UPDATE_NOTIFICATION_ID)
notificationManager.notify(UPDATE_NOTIFICATION_ID, builder.build())
return@io
}
val install = Intent(Intent.ACTION_VIEW).apply {