Yokan / rebuild
Course 1 8624561

AppStartup.kt

composeApp/src/commonMain/kotlin/eu/friedcutlet/yokan/app/AppStartup.kt

implementation59 lines
1package eu.friedcutlet.yokan.app23import coil3.PlatformContext4import coil3.SingletonImageLoader5import eu.friedcutlet.yokan.ui.image.clearCaches6import eu.friedcutlet.yokan.services.catchingNonCancellation7import eu.friedcutlet.yokan.services.notifications.InAppNotifications8import eu.friedcutlet.yokan.services.updates.checkForAppUpdate9import kotlinx.coroutines.Dispatchers10import kotlinx.coroutines.coroutineScope11import kotlinx.coroutines.delay12import kotlinx.coroutines.launch1314/** One-shot startup maintenance, run once from the app root after bootstrap. Each task runs concurrently. */15internal suspend fun runAppStartup(imageContext: PlatformContext): Unit = coroutineScope {16    val owner = YokanRuntime.activeSession17    val settings = owner.settings.db.value18    // "Clear chapter/episode cache on app launch": the same chapter cache as the Data and storage19    // button — Coil's disk+memory image caches (like Mangayomi's DefaultCacheManager.emptyCache())20    // and the saved chapter page lists.21    launch(Dispatchers.Default) {22        if (!owner.services.database.settings().clearChapterCacheOnAppLaunch) return@launch23        runCatching {24            SingletonImageLoader.get(imageContext).clearCaches()25            owner.repository.clearPageCache()26        }27    }28    // Auto-prune browsed (non-favorite) titles the user never interacted with29    // (no history, downloads, or tracking), so cached browse results don't30    // pile up until a manual "Clean database".31    launch(Dispatchers.Default) {32        runCatching { owner.repository.pruneBrowsedTitles() }33    }34    // Startup extension repo check (Mangayomi's main_screen behavior): when35    // "Check for extension updates" is on, fetch every item-type repository36    // shortly after launch; the refresh auto-installs updates when37    // autoExtensionsUpdates is enabled.38    if (settings.checkForExtensionUpdates) {39        launch(Dispatchers.Default) {40            delay(2_000)41            owner.sourceInstall.refreshAllRepositories()42        }43    }44    // Startup app-update check (Mangayomi main_screen): compare the latest45    // GitHub release with the installed version and surface a toast.46    if (settings.checkForAppUpdates) {47        launch {48            delay(3_000)49            catchingNonCancellation {50                checkForAppUpdate(owner.services.http)?.let { release ->51                    InAppNotifications.post(52                        "Update available: ${release.tag}",53                        "Open More → About to download it.",54                    )55                }56            }57        }58    }59}60

Search chapters, reference and source filenames.