Change auto clear cache to occur on app launch instead

Fixes #9564

Avoids the issue of clearing the cache when the app is backgrounded despite being in the reader.
We could do a job on idle, but we'd still need to be careful around whether the reader is active,
so this is just simpler considering it's a separate activity.

(cherry picked from commit 53c6230afebe8e8cddca216f281fdec70e450a33)

# Conflicts:
#	app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt
This commit is contained in:
arkon 2023-07-07 17:46:39 -04:00 committed by Jobobby04
parent 5a8f583c08
commit e26360186a
3 changed files with 16 additions and 14 deletions

View File

@ -38,7 +38,6 @@ import eu.kanade.domain.ui.UiPreferences
import eu.kanade.domain.ui.model.setAppCompatDelegateThemeMode import eu.kanade.domain.ui.model.setAppCompatDelegateThemeMode
import eu.kanade.tachiyomi.crash.CrashActivity import eu.kanade.tachiyomi.crash.CrashActivity
import eu.kanade.tachiyomi.crash.GlobalExceptionHandler import eu.kanade.tachiyomi.crash.GlobalExceptionHandler
import eu.kanade.tachiyomi.data.cache.ChapterCache
import eu.kanade.tachiyomi.data.coil.MangaCoverFetcher import eu.kanade.tachiyomi.data.coil.MangaCoverFetcher
import eu.kanade.tachiyomi.data.coil.MangaCoverKeyer import eu.kanade.tachiyomi.data.coil.MangaCoverKeyer
import eu.kanade.tachiyomi.data.coil.MangaKeyer import eu.kanade.tachiyomi.data.coil.MangaKeyer
@ -66,7 +65,6 @@ import logcat.LogPriority
import logcat.LogcatLogger import logcat.LogcatLogger
import org.conscrypt.Conscrypt import org.conscrypt.Conscrypt
import tachiyomi.core.util.system.logcat import tachiyomi.core.util.system.logcat
import tachiyomi.domain.library.service.LibraryPreferences
import tachiyomi.presentation.widget.TachiyomiWidgetManager import tachiyomi.presentation.widget.TachiyomiWidgetManager
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
@ -80,11 +78,9 @@ import kotlin.time.Duration.Companion.days
class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory { class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
private val basePreferences: BasePreferences by injectLazy() private val basePreferences: BasePreferences by injectLazy()
private val libraryPreferences: LibraryPreferences by injectLazy()
private val networkPreferences: NetworkPreferences by injectLazy() private val networkPreferences: NetworkPreferences by injectLazy()
private val disableIncognitoReceiver = DisableIncognitoReceiver() private val disableIncognitoReceiver = DisableIncognitoReceiver()
private val chapterCache: ChapterCache by injectLazy()
@SuppressLint("LaunchActivityFromNotification") @SuppressLint("LaunchActivityFromNotification")
override fun onCreate() { override fun onCreate() {
@ -198,10 +194,6 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
override fun onStop(owner: LifecycleOwner) { override fun onStop(owner: LifecycleOwner) {
SecureActivityDelegate.onApplicationStopped() SecureActivityDelegate.onApplicationStopped()
if (libraryPreferences.autoClearChapterCache().get()) {
chapterCache.clear()
}
} }
override fun getPackageName(): String { override fun getPackageName(): String {

View File

@ -62,6 +62,9 @@ import eu.kanade.presentation.util.AssistContentScreen
import eu.kanade.presentation.util.DefaultNavigatorScreenTransition import eu.kanade.presentation.util.DefaultNavigatorScreenTransition
import eu.kanade.presentation.util.collectAsState import eu.kanade.presentation.util.collectAsState
import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.BuildConfig
import eu.kanade.tachiyomi.Migrations
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.cache.ChapterCache
import eu.kanade.tachiyomi.data.download.DownloadCache import eu.kanade.tachiyomi.data.download.DownloadCache
import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.updater.AppUpdateChecker import eu.kanade.tachiyomi.data.updater.AppUpdateChecker
@ -117,6 +120,7 @@ class MainActivity : BaseActivity() {
// SY <-- // SY <--
private val downloadCache: DownloadCache by injectLazy() private val downloadCache: DownloadCache by injectLazy()
private val chapterCache: ChapterCache by injectLazy()
// To be checked by splash screen. If true then splash screen will be removed. // To be checked by splash screen. If true then splash screen will be removed.
var ready = false var ready = false
@ -145,12 +149,14 @@ class MainActivity : BaseActivity() {
// SY <-- // SY <--
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
val isLaunch = savedInstanceState == null
// Prevent splash screen showing up on configuration changes // Prevent splash screen showing up on configuration changes
val splashScreen = if (savedInstanceState == null) installSplashScreen() else null val splashScreen = if (isLaunch) installSplashScreen() else null
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
val didMigration = if (savedInstanceState == null) { val didMigration = if (isLaunch) {
addAnalytics() addAnalytics()
EXHMigrations.upgrade( EXHMigrations.upgrade(
context = applicationContext, context = applicationContext,
@ -188,7 +194,7 @@ class MainActivity : BaseActivity() {
val downloadOnly by preferences.downloadedOnly().collectAsState() val downloadOnly by preferences.downloadedOnly().collectAsState()
val indexing by downloadCache.isInitializing.collectAsState() val indexing by downloadCache.isInitializing.collectAsState()
// Set statusbar color considering the top app state banner // Set status bar color considering the top app state banner
val systemUiController = rememberSystemUiController() val systemUiController = rememberSystemUiController()
val isSystemInDarkTheme = isSystemInDarkTheme() val isSystemInDarkTheme = isSystemInDarkTheme()
val statusBarBackgroundColor = when { val statusBarBackgroundColor = when {
@ -228,7 +234,7 @@ class MainActivity : BaseActivity() {
LaunchedEffect(navigator) { LaunchedEffect(navigator) {
this@MainActivity.navigator = navigator this@MainActivity.navigator = navigator
if (savedInstanceState == null) { if (isLaunch) {
// Set start screen // Set start screen
handleIntentAction(intent, navigator) handleIntentAction(intent, navigator)
@ -325,6 +331,10 @@ class MainActivity : BaseActivity() {
} }
setSplashScreenExitAnimation(splashScreen) setSplashScreenExitAnimation(splashScreen)
if (isLaunch && libraryPreferences.autoClearChapterCache().get()) {
chapterCache.clear()
}
// SY --> // SY -->
if (!unsortedPreferences.isHentaiEnabled().get()) { if (!unsortedPreferences.isHentaiEnabled().get()) {
BlacklistedSources.HIDDEN_SOURCES += EH_SOURCE_ID BlacklistedSources.HIDDEN_SOURCES += EH_SOURCE_ID
@ -343,7 +353,7 @@ class MainActivity : BaseActivity() {
} }
@Composable @Composable
fun HandleOnNewIntent(context: Context, navigator: Navigator) { private fun HandleOnNewIntent(context: Context, navigator: Navigator) {
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
callbackFlow<Intent> { callbackFlow<Intent> {
val componentActivity = context as ComponentActivity val componentActivity = context as ComponentActivity

View File

@ -538,7 +538,7 @@
<string name="used_cache">Used: %1$s</string> <string name="used_cache">Used: %1$s</string>
<string name="cache_deleted">Cache cleared. %1$d files have been deleted</string> <string name="cache_deleted">Cache cleared. %1$d files have been deleted</string>
<string name="cache_delete_error">Error occurred while clearing</string> <string name="cache_delete_error">Error occurred while clearing</string>
<string name="pref_auto_clear_chapter_cache">Clear chapter cache on app close</string> <string name="pref_auto_clear_chapter_cache">Clear chapter cache on app launch</string>
<string name="pref_invalidate_download_cache">Invalidate downloads index</string> <string name="pref_invalidate_download_cache">Invalidate downloads index</string>
<string name="pref_invalidate_download_cache_summary">Force app to recheck downloaded chapters</string> <string name="pref_invalidate_download_cache_summary">Force app to recheck downloaded chapters</string>
<string name="pref_clear_database">Clear database</string> <string name="pref_clear_database">Clear database</string>