Address Build Warnings and Cleanup (#707)

* Address build warnings and cleanup

* Actual name of who defined the protocol

* Remove uneeded detekt supression

* GraphQL Before-After cleanup

* Lint

* Cleanup unused functions

* Fix some discrepancies with the 1.5 source api and fix lang exception
This commit is contained in:
Mitchell Syer
2023-10-15 20:16:30 -04:00
committed by GitHub
parent e70730e9a8
commit 682c364647
31 changed files with 151 additions and 278 deletions

View File

@@ -8,7 +8,9 @@ import kotlinx.coroutines.withContext
/**
* Util for evaluating JavaScript in sources.
*/
class JavaScriptEngine(context: Context) {
class JavaScriptEngine(
@Suppress("UNUSED_PARAMETER") context: Context,
) {
/**
* Evaluate arbitrary JavaScript code and get the result as a primitive type
* (e.g., String, Int).

View File

@@ -25,6 +25,7 @@ class CloudflareInterceptor : Interceptor {
private val network: NetworkHelper by injectLazy()
@Suppress("UNUSED_VARIABLE", "UNREACHABLE_CODE")
override fun intercept(chain: Interceptor.Chain): Response {
val originalRequest = chain.request()
@@ -141,6 +142,7 @@ object CFClearance {
.build()
}
@Suppress("UNREACHABLE_CODE")
fun getWebViewUserAgent(): String {
return try {
throw PlaywrightException("playwrite is diabled for v0.6.7")

View File

@@ -9,7 +9,7 @@ interface CatalogueSource : Source {
/**
* An ISO 639-1 compliant language code (two letters in lower case).
*/
val lang: String
override val lang: String
/**
* Whether the source has support for latest updates.

View File

@@ -18,8 +18,10 @@ interface ConfigurableSource : Source {
fun setupPreferenceScreen(screen: PreferenceScreen)
}
private fun ConfigurableSource.preferenceKey(): String = "source_$id"
fun ConfigurableSource.preferenceKey(): String = "source_$id"
// TODO: use getSourcePreferences once all extensions are on ext-lib 1.5
fun ConfigurableSource.sourcePreferences(): SharedPreferences =
Injekt.get<Application>().getSharedPreferences(preferenceKey(), Context.MODE_PRIVATE)
fun sourcePreferences(key: String): SharedPreferences = Injekt.get<Application>().getSharedPreferences(key, Context.MODE_PRIVATE)

View File

@@ -7,11 +7,11 @@ import rx.Observable
import suwayomi.tachidesk.manga.impl.util.lang.awaitSingle
/**
* A basic interface for creating a source. It could be an online source, a local source, etc...
* A basic interface for creating a source. It could be an online source, a local source, etc.
*/
interface Source {
/**
* Id for the source. Must be unique.
* ID for the source. Must be unique.
*/
val id: Long
@@ -20,6 +20,9 @@ interface Source {
*/
val name: String
val lang: String
get() = ""
/**
* Get the updated details for a manga.
*
@@ -73,9 +76,7 @@ interface Source {
"Use the non-RxJava API instead",
ReplaceWith("getPageList"),
)
fun fetchPageList(chapter: SChapter): Observable<List<Page>> = Observable.empty()
fun fetchPageList(chapter: SChapter): Observable<List<Page>> = throw IllegalStateException("Not used")
}
// fun Source.icon(): Drawable? = Injekt.get<ExtensionManager>().getAppIconForSource(this)
fun Source.getPreferenceKey(): String = "source_$id"

View File

@@ -32,6 +32,7 @@ import kotlinx.coroutines.withContext
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
import mu.KotlinLogging
import nl.adaptivity.xmlutil.ExperimentalXmlUtilApi
import nl.adaptivity.xmlutil.core.KtXmlReader
import nl.adaptivity.xmlutil.serialization.XML
import org.apache.commons.compress.archivers.zip.ZipFile
@@ -271,6 +272,7 @@ class LocalSource(
}
}
@OptIn(ExperimentalXmlUtilApi::class)
private fun setMangaDetailsFromComicInfoFile(
stream: InputStream,
manga: SManga,

View File

@@ -26,18 +26,12 @@ import java.security.MessageDigest
/**
* A simple implementation for sources from a website.
*/
@Suppress("unused")
abstract class HttpSource : CatalogueSource {
/**
* Network service.
*/
val network: NetworkHelper by injectLazy()
// /**
// * Preferences that a source may need.
// */
// val preferences: SharedPreferences by lazy {
// Injekt.get<Application>().getSharedPreferences(source.getPreferenceKey(), Context.MODE_PRIVATE)
// }
protected val network: NetworkHelper by injectLazy()
/**
* Base url of the website without the trailing slash, like: http://mysite.com
@@ -60,7 +54,7 @@ abstract class HttpSource : CatalogueSource {
*
* Note: the generated ID sets the sign bit to `0`.
*/
override val id by lazy { generateId(name, lang, versionId) }
override val id by lazy { generateId() }
/**
* Headers used for requests.
@@ -73,6 +67,10 @@ abstract class HttpSource : CatalogueSource {
open val client: OkHttpClient
get() = network.client
private fun generateId(): Long {
return generateId(name, lang, versionId)
}
/**
* Generates a unique ID for the source based on the provided [name], [lang] and
* [versionId]. It will use the first 16 characters (64 bits) of the MD5 of the string
@@ -89,6 +87,7 @@ abstract class HttpSource : CatalogueSource {
* @param versionId [Int] the version ID of the source
* @return a unique ID for the source
*/
@Suppress("MemberVisibilityCanBePrivate")
protected fun generateId(
name: String,
lang: String,
@@ -155,8 +154,15 @@ abstract class HttpSource : CatalogueSource {
query: String,
filters: FilterList,
): Observable<MangasPage> {
return client.newCall(searchMangaRequest(page, query, filters))
.asObservableSuccess()
return Observable.defer {
try {
client.newCall(searchMangaRequest(page, query, filters)).asObservableSuccess()
} catch (e: NoClassDefFoundError) {
// RxJava doesn't handle Errors, which tends to happen during global searches
// if an old extension using non-existent classes is still around
throw RuntimeException(e)
}
}
.map { response ->
searchMangaParse(response)
}
@@ -387,7 +393,7 @@ abstract class HttpSource : CatalogueSource {
*
* @param page the chapter whose page list has to be fetched
*/
open fun imageRequest(page: Page): Request {
protected open fun imageRequest(page: Page): Request {
return GET(page.imageUrl!!, headers)
}
@@ -418,7 +424,7 @@ abstract class HttpSource : CatalogueSource {
*/
private fun getUrlWithoutDomain(orig: String): String {
return try {
val uri = URI(orig)
val uri = URI(orig.replace(" ", "%20"))
var out = uri.path
if (uri.query != null) {
out += "?" + uri.query