Fix App's preferences referencing deleted categories (mihonapp/mihon#1734)

This commit is contained in:
Cuong-Tran 2025-02-25 01:44:28 +07:00
parent 3dded3568a
commit 2f33754c20
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
6 changed files with 104 additions and 39 deletions

View file

@ -24,6 +24,7 @@ The format is a modified version of [Keep a Changelog](https://keepachangelog.co
- Fix MAL `main_picture` nullability breaking search if a result doesn't have a cover set ([@MajorTanya](https://github.com/MajorTanya)) ([#1618](https://github.com/mihonapp/mihon/pull/1618)) - Fix MAL `main_picture` nullability breaking search if a result doesn't have a cover set ([@MajorTanya](https://github.com/MajorTanya)) ([#1618](https://github.com/mihonapp/mihon/pull/1618))
- Fix Bangumi and MAL tracking 401 errors due to Mihon sending expired credentials ([@MajorTanya](https://github.com/MajorTanya)) ([#1681](https://github.com/mihonapp/mihon/pull/1681), [#1682](https://github.com/mihonapp/mihon/pull/1682)) - Fix Bangumi and MAL tracking 401 errors due to Mihon sending expired credentials ([@MajorTanya](https://github.com/MajorTanya)) ([#1681](https://github.com/mihonapp/mihon/pull/1681), [#1682](https://github.com/mihonapp/mihon/pull/1682))
- Fix certain Infinix devices being unable to use any "Open link in browser" actions, including tracker setup ([@MajorTanya](https://github.com/MajorTanya)) ([#1684](https://github.com/mihonapp/mihon/pull/1684)) - Fix certain Infinix devices being unable to use any "Open link in browser" actions, including tracker setup ([@MajorTanya](https://github.com/MajorTanya)) ([#1684](https://github.com/mihonapp/mihon/pull/1684))
- Fix App's preferences referencing deleted categories ([@cuong-tran](https://github.com/cuong-tran)) ([#1734](https://github.com/mihonapp/mihon/pull/1734))
### Other ### Other
- Add zoned "Current time" to debug info and include year & timezone in logcat output ([@MajorTanya](https://github.com/MajorTanya)) ([#1672](https://github.com/mihonapp/mihon/pull/1672)) - Add zoned "Current time" to debug info and include year & timezone in logcat output ([@MajorTanya](https://github.com/MajorTanya)) ([#1672](https://github.com/mihonapp/mihon/pull/1672))

View file

@ -30,7 +30,7 @@ android {
defaultConfig { defaultConfig {
applicationId = "app.komikku" applicationId = "app.komikku"
versionCode = 72 versionCode = 73
versionName = "1.13.0" versionName = "1.13.0"
buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"") buildConfigField("String", "COMMIT_COUNT", "\"${getCommitCount()}\"")

View file

@ -112,7 +112,7 @@ class DomainModule : InjektModule {
addFactory { RenameCategory(get()) } addFactory { RenameCategory(get()) }
addFactory { ReorderCategory(get()) } addFactory { ReorderCategory(get()) }
addFactory { UpdateCategory(get()) } addFactory { UpdateCategory(get()) }
addFactory { DeleteCategory(get()) } addFactory { DeleteCategory(get(), get(), get()) }
// KMK --> // KMK -->
addFactory { HideCategory(get()) } addFactory { HideCategory(get()) }
// KMK <-- // KMK <--

View file

@ -0,0 +1,40 @@
package mihon.core.migration.migrations
import mihon.core.migration.Migration
import mihon.core.migration.MigrationContext
import tachiyomi.core.common.util.lang.withIOContext
import tachiyomi.domain.category.interactor.GetCategories
import tachiyomi.domain.download.service.DownloadPreferences
import tachiyomi.domain.library.service.LibraryPreferences
class CategoryPreferencesCleanupMigration : Migration {
override val version: Float = 73f
override suspend fun invoke(migrationContext: MigrationContext): Boolean = withIOContext {
val libraryPreferences = migrationContext.get<LibraryPreferences>() ?: return@withIOContext false
val downloadPreferences = migrationContext.get<DownloadPreferences>() ?: return@withIOContext false
val getCategories = migrationContext.get<GetCategories>() ?: return@withIOContext false
val allCategories = getCategories.await().map { it.id.toString() }.toSet()
val defaultCategory = libraryPreferences.defaultCategory().get()
if (defaultCategory.toString() !in allCategories) {
libraryPreferences.defaultCategory().delete()
}
val categoryPreferences = listOf(
libraryPreferences.updateCategories(),
libraryPreferences.updateCategoriesExclude(),
downloadPreferences.removeExcludeCategories(),
downloadPreferences.downloadNewChapterCategories(),
downloadPreferences.downloadNewChapterCategoriesExclude(),
)
categoryPreferences.forEach { preference ->
val ids = preference.get()
val garbageIds = ids.minus(allCategories)
if (garbageIds.isEmpty()) return@forEach
preference.set(ids.minus(garbageIds))
}
return@withIOContext true
}
}

View file

@ -8,46 +8,47 @@ val migrations: List<Migration>
SetupLibraryUpdateMigration(), SetupLibraryUpdateMigration(),
SetupEHentaiUpdateMigration(), SetupEHentaiUpdateMigration(),
SetupSyncDataMigration(), SetupSyncDataMigration(),
DelegateHBrowseMigration(), // DelegateHBrowseMigration(),
DelegateNHentaiMigration(), // DelegateNHentaiMigration(),
MergedMangaRewriteMigration(), // MergedMangaRewriteMigration(),
LogoutFromMALMigration(), // LogoutFromMALMigration(),
MoveDOHSettingMigration(), // MoveDOHSettingMigration(),
ResetRotationSettingMigration(), // ResetRotationSettingMigration(),
ResetReaderSettingsMigration(), // ResetReaderSettingsMigration(),
DeleteOldMangaDexTracksMigration(), // DeleteOldMangaDexTracksMigration(),
RemoveOldReaderThemeMigration(), // RemoveOldReaderThemeMigration(),
RemoveShorterLibraryUpdatesMigration(), // RemoveShorterLibraryUpdatesMigration(),
MoveLibrarySortingSettingsMigration(), // MoveLibrarySortingSettingsMigration(),
RemoveShortLibraryUpdatesMigration(), // RemoveShortLibraryUpdatesMigration(),
MoveLibraryNonCompleteSettingMigration(), // MoveLibraryNonCompleteSettingMigration(),
DeleteOldEhFavoritesDatabaseMigration(), // DeleteOldEhFavoritesDatabaseMigration(),
MoveSecureScreenSettingMigration(), // MoveSecureScreenSettingMigration(),
ChangeMiuiExtensionInstallerMigration(), // ChangeMiuiExtensionInstallerMigration(),
MoveCoverOnlyGridSettingMigration(), // MoveCoverOnlyGridSettingMigration(),
MoveCatalogueCoverOnlyGridSettingMigration(), // MoveCatalogueCoverOnlyGridSettingMigration(),
MoveLatestToFeedMigration(), // MoveLatestToFeedMigration(),
MoveReaderTapSettingMigration(), // MoveReaderTapSettingMigration(),
MoveSortingModeSettingsMigration(), // MoveSortingModeSettingsMigration(),
MoveSortingModeSettingMigration(), // MoveSortingModeSettingMigration(),
AlwaysBackupMigration(), // AlwaysBackupMigration(),
ResetFilterAndSortSettingsMigration(), // ResetFilterAndSortSettingsMigration(),
ChangeThemeModeToUppercaseMigration(), // ChangeThemeModeToUppercaseMigration(),
MoveReadingButtonSettingMigration(), // MoveReadingButtonSettingMigration(),
ChangeTrackingQueueTypeMigration(), // ChangeTrackingQueueTypeMigration(),
LogoutFromMangaDexMigration(), // LogoutFromMangaDexMigration(),
RemoveUpdateCheckerJobsMigration(), // RemoveUpdateCheckerJobsMigration(),
RemoveBatteryNotLowRestrictionMigration(), // RemoveBatteryNotLowRestrictionMigration(),
MoveRelativeTimeSettingMigration(), // MoveRelativeTimeSettingMigration(),
ClearBrokenPagePreviewCacheMigration(), // ClearBrokenPagePreviewCacheMigration(),
MoveSettingsToPrivateOrAppStateMigration(), // MoveSettingsToPrivateOrAppStateMigration(),
MoveExtensionRepoSettingsMigration(), // MoveExtensionRepoSettingsMigration(),
MoveCacheToDiskSettingMigration(), // MoveCacheToDiskSettingMigration(),
MoveEncryptionSettingsToAppStateMigration(), // MoveEncryptionSettingsToAppStateMigration(),
TrustExtensionRepositoryMigration(),
// KMK --> // KMK -->
IntegratedHentaiMigration(), IntegratedHentaiMigration(),
SetupAppUpdateMigration(), SetupAppUpdateMigration(),
EHentaiMigration(), EHentaiMigration(),
// KMK <-- // KMK <--
TrustExtensionRepositoryMigration(),
CategoryPreferencesCleanupMigration(),
) )

View file

@ -5,9 +5,13 @@ import tachiyomi.core.common.util.lang.withNonCancellableContext
import tachiyomi.core.common.util.system.logcat import tachiyomi.core.common.util.system.logcat
import tachiyomi.domain.category.model.CategoryUpdate import tachiyomi.domain.category.model.CategoryUpdate
import tachiyomi.domain.category.repository.CategoryRepository import tachiyomi.domain.category.repository.CategoryRepository
import tachiyomi.domain.download.service.DownloadPreferences
import tachiyomi.domain.library.service.LibraryPreferences
class DeleteCategory( class DeleteCategory(
private val categoryRepository: CategoryRepository, private val categoryRepository: CategoryRepository,
private val libraryPreferences: LibraryPreferences,
private val downloadPreferences: DownloadPreferences,
) { ) {
suspend fun await(categoryId: Long) = withNonCancellableContext { suspend fun await(categoryId: Long) = withNonCancellableContext {
@ -26,6 +30,25 @@ class DeleteCategory(
) )
} }
val defaultCategory = libraryPreferences.defaultCategory().get()
if (defaultCategory == categoryId.toInt()) {
libraryPreferences.defaultCategory().delete()
}
val categoryPreferences = listOf(
libraryPreferences.updateCategories(),
libraryPreferences.updateCategoriesExclude(),
downloadPreferences.removeExcludeCategories(),
downloadPreferences.downloadNewChapterCategories(),
downloadPreferences.downloadNewChapterCategoriesExclude(),
)
val categoryIdString = categoryId.toString()
categoryPreferences.forEach { preference ->
val ids = preference.get()
if (categoryIdString !in ids) return@forEach
preference.set(ids.minus(categoryIdString))
}
try { try {
categoryRepository.updatePartial(updates) categoryRepository.updatePartial(updates)
Result.Success Result.Success