fix: move try inside withContext

This commit is contained in:
rebelonion 2024-05-24 13:34:39 -05:00
parent 945018653e
commit a5304477c7

View file

@ -201,8 +201,8 @@ class AnimeDownloaderService : Service() {
@androidx.annotation.OptIn(UnstableApi::class) @androidx.annotation.OptIn(UnstableApi::class)
suspend fun download(task: AnimeDownloadTask) { suspend fun download(task: AnimeDownloadTask) {
try {
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
try {
val notifi = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { val notifi = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
ContextCompat.checkSelfPermission( ContextCompat.checkSelfPermission(
this@AnimeDownloaderService, this@AnimeDownloaderService,
@ -226,10 +226,14 @@ class AnimeDownloaderService : Service() {
) ?: throw Exception("Failed to create output directory") ) ?: throw Exception("Failed to create output directory")
val extension = ffExtension!!.getFileExtension() val extension = ffExtension!!.getFileExtension()
outputDir.findFile("${task.getTaskName().findValidName()}.${extension.first}")?.delete() outputDir.findFile("${task.getTaskName().findValidName()}.${extension.first}")
?.delete()
val outputFile = val outputFile =
outputDir.createFile(extension.second, "${task.getTaskName()}.${extension.first}") outputDir.createFile(
extension.second,
"${task.getTaskName()}.${extension.first}"
)
?: throw Exception("Failed to create output file") ?: throw Exception("Failed to create output file")
var percent = 0 var percent = 0
@ -385,7 +389,6 @@ class AnimeDownloaderService : Service() {
broadcastDownloadFinished(task.episode) broadcastDownloadFinished(task.episode)
} else throw Exception("Download failed") } else throw Exception("Download failed")
}
} catch (e: Exception) { } catch (e: Exception) {
if (e.message?.contains("Coroutine was cancelled") == false) { //wut if (e.message?.contains("Coroutine was cancelled") == false) { //wut
Logger.log("Exception while downloading file: ${e.message}") Logger.log("Exception while downloading file: ${e.message}")
@ -396,6 +399,7 @@ class AnimeDownloaderService : Service() {
broadcastDownloadFailed(task.episode) broadcastDownloadFailed(task.episode)
} }
} }
}
private fun saveMediaInfo(task: AnimeDownloadTask) { private fun saveMediaInfo(task: AnimeDownloadTask) {
CoroutineScope(Dispatchers.IO).launch { CoroutineScope(Dispatchers.IO).launch {