优化
This commit is contained in:
@@ -26,12 +26,15 @@ import io.legado.app.help.config.AppConfig
|
|||||||
import io.legado.app.help.config.ThemeConfig.applyDayNight
|
import io.legado.app.help.config.ThemeConfig.applyDayNight
|
||||||
import io.legado.app.help.coroutine.Coroutine
|
import io.legado.app.help.coroutine.Coroutine
|
||||||
import io.legado.app.help.http.Cronet
|
import io.legado.app.help.http.Cronet
|
||||||
|
import io.legado.app.help.http.ObsoleteUrlFactory
|
||||||
|
import io.legado.app.help.http.okHttpClient
|
||||||
import io.legado.app.model.BookCover
|
import io.legado.app.model.BookCover
|
||||||
import io.legado.app.utils.defaultSharedPreferences
|
import io.legado.app.utils.defaultSharedPreferences
|
||||||
import io.legado.app.utils.getPrefBoolean
|
import io.legado.app.utils.getPrefBoolean
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import splitties.init.appCtx
|
import splitties.init.appCtx
|
||||||
import splitties.systemservices.notificationManager
|
import splitties.systemservices.notificationManager
|
||||||
|
import java.net.URL
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
class App : Application() {
|
class App : Application() {
|
||||||
@@ -53,6 +56,7 @@ class App : Application() {
|
|||||||
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(AppConfig)
|
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(AppConfig)
|
||||||
DefaultData.upVersion()
|
DefaultData.upVersion()
|
||||||
Coroutine.async {
|
Coroutine.async {
|
||||||
|
URL.setURLStreamHandlerFactory(ObsoleteUrlFactory(okHttpClient))
|
||||||
launch { installGmsTlsProvider(appCtx) }
|
launch { installGmsTlsProvider(appCtx) }
|
||||||
//初始化封面
|
//初始化封面
|
||||||
BookCover.toString()
|
BookCover.toString()
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import io.legado.app.data.entities.BaseSource
|
|||||||
import io.legado.app.exception.NoStackTraceException
|
import io.legado.app.exception.NoStackTraceException
|
||||||
import io.legado.app.help.http.BackstageWebView
|
import io.legado.app.help.http.BackstageWebView
|
||||||
import io.legado.app.help.http.CookieManager
|
import io.legado.app.help.http.CookieManager
|
||||||
|
import io.legado.app.help.http.CookieManager.cookieJarHeader
|
||||||
import io.legado.app.help.http.CookieStore
|
import io.legado.app.help.http.CookieStore
|
||||||
import io.legado.app.help.http.SSLHelper
|
import io.legado.app.help.http.SSLHelper
|
||||||
import io.legado.app.help.http.StrResponse
|
import io.legado.app.help.http.StrResponse
|
||||||
@@ -279,52 +280,55 @@ interface JsExtensions : JsEncodeUtils {
|
|||||||
/**
|
/**
|
||||||
* js实现重定向拦截,网络访问get
|
* js实现重定向拦截,网络访问get
|
||||||
*/
|
*/
|
||||||
|
@Suppress("UnnecessaryVariable")
|
||||||
fun get(urlStr: String, headers: Map<String, String>): Connection.Response {
|
fun get(urlStr: String, headers: Map<String, String>): Connection.Response {
|
||||||
|
val requestHeaders = if (getSource()?.enabledCookieJar == true) {
|
||||||
|
headers.toMutableMap().apply { put(cookieJarHeader, "1") }
|
||||||
|
} else headers
|
||||||
val response = Jsoup.connect(urlStr)
|
val response = Jsoup.connect(urlStr)
|
||||||
.sslSocketFactory(SSLHelper.unsafeSSLSocketFactory)
|
.sslSocketFactory(SSLHelper.unsafeSSLSocketFactory)
|
||||||
.ignoreContentType(true)
|
.ignoreContentType(true)
|
||||||
.followRedirects(false)
|
.followRedirects(false)
|
||||||
.headers(headers)
|
.headers(requestHeaders)
|
||||||
.method(Connection.Method.GET)
|
.method(Connection.Method.GET)
|
||||||
.execute()
|
.execute()
|
||||||
if (getSource()?.enabledCookieJar == true) {
|
|
||||||
CookieManager.saveResponse(response)
|
|
||||||
}
|
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* js实现重定向拦截,网络访问head,不返回Response Body更省流量
|
* js实现重定向拦截,网络访问head,不返回Response Body更省流量
|
||||||
*/
|
*/
|
||||||
|
@Suppress("UnnecessaryVariable")
|
||||||
fun head(urlStr: String, headers: Map<String, String>): Connection.Response {
|
fun head(urlStr: String, headers: Map<String, String>): Connection.Response {
|
||||||
|
val requestHeaders = if (getSource()?.enabledCookieJar == true) {
|
||||||
|
headers.toMutableMap().apply { put(cookieJarHeader, "1") }
|
||||||
|
} else headers
|
||||||
val response = Jsoup.connect(urlStr)
|
val response = Jsoup.connect(urlStr)
|
||||||
.sslSocketFactory(SSLHelper.unsafeSSLSocketFactory)
|
.sslSocketFactory(SSLHelper.unsafeSSLSocketFactory)
|
||||||
.ignoreContentType(true)
|
.ignoreContentType(true)
|
||||||
.followRedirects(false)
|
.followRedirects(false)
|
||||||
.headers(headers)
|
.headers(requestHeaders)
|
||||||
.method(Connection.Method.HEAD)
|
.method(Connection.Method.HEAD)
|
||||||
.execute()
|
.execute()
|
||||||
if (getSource()?.enabledCookieJar == true) {
|
|
||||||
CookieManager.saveResponse(response)
|
|
||||||
}
|
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 网络访问post
|
* 网络访问post
|
||||||
*/
|
*/
|
||||||
|
@Suppress("UnnecessaryVariable")
|
||||||
fun post(urlStr: String, body: String, headers: Map<String, String>): Connection.Response {
|
fun post(urlStr: String, body: String, headers: Map<String, String>): Connection.Response {
|
||||||
|
val requestHeaders = if (getSource()?.enabledCookieJar == true) {
|
||||||
|
headers.toMutableMap().apply { put(cookieJarHeader, "1") }
|
||||||
|
} else headers
|
||||||
val response = Jsoup.connect(urlStr)
|
val response = Jsoup.connect(urlStr)
|
||||||
.sslSocketFactory(SSLHelper.unsafeSSLSocketFactory)
|
.sslSocketFactory(SSLHelper.unsafeSSLSocketFactory)
|
||||||
.ignoreContentType(true)
|
.ignoreContentType(true)
|
||||||
.followRedirects(false)
|
.followRedirects(false)
|
||||||
.requestBody(body)
|
.requestBody(body)
|
||||||
.headers(headers)
|
.headers(requestHeaders)
|
||||||
.method(Connection.Method.POST)
|
.method(Connection.Method.POST)
|
||||||
.execute()
|
.execute()
|
||||||
if (getSource()?.enabledCookieJar == true) {
|
|
||||||
CookieManager.saveResponse(response)
|
|
||||||
}
|
|
||||||
return response
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -511,6 +515,7 @@ interface JsExtensions : JsEncodeUtils {
|
|||||||
fun unzipFile(zipPath: String): String {
|
fun unzipFile(zipPath: String): String {
|
||||||
return unArchiveFile(zipPath)
|
return unArchiveFile(zipPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* js实现7Zip压缩文件解压
|
* js实现7Zip压缩文件解压
|
||||||
* @param zipPath 相对路径
|
* @param zipPath 相对路径
|
||||||
@@ -519,6 +524,7 @@ interface JsExtensions : JsEncodeUtils {
|
|||||||
fun un7zFile(zipPath: String): String {
|
fun un7zFile(zipPath: String): String {
|
||||||
return unArchiveFile(zipPath)
|
return unArchiveFile(zipPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* js实现Rar压缩文件解压
|
* js实现Rar压缩文件解压
|
||||||
* @param zipPath 相对路径
|
* @param zipPath 相对路径
|
||||||
@@ -527,6 +533,7 @@ interface JsExtensions : JsEncodeUtils {
|
|||||||
fun unrarFile(zipPath: String): String {
|
fun unrarFile(zipPath: String): String {
|
||||||
return unArchiveFile(zipPath)
|
return unArchiveFile(zipPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* js实现压缩文件解压
|
* js实现压缩文件解压
|
||||||
* @param zipPath 相对路径
|
* @param zipPath 相对路径
|
||||||
@@ -730,6 +737,7 @@ interface JsExtensions : JsEncodeUtils {
|
|||||||
}
|
}
|
||||||
return@runBlocking x
|
return@runBlocking x
|
||||||
}
|
}
|
||||||
|
|
||||||
str.isContentScheme() -> Uri.parse(str).readBytes(appCtx)
|
str.isContentScheme() -> Uri.parse(str).readBytes(appCtx)
|
||||||
str.startsWith("/storage") -> File(str).readBytes()
|
str.startsWith("/storage") -> File(str).readBytes()
|
||||||
else -> base64DecodeToByteArray(str)
|
else -> base64DecodeToByteArray(str)
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user