优化
Some checks failed
Test Build / prepare (push) Has been cancelled
Test Build / build (app, release) (push) Has been cancelled
Test Build / build (app, releaseA) (push) Has been cancelled
Test Build / prerelease (push) Has been cancelled
Test Build / lanzou (push) Has been cancelled
Test Build / test_Branch (push) Has been cancelled
Test Build / telegram (push) Has been cancelled

This commit is contained in:
Horis
2025-04-21 14:31:09 +08:00
parent e9f85d1e19
commit c060880b49
14 changed files with 51 additions and 6 deletions

View File

@@ -1,5 +1,6 @@
package io.legado.app.help.source
import com.script.rhino.runScriptWithContext
import io.legado.app.constant.BookSourceType
import io.legado.app.constant.BookType
import io.legado.app.data.entities.BookSource
@@ -11,7 +12,6 @@ import io.legado.app.utils.MD5Utils
import io.legado.app.utils.fromJsonArray
import io.legado.app.utils.isJsonArray
import io.legado.app.utils.printOnDebug
import com.script.rhino.runScriptWithContext
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
@@ -96,6 +96,14 @@ suspend fun BookSourcePart.clearExploreKindsCache() {
}
}
suspend fun BookSource.clearExploreKindsCache() {
withContext(Dispatchers.IO) {
val exploreKindsKey = getExploreKindsKey()
aCache.remove(exploreKindsKey)
exploreKindsMap.remove(exploreKindsKey)
}
}
fun BookSource.getBookType(): Int {
return when (bookSourceType) {
BookSourceType.file -> BookType.text or BookType.webFile

View File

@@ -1,5 +1,6 @@
package io.legado.app.model
import androidx.collection.LruCache
import com.google.gson.reflect.TypeToken
import com.script.ScriptBindings
import com.script.rhino.RhinoScriptEngine
@@ -24,7 +25,7 @@ object SharedJsScope {
private val cacheFolder = File(appCtx.cacheDir, "shareJs")
private val aCache = ACache.get(cacheFolder)
private val scopeMap = hashMapOf<String, WeakReference<Scriptable>>()
private val scopeMap = LruCache<String, WeakReference<Scriptable>>(16)
fun getScope(jsLib: String?, coroutineContext: CoroutineContext?): Scriptable? {
if (jsLib.isNullOrBlank()) {
@@ -70,7 +71,7 @@ object SharedJsScope {
if (scope is ScriptableObject) {
scope.sealObject()
}
scopeMap[key] = WeakReference(scope)
scopeMap.put(key, WeakReference(scope))
}
return scope
}

View File

@@ -11,6 +11,7 @@ import androidx.lifecycle.lifecycleScope
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.databinding.ActivitySourceDebugBinding
import io.legado.app.help.source.clearExploreKindsCache
import io.legado.app.help.source.exploreKinds
import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.theme.accentColor
@@ -117,6 +118,10 @@ class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookS
binding.textContent.onClick {
prefixAutoComplete("--")
}
initExploreKinds()
}
private fun initExploreKinds() {
lifecycleScope.launch {
val exploreKinds = viewModel.bookSource?.exploreKinds()?.filter {
!it.url.isNullOrBlank()
@@ -188,6 +193,10 @@ class BookSourceDebugActivity : VMBaseActivity<ActivitySourceDebugBinding, BookS
R.id.menu_book_src -> showDialogFragment(TextDialog("html", viewModel.bookSrc))
R.id.menu_toc_src -> showDialogFragment(TextDialog("html", viewModel.tocSrc))
R.id.menu_content_src -> showDialogFragment(TextDialog("html", viewModel.contentSrc))
R.id.menu_refresh_explore -> lifecycleScope.launch {
viewModel.bookSource?.clearExploreKindsCache()
initExploreKinds()
}
R.id.menu_help -> showHelp("debugHelp")
}
return super.onCompatOptionsItemSelected(item)

View File

@@ -123,7 +123,7 @@ class BookSourceEditActivity :
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_save -> viewModel.save(getSource()) {
setResult(Activity.RESULT_OK, Intent().putExtra("origin", it.bookSourceUrl))
setResult(RESULT_OK, Intent().putExtra("origin", it.bookSourceUrl))
finish()
}

View File

@@ -12,8 +12,18 @@ import io.legado.app.help.config.SourceConfig
import io.legado.app.help.http.CookieStore
import io.legado.app.help.http.newCallStrResponse
import io.legado.app.help.http.okHttpClient
import io.legado.app.help.source.clearExploreKindsCache
import io.legado.app.help.storage.ImportOldData
import io.legado.app.utils.*
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonArray
import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.getClipText
import io.legado.app.utils.isAbsUrl
import io.legado.app.utils.isJsonArray
import io.legado.app.utils.isJsonObject
import io.legado.app.utils.jsonPath
import io.legado.app.utils.printOnDebug
import io.legado.app.utils.toastOnUi
import kotlinx.coroutines.Dispatchers
@@ -41,8 +51,12 @@ class BookSourceEditViewModel(application: Application) : BaseViewModel(applicat
if (source.bookSourceUrl.isBlank() || source.bookSourceName.isBlank()) {
throw NoStackTraceException(context.getString(R.string.non_null_name_url))
}
if (!source.equal(bookSource ?: BookSource())) {
val oldSource = bookSource ?: BookSource()
if (!source.equal(oldSource)) {
source.lastUpdateTime = System.currentTimeMillis()
if (oldSource.exploreUrl != source.exploreUrl) {
oldSource.clearExploreKindsCache()
}
}
bookSource?.let {
appDb.bookSourceDao.delete(it)

View File

@@ -30,6 +30,11 @@
android:title="@string/content_src"
app:showAsAction="never" />
<item
android:id="@+id/menu_refresh_explore"
android:title="@string/refresh_explore"
app:showAsAction="never" />
<item
android:id="@+id/menu_help"
android:title="@string/help"

View File

@@ -1209,4 +1209,5 @@
<string name="enable_manga_horizontal_scroll">水平滚动</string>
<string name="manga_color_filter">滤镜</string>
<string name="hide_manga_title">隐藏漫画列表标题</string>
<string name="refresh_explore">刷新发现</string>
</resources>

View File

@@ -1212,4 +1212,5 @@
<string name="enable_manga_horizontal_scroll">水平滚动</string>
<string name="manga_color_filter">滤镜</string>
<string name="hide_manga_title">隐藏漫画列表标题</string>
<string name="refresh_explore">刷新发现</string>
</resources>

View File

@@ -1212,4 +1212,5 @@
<string name="enable_manga_horizontal_scroll">水平滚动</string>
<string name="manga_color_filter">滤镜</string>
<string name="hide_manga_title">隐藏漫画列表标题</string>
<string name="refresh_explore">刷新发现</string>
</resources>

View File

@@ -1208,4 +1208,5 @@ Còn </string>
<string name="enable_manga_horizontal_scroll">水平滚动</string>
<string name="manga_color_filter">滤镜</string>
<string name="hide_manga_title">隐藏漫画列表标题</string>
<string name="refresh_explore">刷新发现</string>
</resources>

View File

@@ -1209,4 +1209,5 @@
<string name="enable_manga_horizontal_scroll">水平滚动</string>
<string name="manga_color_filter">滤镜</string>
<string name="hide_manga_title">隐藏漫画列表标题</string>
<string name="refresh_explore">刷新发现</string>
</resources>

View File

@@ -1211,4 +1211,5 @@
<string name="enable_manga_horizontal_scroll">水平滚动</string>
<string name="manga_color_filter">滤镜</string>
<string name="hide_manga_title">隐藏漫画列表标题</string>
<string name="refresh_explore">刷新发现</string>
</resources>

View File

@@ -1211,4 +1211,5 @@
<string name="enable_manga_horizontal_scroll">水平滚动</string>
<string name="manga_color_filter">滤镜</string>
<string name="hide_manga_title">隐藏漫画列表标题</string>
<string name="refresh_explore">刷新发现</string>
</resources>

View File

@@ -1212,4 +1212,5 @@
<string name="enable_manga_horizontal_scroll">水平滚动</string>
<string name="manga_color_filter">滤镜</string>
<string name="hide_manga_title">隐藏漫画列表标题</string>
<string name="refresh_explore">刷新发现</string>
</resources>