fix: Migrations not getting context correctly (#1820)

This commit is contained in:
Secozzi 2024-11-09 22:49:46 +01:00 committed by GitHub
parent 33c813792b
commit 8637207121
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 58 additions and 58 deletions

View file

@ -1,7 +1,7 @@
package mihon.core.migration.migrations
import android.app.Application
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.App
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
import tachiyomi.core.common.preference.minusAssign
@ -13,7 +13,7 @@ class CombineUpdateRestrictionMigration : Migration {
// Combine global update item restrictions
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val libraryPreferences = migrationContext.get<LibraryPreferences>() ?: return false
val prefs = PreferenceManager.getDefaultSharedPreferences(context)

View file

@ -1,6 +1,6 @@
package mihon.core.migration.migrations
import eu.kanade.tachiyomi.App
import android.app.Application
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
import java.io.File
@ -10,7 +10,7 @@ class CoverToExternalFileMigration : Migration {
// Move covers to external files dir.
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val oldDir = File(context.externalCacheDir, "cover_disk_cache")
if (oldDir.exists()) {

View file

@ -1,8 +1,8 @@
package mihon.core.migration.migrations
import android.app.Application
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.App
import eu.kanade.tachiyomi.network.NetworkPreferences
import eu.kanade.tachiyomi.network.PREF_DOH_CLOUDFLARE
import mihon.core.migration.Migration
@ -13,7 +13,7 @@ class DOHMigration : Migration {
// Migrate DNS over HTTPS setting
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val networkPreferences = migrationContext.get<NetworkPreferences>() ?: return false
val prefs = PreferenceManager.getDefaultSharedPreferences(context)

View file

@ -1,6 +1,6 @@
package mihon.core.migration.migrations
import eu.kanade.tachiyomi.App
import android.app.Application
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
import java.io.File
@ -10,7 +10,7 @@ class DeleteExternalChapterCacheDirMigration : Migration {
// Delete external chapter cache dir.
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val extCache = context.externalCacheDir
if (extCache != null) {

View file

@ -1,6 +1,6 @@
package mihon.core.migration.migrations
import eu.kanade.tachiyomi.App
import android.app.Application
import eu.kanade.tachiyomi.data.backup.create.BackupCreateJob
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
@ -11,7 +11,7 @@ class EnableAutoBackupMigration : Migration {
// Always attempt automatic backup creation
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val backupPreferences = migrationContext.get<BackupPreferences>() ?: return false
if (backupPreferences.backupInterval().get() == 0) {

View file

@ -1,8 +1,8 @@
package mihon.core.migration.migrations
import android.app.Application
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.App
import eu.kanade.tachiyomi.ui.player.viewer.AspectState
import eu.kanade.tachiyomi.ui.player.viewer.HwDecState
import eu.kanade.tachiyomi.ui.player.viewer.InvertedPlayback
@ -17,7 +17,7 @@ class EnumsMigration : Migration {
// refactor(player): Implement more enums
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val preferenceStore = migrationContext.get<PreferenceStore>() ?: return false
val prefs = PreferenceManager.getDefaultSharedPreferences(context)

View file

@ -1,6 +1,6 @@
package mihon.core.migration.migrations
import eu.kanade.tachiyomi.App
import android.app.Application
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
import java.io.File
@ -10,7 +10,7 @@ class InternalChapterCacheDirMigration : Migration {
// Delete internal chapter cache dir.
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
File(context.cacheDir, "chapter_disk_cache").deleteRecursively()

View file

@ -1,8 +1,8 @@
package mihon.core.migration.migrations
import android.app.Application
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.App
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
import tachiyomi.domain.library.service.LibraryPreferences
@ -12,7 +12,7 @@ class MergeSortTypeDirectionMigration : Migration {
// Merge Sort Type and Direction into one class
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val libraryPreferences = migrationContext.get<LibraryPreferences>() ?: return false
val prefs = PreferenceManager.getDefaultSharedPreferences(context)

View file

@ -1,8 +1,8 @@
package mihon.core.migration.migrations
import android.app.Application
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.App
import eu.kanade.tachiyomi.ui.reader.setting.ReaderOrientation
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
@ -12,7 +12,7 @@ class MigrateRotationViewerValuesMigration : Migration {
// Migrate Rotation and Viewer values to default values for viewer_flags
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
val newOrientation = when (prefs.getInt("pref_rotation_type_key", 1)) {

View file

@ -1,8 +1,8 @@
package mihon.core.migration.migrations
import android.app.Application
import androidx.preference.PreferenceManager
import eu.kanade.domain.base.BasePreferences
import eu.kanade.tachiyomi.App
import eu.kanade.tachiyomi.core.security.SecurityPreferences
import eu.kanade.tachiyomi.util.system.DeviceUtil
import mihon.core.migration.Migration
@ -13,7 +13,7 @@ class MigrateSecureScreenMigration : Migration {
// Allow disabling secure screen when incognito mode is on
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val securityPreferences = migrationContext.get<SecurityPreferences>() ?: return false
val basePreferences = migrationContext.get<BasePreferences>() ?: return false
val prefs = PreferenceManager.getDefaultSharedPreferences(context)

View file

@ -1,8 +1,8 @@
package mihon.core.migration.migrations
import android.app.Application
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.App
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
import tachiyomi.domain.library.service.LibraryPreferences
@ -12,7 +12,7 @@ class MigrateSortingModeMigration : Migration {
// Switch to sort per category
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val libraryPreferences = migrationContext.get<LibraryPreferences>() ?: return false
val prefs = PreferenceManager.getDefaultSharedPreferences(context)

View file

@ -1,9 +1,9 @@
package mihon.core.migration.migrations
import android.app.Application
import android.content.SharedPreferences
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.App
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
import tachiyomi.domain.library.service.LibraryPreferences
@ -13,7 +13,7 @@ class MigrateToTriStateMigration : Migration {
// Migrate library filters to tri-state versions
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val libraryPreferences = migrationContext.get<LibraryPreferences>() ?: return false
val prefs = PreferenceManager.getDefaultSharedPreferences(context)

View file

@ -1,8 +1,8 @@
package mihon.core.migration.migrations
import android.app.Application
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.App
import eu.kanade.tachiyomi.data.track.TrackerManager
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
@ -15,7 +15,7 @@ class MigrateTriStateMigration : Migration {
// Migrate TriState usages to TriStateFilter enum
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val trackerManager = migrationContext.get<TrackerManager>() ?: return false
val preferenceStore = migrationContext.get<PreferenceStore>() ?: return false
val prefs = PreferenceManager.getDefaultSharedPreferences(context)

View file

@ -1,8 +1,8 @@
package mihon.core.migration.migrations
import android.app.Application
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.App
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
import tachiyomi.domain.library.service.LibraryPreferences
@ -12,7 +12,7 @@ class MoveChapterPreferencesMigration : Migration {
// Move chapter preferences from PreferencesHelper to LibraryPrefrences
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val libraryPreferences = migrationContext.get<LibraryPreferences>() ?: return false
val prefs = PreferenceManager.getDefaultSharedPreferences(context)

View file

@ -1,9 +1,9 @@
package mihon.core.migration.migrations
import android.app.Application
import android.content.Context
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.App
import eu.kanade.tachiyomi.ui.player.settings.PlayerPreferences
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
@ -14,7 +14,7 @@ class MovePlayerPreferencesMigration : Migration {
// more migrations for player prefs
@Suppress("SwallowedException")
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val playerPreferences = migrationContext.get<PlayerPreferences>() ?: return false
val prefs = PreferenceManager.getDefaultSharedPreferences(context)

View file

@ -1,10 +1,10 @@
package mihon.core.migration.migrations
import android.app.Application
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import eu.kanade.domain.ui.model.NavStyle
import eu.kanade.domain.ui.model.StartScreen
import eu.kanade.tachiyomi.App
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
import tachiyomi.core.common.preference.PreferenceStore
@ -15,7 +15,7 @@ class NavigationOptionsMigration : Migration {
// Bring back navigation options
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val preferenceStore = migrationContext.get<PreferenceStore>() ?: return false
val prefs = PreferenceManager.getDefaultSharedPreferences(context)

View file

@ -1,6 +1,6 @@
package mihon.core.migration.migrations
import eu.kanade.tachiyomi.App
import android.app.Application
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
import tachiyomi.core.common.preference.Preference
@ -11,7 +11,7 @@ class NoAppStateMigration : Migration {
// Don't include "app state" preferences in backups
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val preferenceStore = migrationContext.get<PreferenceStore>() ?: return false
val prefsToReplace = listOf(

View file

@ -1,8 +1,8 @@
package mihon.core.migration.migrations
import android.app.Application
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.App
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
import tachiyomi.core.common.preference.Preference
@ -12,7 +12,7 @@ class PermaTrustExtensionsMigration : Migration {
// Allow permanently trusting unofficial extensions by version code + signature
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
prefs.edit {

View file

@ -1,8 +1,8 @@
package mihon.core.migration.migrations
import android.app.Application
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.App
import eu.kanade.tachiyomi.ui.player.settings.PlayerPreferences
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
@ -13,7 +13,7 @@ class PlayerPreferenceMigration : Migration {
// add migration for player preference
@Suppress("SwallowedException")
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val playerPreferences = migrationContext.get<PlayerPreferences>() ?: return false
val prefs = PreferenceManager.getDefaultSharedPreferences(context)

View file

@ -1,8 +1,8 @@
package mihon.core.migration.migrations
import android.app.Application
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.App
import eu.kanade.tachiyomi.util.system.workManager
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
@ -12,7 +12,7 @@ class RemoveBackgroundJobsMigration : Migration {
// Removed background jobs
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
context.workManager.cancelAllWorkByTag("UpdateChecker")

View file

@ -1,6 +1,6 @@
package mihon.core.migration.migrations
import eu.kanade.tachiyomi.App
import android.app.Application
import eu.kanade.tachiyomi.data.library.anime.AnimeLibraryUpdateJob
import eu.kanade.tachiyomi.data.library.manga.MangaLibraryUpdateJob
import mihon.core.migration.Migration
@ -12,7 +12,7 @@ class RemoveOneTwoHourUpdateMigration : Migration {
// Handle removed every 1 or 2 hour library updates
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val libraryPreferences = migrationContext.get<LibraryPreferences>() ?: return false
val updateInterval = libraryPreferences.autoUpdateInterval().get()

View file

@ -1,6 +1,6 @@
package mihon.core.migration.migrations
import eu.kanade.tachiyomi.App
import android.app.Application
import eu.kanade.tachiyomi.data.library.anime.AnimeLibraryUpdateJob
import eu.kanade.tachiyomi.data.library.manga.MangaLibraryUpdateJob
import mihon.core.migration.Migration
@ -12,7 +12,7 @@ class RemoveQuickUpdateMigration : Migration {
// Handle removed every 3, 4, 6, and 8 hour library updates
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val libraryPreferences = migrationContext.get<LibraryPreferences>() ?: return false
val updateInterval = libraryPreferences.autoUpdateInterval().get()

View file

@ -1,7 +1,7 @@
package mihon.core.migration.migrations
import android.app.Application
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.App
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
@ -11,7 +11,7 @@ class RemoveReaderTapMigration : Migration {
// Remove reader tapping option in favor of disabled nav layouts
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val readerPreferences = migrationContext.get<ReaderPreferences>() ?: return false
val prefs = PreferenceManager.getDefaultSharedPreferences(context)

View file

@ -1,8 +1,8 @@
package mihon.core.migration.migrations
import android.app.Application
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.App
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
import tachiyomi.domain.library.service.LibraryPreferences
@ -12,7 +12,7 @@ class RenameEnumMigration : Migration {
// Handle renamed enum values
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val libraryPreferences = migrationContext.get<LibraryPreferences>() ?: return false
val prefs = PreferenceManager.getDefaultSharedPreferences(context)

View file

@ -1,8 +1,8 @@
package mihon.core.migration.migrations
import android.app.Application
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.App
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
@ -11,7 +11,7 @@ class ResetRotationMigration : Migration {
// Reset rotation to Free after replacing Lock
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
if (prefs.contains("pref_rotation_type_key")) {

View file

@ -1,8 +1,8 @@
package mihon.core.migration.migrations
import android.app.Application
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import eu.kanade.tachiyomi.App
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
import tachiyomi.domain.library.service.LibraryPreferences
@ -12,7 +12,7 @@ class ResetSortPreferenceRemovedMigration : Migration {
// Reset sorting preference if using removed sort by source
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val libraryPreferences = migrationContext.get<LibraryPreferences>() ?: return false
val prefs = PreferenceManager.getDefaultSharedPreferences(context)

View file

@ -1,6 +1,6 @@
package mihon.core.migration.migrations
import eu.kanade.tachiyomi.App
import android.app.Application
import eu.kanade.tachiyomi.data.library.anime.AnimeLibraryUpdateJob
import eu.kanade.tachiyomi.data.library.manga.MangaLibraryUpdateJob
import mihon.core.migration.Migration
@ -11,7 +11,7 @@ class SetupBackgroundTasksMigration : Migration {
// Set up background tasks
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
MangaLibraryUpdateJob.setupTask(context)
AnimeLibraryUpdateJob.setupTask(context)

View file

@ -1,9 +1,9 @@
package mihon.core.migration.migrations
import android.app.Application
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import eu.kanade.domain.ui.UiPreferences
import eu.kanade.tachiyomi.App
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
@ -12,7 +12,7 @@ class SplitPreferencesMigration : Migration {
// Split the rest of the preferences in PreferencesHelper
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
val uiPreferences = migrationContext.get<UiPreferences>() ?: return false
val prefs = PreferenceManager.getDefaultSharedPreferences(context)

View file

@ -1,6 +1,6 @@
package mihon.core.migration.migrations
import eu.kanade.tachiyomi.App
import android.app.Application
import eu.kanade.tachiyomi.data.library.anime.AnimeLibraryUpdateJob
import eu.kanade.tachiyomi.data.library.manga.MangaLibraryUpdateJob
import mihon.core.migration.Migration
@ -11,7 +11,7 @@ class UseWorkManagerMigration : Migration {
// Fully utilize WorkManager for library updates
override suspend fun invoke(migrationContext: MigrationContext): Boolean {
val context = migrationContext.get<App>() ?: return false
val context = migrationContext.get<Application>() ?: return false
MangaLibraryUpdateJob.cancelAllWorks(context)
AnimeLibraryUpdateJob.cancelAllWorks(context)