From 3190ab79c8d840becc5d55e5e89378c2b0c8ee9a Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 11 May 2022 09:55:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../legado/app/data/entities/BookChapter.kt | 3 +++ .../io/legado/app/help/ContentProcessor.kt | 24 +++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt index 38d6794cb..4a46bde8a 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt @@ -16,6 +16,7 @@ import io.legado.app.help.config.AppConfig import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.RuleDataInterface import io.legado.app.utils.* +import kotlinx.coroutines.CancellationException import kotlinx.parcelize.IgnoredOnParcel import kotlinx.parcelize.Parcelize import splitties.init.appCtx @@ -113,6 +114,8 @@ data class BookChapter( } catch (e: RegexTimeoutException) { item.isEnabled = false appDb.replaceRuleDao.update(item) + } catch (e: CancellationException) { + return displayTitle } catch (e: Exception) { AppLog.put("${item.name}替换出错\n替换内容\n${displayTitle}", e) appCtx.toastOnUi("${item.name}替换出错") diff --git a/app/src/main/java/io/legado/app/help/ContentProcessor.kt b/app/src/main/java/io/legado/app/help/ContentProcessor.kt index 480b092cd..466b348a6 100644 --- a/app/src/main/java/io/legado/app/help/ContentProcessor.kt +++ b/app/src/main/java/io/legado/app/help/ContentProcessor.kt @@ -12,6 +12,7 @@ import io.legado.app.help.config.ReadBookConfig import io.legado.app.utils.msg import io.legado.app.utils.replace import io.legado.app.utils.toastOnUi +import kotlinx.coroutines.CancellationException import splitties.init.appCtx import java.lang.ref.WeakReference import java.util.concurrent.CopyOnWriteArrayList @@ -135,7 +136,7 @@ class ContentProcessor private constructor( var mContent = content getContentReplaceRules().forEach { item -> if (item.pattern.isNotEmpty()) { - kotlin.runCatching { + try { mContent = if (item.isRegex) { mContent.replace( item.pattern.toRegex(), @@ -145,18 +146,15 @@ class ContentProcessor private constructor( } else { mContent.replace(item.pattern, item.replacement) } - }.onFailure { - when (it) { - is RegexTimeoutException -> { - item.isEnabled = false - appDb.replaceRuleDao.update(item) - return item.name + it.msg - } - else -> { - AppLog.put("${item.name}替换出错\n替换内容\n${mContent}", it) - appCtx.toastOnUi("${item.name}替换出错") - } - } + } catch (e: RegexTimeoutException) { + item.isEnabled = false + appDb.replaceRuleDao.update(item) + return item.name + e.msg + } catch (e: CancellationException) { + return mContent + } catch (e: Exception) { + AppLog.put("${item.name}替换出错\n替换内容\n${mContent}", e) + appCtx.toastOnUi("${item.name}替换出错") } } }