diff --git a/app/src/main/java/com/hippo/ehviewer/EhApplication.kt b/app/src/main/java/com/hippo/ehviewer/EhApplication.kt index 7baac02d6..67243e049 100644 --- a/app/src/main/java/com/hippo/ehviewer/EhApplication.kt +++ b/app/src/main/java/com/hippo/ehviewer/EhApplication.kt @@ -53,6 +53,7 @@ import io.ktor.client.plugins.cookies.HttpCookies import kotlinx.coroutines.DelicateCoroutinesApi import okhttp3.OkHttpClient import okio.Path.Companion.toOkioPath +import java.io.File import java.net.InetAddress import java.net.InetSocketAddress import java.net.Proxy @@ -77,7 +78,6 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor } @OptIn(DelicateCoroutinesApi::class) - @SuppressLint("StaticFieldLeak") override fun onCreate() { ProcessLifecycleOwner.get().lifecycle.addObserver(this) application = this @@ -114,10 +114,24 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor checkDawn() } } + launchIO { + cleanObsoleteCache() + } } mIdGenerator.setNextId(Settings.getInt(KEY_GLOBAL_STUFF_NEXT_ID, 0)) } + // TODO: Remove this after a few releases + private fun cleanObsoleteCache() { + val dir = cacheDir + for (subdir in OBSOLETE_CACHE_DIRS) { + val file = File(dir, subdir) + if (file.exists()) { + file.deleteRecursively() + } + } + } + private fun cleanupDownload() { try { val downloadLocation = Settings.downloadLocation @@ -210,6 +224,15 @@ class EhApplication : Application(), DefaultLifecycleObserver, ImageLoaderFactor var locked = true var locked_last_leave_time: Long = 0 + private val OBSOLETE_CACHE_DIRS = arrayOf( + "image", + "thumb", + "http_cache", + "image_cache", + "gallery_image", + "spider_info" + ) + @JvmStatic lateinit var application: EhApplication private set