pull/1738/head
kunfei 3 years ago
parent eada533161
commit 163fdad8f9
  1. 2
      app/src/main/java/io/legado/app/App.kt
  2. 22
      app/src/main/java/io/legado/app/help/storage/AppWebDav.kt

@ -60,7 +60,7 @@ class App : MultiDexApplication() {
2 -> ChineseUtils.s2t("初始化") 2 -> ChineseUtils.s2t("初始化")
} }
//同步阅读记录 //同步阅读记录
if (AppConfig.syncBookProgress) { if (AppWebDav.isOk && AppConfig.syncBookProgress) {
AppWebDav.downloadAllBookProgress() AppWebDav.downloadAllBookProgress()
} }
} }

@ -17,6 +17,7 @@ import io.legado.app.lib.webdav.WebDav
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import splitties.init.appCtx import splitties.init.appCtx
import java.io.File import java.io.File
@ -30,6 +31,12 @@ object AppWebDav {
var isOk = false var isOk = false
init {
runBlocking {
initConfig()
}
}
private val rootWebDavUrl: String private val rootWebDavUrl: String
get() { get() {
val configUrl = appCtx.getPrefString(PreferKey.webDavUrl)?.trim() val configUrl = appCtx.getPrefString(PreferKey.webDavUrl)?.trim()
@ -50,14 +57,15 @@ object AppWebDav {
return "backup${backupDate}.zip" return "backup${backupDate}.zip"
} }
@Throws(Exception::class)
suspend fun initConfig() { suspend fun initConfig() {
isOk = false kotlin.runCatching {
val account = appCtx.getPrefString(PreferKey.webDavAccount) isOk = false
val password = appCtx.getPrefString(PreferKey.webDavPassword) val account = appCtx.getPrefString(PreferKey.webDavAccount)
if (!account.isNullOrBlank() && !password.isNullOrBlank()) { val password = appCtx.getPrefString(PreferKey.webDavPassword)
HttpAuth.auth = HttpAuth.Auth(account, password) if (!account.isNullOrBlank() && !password.isNullOrBlank()) {
isOk = WebDav(rootWebDavUrl).makeAsDir() && WebDav(bookProgressUrl).makeAsDir() HttpAuth.auth = HttpAuth.Auth(account, password)
isOk = WebDav(rootWebDavUrl).makeAsDir() && WebDav(bookProgressUrl).makeAsDir()
}
} }
} }

Loading…
Cancel
Save