From 163fdad8f9c3b1a2e31aded03276ec3b2332ede6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 21 Mar 2022 11:05:04 +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 --- app/src/main/java/io/legado/app/App.kt | 2 +- .../io/legado/app/help/storage/AppWebDav.kt | 22 +++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/App.kt b/app/src/main/java/io/legado/app/App.kt index bc819a113..8f63d6628 100644 --- a/app/src/main/java/io/legado/app/App.kt +++ b/app/src/main/java/io/legado/app/App.kt @@ -60,7 +60,7 @@ class App : MultiDexApplication() { 2 -> ChineseUtils.s2t("初始化") } //同步阅读记录 - if (AppConfig.syncBookProgress) { + if (AppWebDav.isOk && AppConfig.syncBookProgress) { AppWebDav.downloadAllBookProgress() } } diff --git a/app/src/main/java/io/legado/app/help/storage/AppWebDav.kt b/app/src/main/java/io/legado/app/help/storage/AppWebDav.kt index 62639f539..7d27a0ac4 100644 --- a/app/src/main/java/io/legado/app/help/storage/AppWebDav.kt +++ b/app/src/main/java/io/legado/app/help/storage/AppWebDav.kt @@ -17,6 +17,7 @@ import io.legado.app.lib.webdav.WebDav import io.legado.app.utils.* import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main +import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import splitties.init.appCtx import java.io.File @@ -30,6 +31,12 @@ object AppWebDav { var isOk = false + init { + runBlocking { + initConfig() + } + } + private val rootWebDavUrl: String get() { val configUrl = appCtx.getPrefString(PreferKey.webDavUrl)?.trim() @@ -50,14 +57,15 @@ object AppWebDav { return "backup${backupDate}.zip" } - @Throws(Exception::class) suspend fun initConfig() { - isOk = false - val account = appCtx.getPrefString(PreferKey.webDavAccount) - val password = appCtx.getPrefString(PreferKey.webDavPassword) - if (!account.isNullOrBlank() && !password.isNullOrBlank()) { - HttpAuth.auth = HttpAuth.Auth(account, password) - isOk = WebDav(rootWebDavUrl).makeAsDir() && WebDav(bookProgressUrl).makeAsDir() + kotlin.runCatching { + isOk = false + val account = appCtx.getPrefString(PreferKey.webDavAccount) + val password = appCtx.getPrefString(PreferKey.webDavPassword) + if (!account.isNullOrBlank() && !password.isNullOrBlank()) { + HttpAuth.auth = HttpAuth.Auth(account, password) + isOk = WebDav(rootWebDavUrl).makeAsDir() && WebDav(bookProgressUrl).makeAsDir() + } } }