Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix migrations not getting context correctly #1820

Merged
merged 1 commit into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand Down
Loading