2024-10-05 23:17:20 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { AppMetadataKeys, IMetadataMigration } from '@/modules/metadata/Metadata.types.ts';
|
2025-01-11 02:02:48 +01:00
|
|
|
import { ProgressBarPosition, ReaderPageScaleMode, ReadingMode } from '@/modules/reader/types/Reader.types.ts';
|
|
|
|
|
import { DEFAULT_READER_SETTINGS } from '@/modules/reader/constants/ReaderSettings.constants.tsx';
|
2024-10-05 23:17:20 +02:00
|
|
|
|
2024-10-28 18:03:29 +01:00
|
|
|
export const APP_METADATA_KEY_PREFIX = 'webUI';
|
2024-10-05 23:17:20 +02:00
|
|
|
|
2024-10-26 17:25:04 +02:00
|
|
|
const APP_METADATA_OBJECT: Record<AppMetadataKeys, undefined> = {
|
|
|
|
|
migration: undefined,
|
|
|
|
|
deleteChaptersManuallyMarkedRead: undefined,
|
|
|
|
|
deleteChaptersWhileReading: undefined,
|
|
|
|
|
deleteChaptersWithBookmark: undefined,
|
|
|
|
|
downloadAheadLimit: undefined,
|
|
|
|
|
showAddToLibraryCategorySelectDialog: undefined,
|
|
|
|
|
ignoreFilters: undefined,
|
|
|
|
|
removeMangaFromCategories: undefined,
|
|
|
|
|
showTabSize: undefined,
|
|
|
|
|
devices: undefined,
|
|
|
|
|
migrateChapters: undefined,
|
|
|
|
|
migrateCategories: undefined,
|
|
|
|
|
migrateTracking: undefined,
|
|
|
|
|
deleteChapters: undefined,
|
|
|
|
|
migrateSortSettings: undefined,
|
|
|
|
|
hideLibraryEntries: undefined,
|
|
|
|
|
updateProgressAfterReading: undefined,
|
|
|
|
|
updateProgressManualMarkRead: undefined,
|
|
|
|
|
webUIInformAvailableUpdate: undefined,
|
|
|
|
|
serverInformAvailableUpdate: undefined,
|
|
|
|
|
readerWidth: undefined,
|
|
|
|
|
savedSearches: undefined,
|
|
|
|
|
showContinueReadingButton: undefined,
|
|
|
|
|
showDownloadBadge: undefined,
|
|
|
|
|
showUnreadBadge: undefined,
|
|
|
|
|
gridLayout: undefined,
|
|
|
|
|
sortBy: undefined,
|
|
|
|
|
sortDesc: undefined,
|
|
|
|
|
hasDownloadedChapters: undefined,
|
|
|
|
|
hasBookmarkedChapters: undefined,
|
|
|
|
|
hasUnreadChapters: undefined,
|
2024-12-27 03:32:30 +01:00
|
|
|
hasReadChapters: undefined,
|
2024-10-26 17:25:04 +02:00
|
|
|
hasDuplicateChapters: undefined,
|
|
|
|
|
hasTrackerBinding: undefined,
|
|
|
|
|
hasStatus: undefined,
|
|
|
|
|
customThemes: undefined,
|
|
|
|
|
mangaThumbnailBackdrop: undefined,
|
2025-01-26 03:53:19 +01:00
|
|
|
mangaDynamicColorSchemes: undefined,
|
2024-09-26 17:02:44 +02:00
|
|
|
tapZoneLayout: undefined,
|
|
|
|
|
tapZoneInvertMode: undefined,
|
|
|
|
|
readingDirection: undefined,
|
2024-09-28 03:24:16 +02:00
|
|
|
progressBarType: undefined,
|
|
|
|
|
progressBarSize: undefined,
|
|
|
|
|
progressBarPosition: undefined,
|
2025-01-04 20:59:18 +01:00
|
|
|
progressBarPositionAutoVertical: undefined,
|
2024-10-03 04:03:04 +02:00
|
|
|
readingMode: undefined,
|
2024-10-03 04:02:59 +02:00
|
|
|
pageScaleMode: undefined,
|
|
|
|
|
shouldOffsetDoubleSpreads: undefined,
|
2024-11-04 18:00:35 +01:00
|
|
|
exitMode: undefined,
|
|
|
|
|
customFilter: undefined,
|
|
|
|
|
shouldSkipDupChapters: undefined,
|
|
|
|
|
isStaticNav: undefined,
|
|
|
|
|
overlayMode: undefined,
|
|
|
|
|
shouldStretchPage: undefined,
|
|
|
|
|
shouldShowPageNumber: undefined,
|
|
|
|
|
backgroundColor: undefined,
|
|
|
|
|
pageGap: undefined,
|
2024-11-03 03:09:00 +01:00
|
|
|
hotkeys: undefined,
|
2024-11-06 13:00:36 +01:00
|
|
|
imagePreLoadAmount: undefined,
|
2024-12-26 17:15:50 +01:00
|
|
|
shouldUseAutoWebtoonMode: undefined,
|
2024-12-27 00:30:19 +01:00
|
|
|
autoScroll: undefined,
|
2024-12-30 16:51:39 +01:00
|
|
|
shouldShowReadingModePreview: undefined,
|
|
|
|
|
shouldShowTapZoneLayoutPreview: undefined,
|
2025-01-01 17:24:36 +01:00
|
|
|
shouldInformAboutMissingChapter: undefined,
|
|
|
|
|
shouldInformAboutScanlatorChange: undefined,
|
2025-03-23 01:21:45 +01:00
|
|
|
hideHistory: undefined,
|
2025-03-31 01:03:40 +02:00
|
|
|
scrollAmount: undefined,
|
2025-04-20 21:40:28 +02:00
|
|
|
reverse: undefined,
|
|
|
|
|
bookmarked: undefined,
|
|
|
|
|
downloaded: undefined,
|
|
|
|
|
unread: undefined,
|
|
|
|
|
showChapterNumber: undefined,
|
2025-04-21 15:37:54 +02:00
|
|
|
extensionLanguages: undefined,
|
2024-10-26 17:25:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const VALID_APP_METADATA_KEYS = Object.keys(APP_METADATA_OBJECT);
|
|
|
|
|
|
2024-10-05 23:17:20 +02:00
|
|
|
export const GLOBAL_METADATA_KEYS: AppMetadataKeys[] = [
|
2025-01-04 21:31:47 +01:00
|
|
|
// metadata applied migration id
|
|
|
|
|
'migration',
|
|
|
|
|
|
2024-10-05 23:17:20 +02:00
|
|
|
// downloads
|
|
|
|
|
'deleteChaptersManuallyMarkedRead',
|
|
|
|
|
'deleteChaptersWhileReading',
|
|
|
|
|
'deleteChaptersWithBookmark',
|
|
|
|
|
|
|
|
|
|
// library
|
|
|
|
|
'showAddToLibraryCategorySelectDialog',
|
|
|
|
|
'ignoreFilters',
|
|
|
|
|
'removeMangaFromCategories',
|
|
|
|
|
'showTabSize',
|
|
|
|
|
|
|
|
|
|
// library category options
|
|
|
|
|
// filter
|
|
|
|
|
'hasDownloadedChapters',
|
|
|
|
|
'hasBookmarkedChapters',
|
|
|
|
|
'hasUnreadChapters',
|
2024-12-27 03:32:30 +01:00
|
|
|
'hasReadChapters',
|
2024-10-05 23:17:20 +02:00
|
|
|
'hasDuplicateChapters',
|
|
|
|
|
'hasTrackerBinding',
|
|
|
|
|
'hasStatus',
|
|
|
|
|
// sort
|
|
|
|
|
'sortBy',
|
|
|
|
|
'sortDesc',
|
|
|
|
|
// display
|
|
|
|
|
'showDownloadBadge',
|
|
|
|
|
'showUnreadBadge',
|
|
|
|
|
'showTabSize',
|
|
|
|
|
'showContinueReadingButton',
|
|
|
|
|
|
|
|
|
|
// client
|
|
|
|
|
'devices',
|
|
|
|
|
|
|
|
|
|
// migration
|
|
|
|
|
'migrateChapters',
|
|
|
|
|
'migrateCategories',
|
|
|
|
|
'migrateTracking',
|
|
|
|
|
'deleteChapters',
|
|
|
|
|
'migrateSortSettings',
|
|
|
|
|
|
|
|
|
|
// browse
|
|
|
|
|
'hideLibraryEntries',
|
2025-04-21 15:37:54 +02:00
|
|
|
'extensionLanguages',
|
2024-10-05 23:17:20 +02:00
|
|
|
|
2025-03-23 01:21:45 +01:00
|
|
|
// history
|
|
|
|
|
'hideHistory',
|
|
|
|
|
|
2024-10-05 23:17:20 +02:00
|
|
|
// tracking
|
|
|
|
|
'updateProgressAfterReading',
|
|
|
|
|
'updateProgressManualMarkRead',
|
|
|
|
|
|
|
|
|
|
// updates
|
|
|
|
|
'webUIInformAvailableUpdate',
|
|
|
|
|
'serverInformAvailableUpdate',
|
|
|
|
|
|
|
|
|
|
// sources
|
|
|
|
|
'savedSearches',
|
|
|
|
|
|
|
|
|
|
// themes
|
|
|
|
|
'customThemes',
|
|
|
|
|
'mangaThumbnailBackdrop',
|
2025-01-26 03:53:19 +01:00
|
|
|
'mangaDynamicColorSchemes',
|
2024-11-04 18:00:35 +01:00
|
|
|
|
|
|
|
|
// reader
|
|
|
|
|
'exitMode',
|
|
|
|
|
'customFilter',
|
|
|
|
|
'shouldSkipDupChapters',
|
2024-11-03 03:09:00 +01:00
|
|
|
'hotkeys',
|
2025-04-20 21:40:28 +02:00
|
|
|
|
|
|
|
|
// manga
|
|
|
|
|
// chapter list options
|
|
|
|
|
'reverse',
|
|
|
|
|
'bookmarked',
|
|
|
|
|
'downloaded',
|
|
|
|
|
'unread',
|
|
|
|
|
'showChapterNumber',
|
2024-10-05 23:17:20 +02:00
|
|
|
];
|
2024-10-03 04:03:04 +02:00
|
|
|
|
2024-10-05 23:17:20 +02:00
|
|
|
/**
|
|
|
|
|
* Once all changes have been done in the current branch, a new migration for all changes should be
|
|
|
|
|
* created.
|
|
|
|
|
*
|
|
|
|
|
* In case a value should be migrated for a specific key, and in the same migration the key is
|
|
|
|
|
* getting migrated, the key in the value migration is the "old" key (before the migration to the
|
|
|
|
|
* new key).
|
|
|
|
|
*
|
|
|
|
|
* Migration order (function "applyMetadataMigrations"):
|
|
|
|
|
* 1. app metadata key prefix
|
|
|
|
|
* 2. app metadata values
|
|
|
|
|
* 3. app metadata keys
|
2025-01-05 14:15:29 +01:00
|
|
|
* 4. app metadata keys deletion
|
2024-10-05 23:17:20 +02:00
|
|
|
*
|
|
|
|
|
* @example
|
|
|
|
|
* // changes:
|
|
|
|
|
* // commit: change key "X" to "Z"
|
|
|
|
|
* // commit: change key "Y" to "A"
|
|
|
|
|
* // commit: fix typo in reader setting "someTipo"
|
|
|
|
|
* // commit: add metadata migration
|
|
|
|
|
*
|
|
|
|
|
* // result:
|
|
|
|
|
* // old migrations:
|
|
|
|
|
* // const migrations = [
|
|
|
|
|
* // {
|
|
|
|
|
* // keys: [{ oldKey: 'loadNextonEnding', newKey: 'loadNextOnEnding' }],
|
|
|
|
|
* // }
|
|
|
|
|
* // ];
|
|
|
|
|
*
|
|
|
|
|
* // updated migrations
|
|
|
|
|
* const migrations = [
|
|
|
|
|
* {
|
|
|
|
|
* keys: [{ oldKey: 'loadNextonEnding', newKey: 'loadNextOnEnding' }],
|
|
|
|
|
* },
|
|
|
|
|
* {
|
|
|
|
|
* keys: [
|
|
|
|
|
* { oldKey: 'X', newKey: 'Z' },
|
|
|
|
|
* { oldKey: 'Y', newKey: 'A' },
|
|
|
|
|
* ],
|
|
|
|
|
* // all stored values in the metadata (of this app) will get migrated
|
|
|
|
|
* values: [
|
|
|
|
|
* {
|
|
|
|
|
* oldValue: 'someTipo',
|
|
|
|
|
* newValue: 'someTypo'
|
|
|
|
|
* },
|
|
|
|
|
* ],
|
|
|
|
|
* // to migrate only the value of a specific key (in this case of "someKey"):
|
|
|
|
|
* // values: [
|
|
|
|
|
* // {
|
|
|
|
|
* // key: 'someKey',
|
|
|
|
|
* // oldValue: 'someTipo',
|
|
|
|
|
* // newValue: 'someTypo',
|
|
|
|
|
* // },
|
|
|
|
|
* // ],
|
|
|
|
|
* },
|
|
|
|
|
* ];
|
|
|
|
|
*/
|
|
|
|
|
export const METADATA_MIGRATIONS: IMetadataMigration[] = [
|
|
|
|
|
{
|
|
|
|
|
keys: [{ oldKey: 'loadNextonEnding', newKey: 'loadNextOnEnding' }],
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
keys: [{ oldKey: 'deleteChaptersAutoMarkedRead', newKey: 'deleteChaptersWhileReading' }],
|
|
|
|
|
},
|
2024-10-03 04:03:04 +02:00
|
|
|
{
|
|
|
|
|
keys: [
|
|
|
|
|
{
|
|
|
|
|
oldKey: 'readerType',
|
|
|
|
|
newKey: 'readingMode',
|
|
|
|
|
},
|
2024-10-03 04:02:59 +02:00
|
|
|
{
|
|
|
|
|
oldKey: 'offsetFirstPage',
|
|
|
|
|
newKey: 'shouldOffsetDoubleSpreads',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
oldKey: 'fitPageToWindow',
|
|
|
|
|
newKey: 'pageScaleMode',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
oldKey: 'scalePage',
|
2024-11-04 18:00:35 +01:00
|
|
|
newKey: 'shouldStretchPage',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
oldKey: 'skipDupChapters',
|
|
|
|
|
newKey: 'shouldSkipDupChapters',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
oldKey: 'showPageNumber',
|
|
|
|
|
newKey: 'shouldShowPageNumber',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
oldKey: 'staticNav',
|
|
|
|
|
newKey: 'isStaticNav',
|
2024-10-03 04:02:59 +02:00
|
|
|
},
|
2024-10-03 04:03:04 +02:00
|
|
|
],
|
|
|
|
|
values: [
|
|
|
|
|
// START: readerType
|
|
|
|
|
{
|
|
|
|
|
key: 'readerType',
|
|
|
|
|
oldValue: 'ContinuesVertical',
|
|
|
|
|
newValue: `${ReadingMode.CONTINUOUS_VERTICAL}`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'readerType',
|
|
|
|
|
oldValue: 'Webtoon',
|
2025-01-06 12:51:26 +01:00
|
|
|
newValue: `${ReadingMode.WEBTOON}`,
|
2024-10-03 04:03:04 +02:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'readerType',
|
|
|
|
|
oldValue: 'SingleRTL',
|
|
|
|
|
newValue: `${ReadingMode.SINGLE_PAGE}`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'readerType',
|
|
|
|
|
oldValue: 'SingleLTR',
|
|
|
|
|
newValue: `${ReadingMode.SINGLE_PAGE}`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'readerType',
|
|
|
|
|
oldValue: 'DoubleRTL',
|
|
|
|
|
newValue: `${ReadingMode.DOUBLE_PAGE}`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'readerType',
|
|
|
|
|
oldValue: 'DoubleLTR',
|
|
|
|
|
newValue: `${ReadingMode.DOUBLE_PAGE}`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'readerType',
|
|
|
|
|
oldValue: 'ContinuesHorizontalLTR',
|
|
|
|
|
newValue: `${ReadingMode.CONTINUOUS_HORIZONTAL}`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'readerType',
|
|
|
|
|
oldValue: 'ContinuesHorizontalRTL',
|
|
|
|
|
newValue: `${ReadingMode.CONTINUOUS_HORIZONTAL}`,
|
|
|
|
|
},
|
|
|
|
|
// END: readerType
|
2024-10-03 04:02:59 +02:00
|
|
|
// START: fitPageToWindow
|
|
|
|
|
{
|
|
|
|
|
key: 'fitPageToWindow',
|
|
|
|
|
oldValue: 'false',
|
|
|
|
|
newValue: `${ReaderPageScaleMode.ORIGINAL}`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'fitPageToWindow',
|
|
|
|
|
oldValue: 'true',
|
|
|
|
|
newValue: `${ReaderPageScaleMode.SCREEN}`,
|
|
|
|
|
},
|
|
|
|
|
// END: fitPageToWindow
|
2024-12-10 21:14:56 +01:00
|
|
|
{
|
|
|
|
|
key: 'readerWidth',
|
2024-12-11 11:28:56 +01:00
|
|
|
oldValue: /^[0-9]+$/g,
|
2024-12-10 21:14:56 +01:00
|
|
|
newValue: (oldValue) => JSON.stringify({ value: Number(oldValue), enabled: true }),
|
|
|
|
|
},
|
2024-10-03 04:03:04 +02:00
|
|
|
],
|
|
|
|
|
},
|
2025-01-05 14:29:47 +01:00
|
|
|
{
|
|
|
|
|
deleteKeys: ['pageScaleMode', 'shouldStretchPage', 'readerWidth'],
|
|
|
|
|
},
|
2025-01-11 02:02:48 +01:00
|
|
|
{
|
|
|
|
|
values: [
|
|
|
|
|
{
|
|
|
|
|
key: 'progressBarPositionAutoVertical',
|
|
|
|
|
oldValue: '-1',
|
|
|
|
|
newValue: `${DEFAULT_READER_SETTINGS.progressBarPositionAutoVertical}`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'progressBarPosition',
|
|
|
|
|
oldValue: '0',
|
|
|
|
|
newValue: `${ProgressBarPosition.BOTTOM}`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'progressBarPosition',
|
|
|
|
|
oldValue: '1',
|
|
|
|
|
newValue: `${ProgressBarPosition.LEFT}`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
key: 'progressBarPosition',
|
|
|
|
|
oldValue: '2',
|
|
|
|
|
newValue: `${ProgressBarPosition.RIGHT}`,
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
2024-10-05 23:17:20 +02:00
|
|
|
];
|