From 57644ca1da3361aeeca399df1537720712bb88c0 Mon Sep 17 00:00:00 2001 From: Batorian Date: Thu, 18 Jul 2024 19:17:18 +0200 Subject: [PATCH 1/5] progress-tracking: initial commit --- src/database/queries/ChapterQueries.ts | 6 ++++-- src/database/tables/ChapterTable.ts | 2 ++ src/database/types/index.ts | 2 ++ src/plugins/types/index.ts | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/database/queries/ChapterQueries.ts b/src/database/queries/ChapterQueries.ts index 7c10a7b1e..87e4c17dc 100644 --- a/src/database/queries/ChapterQueries.ts +++ b/src/database/queries/ChapterQueries.ts @@ -12,8 +12,8 @@ import { NOVEL_STORAGE } from '@utils/Storages'; const db = SQLite.openDatabase('lnreader.db'); const insertChapterQuery = ` -INSERT OR IGNORE INTO Chapter (path, name, releaseTime, novelId, chapterNumber, page, position) -VALUES (?, ?, ?, ?, ?, ?, ?) +INSERT OR IGNORE INTO Chapter (path, name, releaseTime, novelId, chapterNumber, page, sourceNovelId, sourceChapterId, position) +VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) `; export const insertChapters = async ( @@ -34,6 +34,8 @@ export const insertChapters = async ( novelId, chapter.chapterNumber || null, chapter.page || '1', + chapter.sourceNovelId || '', + chapter.sourceChapterId || '', index, ], (txObj, { insertId }) => { diff --git a/src/database/tables/ChapterTable.ts b/src/database/tables/ChapterTable.ts index a3d555bca..6914b2465 100644 --- a/src/database/tables/ChapterTable.ts +++ b/src/database/tables/ChapterTable.ts @@ -12,6 +12,8 @@ export const createChapterTableQuery = ` updatedTime TEXT, chapterNumber REAL NULL, page TEXT DEFAULT "1", + sourceNovelId TEXT DEFAULT "novel id", + sourceChapterId TEXT DEFAULT "chapter id", position INTEGER DEFAULT 0, progress INTEGER, UNIQUE(path, novelId), diff --git a/src/database/types/index.ts b/src/database/types/index.ts index 5e3c2c7aa..d6249d0d1 100644 --- a/src/database/types/index.ts +++ b/src/database/types/index.ts @@ -34,6 +34,8 @@ export interface ChapterInfo { updatedTime: string | null; chapterNumber?: number; page: string; + sourceNovelId?: string; + sourceChapterId?: string; progress: number | null; position?: number; } diff --git a/src/plugins/types/index.ts b/src/plugins/types/index.ts index 69f500916..8b8236dd6 100644 --- a/src/plugins/types/index.ts +++ b/src/plugins/types/index.ts @@ -13,6 +13,8 @@ export interface ChapterItem { chapterNumber?: number; releaseTime?: string; page?: string; + sourceNovelId?: string; + sourceChapterId?: string; } export enum NovelStatus { From 1795d10e6c8628659dee50c0cb29485c3d347445 Mon Sep 17 00:00:00 2001 From: Batorian Date: Fri, 19 Jul 2024 19:12:52 +0200 Subject: [PATCH 2/5] progress-tracking: implemented tracking --- src/database/queries/ChapterQueries.ts | 6 ++---- src/database/tables/ChapterTable.ts | 2 -- src/database/types/index.ts | 2 -- src/plugins/types/index.ts | 3 +-- src/screens/reader/hooks/useChapter.ts | 6 ++++++ 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/database/queries/ChapterQueries.ts b/src/database/queries/ChapterQueries.ts index 87e4c17dc..7c10a7b1e 100644 --- a/src/database/queries/ChapterQueries.ts +++ b/src/database/queries/ChapterQueries.ts @@ -12,8 +12,8 @@ import { NOVEL_STORAGE } from '@utils/Storages'; const db = SQLite.openDatabase('lnreader.db'); const insertChapterQuery = ` -INSERT OR IGNORE INTO Chapter (path, name, releaseTime, novelId, chapterNumber, page, sourceNovelId, sourceChapterId, position) -VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) +INSERT OR IGNORE INTO Chapter (path, name, releaseTime, novelId, chapterNumber, page, position) +VALUES (?, ?, ?, ?, ?, ?, ?) `; export const insertChapters = async ( @@ -34,8 +34,6 @@ export const insertChapters = async ( novelId, chapter.chapterNumber || null, chapter.page || '1', - chapter.sourceNovelId || '', - chapter.sourceChapterId || '', index, ], (txObj, { insertId }) => { diff --git a/src/database/tables/ChapterTable.ts b/src/database/tables/ChapterTable.ts index 6914b2465..a3d555bca 100644 --- a/src/database/tables/ChapterTable.ts +++ b/src/database/tables/ChapterTable.ts @@ -12,8 +12,6 @@ export const createChapterTableQuery = ` updatedTime TEXT, chapterNumber REAL NULL, page TEXT DEFAULT "1", - sourceNovelId TEXT DEFAULT "novel id", - sourceChapterId TEXT DEFAULT "chapter id", position INTEGER DEFAULT 0, progress INTEGER, UNIQUE(path, novelId), diff --git a/src/database/types/index.ts b/src/database/types/index.ts index d6249d0d1..5e3c2c7aa 100644 --- a/src/database/types/index.ts +++ b/src/database/types/index.ts @@ -34,8 +34,6 @@ export interface ChapterInfo { updatedTime: string | null; chapterNumber?: number; page: string; - sourceNovelId?: string; - sourceChapterId?: string; progress: number | null; position?: number; } diff --git a/src/plugins/types/index.ts b/src/plugins/types/index.ts index 8b8236dd6..691a1cc12 100644 --- a/src/plugins/types/index.ts +++ b/src/plugins/types/index.ts @@ -13,8 +13,6 @@ export interface ChapterItem { chapterNumber?: number; releaseTime?: string; page?: string; - sourceNovelId?: string; - sourceChapterId?: string; } export enum NovelStatus { @@ -77,6 +75,7 @@ export interface Plugin extends PluginItem { parseNovel: (novelPath: string) => Promise; parsePage?: (novelPath: string, page: string) => Promise; parseChapter: (chapterPath: string) => Promise; + trackProgress?: (novelPath: string, chapterPath: string) => Promise; searchNovels: (searchTerm: string, pageNo: number) => Promise; resolveUrl?: (path: string, isNovel?: boolean) => string; webStorageUtilized?: boolean; diff --git a/src/screens/reader/hooks/useChapter.ts b/src/screens/reader/hooks/useChapter.ts index dfdae5a12..a8db6a598 100644 --- a/src/screens/reader/hooks/useChapter.ts +++ b/src/screens/reader/hooks/useChapter.ts @@ -28,6 +28,7 @@ import { defaultTo } from 'lodash-es'; import { useChapterContext } from '../ChapterContext'; import { showToast } from '@utils/showToast'; import { getString } from '@strings/translations'; +import { getPlugin } from '@plugins/pluginManager'; const emmiter = new NativeEventEmitter(VolumeButtonListener); @@ -146,6 +147,8 @@ export default function useChapter(webViewRef: RefObject) { const saveProgress = useCallback( (percentage: number) => { + const plugin = getPlugin(novel.pluginId); + if (!incognitoMode) { updateChapterProgress(chapter.id, percentage > 100 ? 100 : percentage); } @@ -154,6 +157,9 @@ export default function useChapter(webViewRef: RefObject) { // a relative number markChapterRead(chapter.id); updateTracker(); + if (plugin?.trackProgress) { + plugin.trackProgress(novel.path, chapter.path); + } } }, [chapter], From 5e0d85fc3895af6a8815838987beb29917e71181 Mon Sep 17 00:00:00 2001 From: Batorian Date: Sun, 28 Jul 2024 20:04:05 +0200 Subject: [PATCH 3/5] progress-tracking: update tracker --- src/database/queries/ChapterQueries.ts | 6 ++-- src/hooks/persisted/useNovel.ts | 40 +++++++++++++++++++++----- src/screens/novel/NovelScreen.tsx | 4 +-- src/screens/reader/hooks/useChapter.ts | 6 ++-- 4 files changed, 41 insertions(+), 15 deletions(-) diff --git a/src/database/queries/ChapterQueries.ts b/src/database/queries/ChapterQueries.ts index 7c10a7b1e..0fff925f2 100644 --- a/src/database/queries/ChapterQueries.ts +++ b/src/database/queries/ChapterQueries.ts @@ -385,16 +385,16 @@ export const bookmarkChapter = async (chapterId: number) => { }); }; -const markPreviuschaptersReadQuery = +const markPreviousChaptersReadQuery = 'UPDATE Chapter SET `unread` = 0 WHERE id <= ? AND novelId = ?'; -export const markPreviuschaptersRead = async ( +export const markPreviousChaptersRead = async ( chapterId: number, novelId: number, ) => { db.transaction(tx => { tx.executeSql( - markPreviuschaptersReadQuery, + markPreviousChaptersReadQuery, [chapterId, novelId], (_txObj, _res) => {}, (_txObj, _error) => { diff --git a/src/hooks/persisted/useNovel.ts b/src/hooks/persisted/useNovel.ts index 5ae603b22..bb54676e6 100644 --- a/src/hooks/persisted/useNovel.ts +++ b/src/hooks/persisted/useNovel.ts @@ -14,7 +14,7 @@ import { bookmarkChapter as _bookmarkChapter, markChapterRead as _markChapterRead, markChaptersRead as _markChaptersRead, - markPreviuschaptersRead as _markPreviuschaptersRead, + markPreviousChaptersRead as _markPreviousChaptersRead, markPreviousChaptersUnread as _markPreviousChaptersUnread, markChaptersUnread as _markChaptersUnread, deleteChapter as _deleteChapter, @@ -32,6 +32,7 @@ import { parseChapterNumber } from '@utils/parseChapterNumber'; import { NOVEL_STORAGE } from '@utils/Storages'; import FileManager from '@native/FileManager'; import { useAppSettings } from './useSettings'; +import { getPlugin } from '@plugins/pluginManager'; // store key: '__', // store key: '_', @@ -195,6 +196,7 @@ export const useNovel = (novelPath: string, pluginId: string) => { _chapters.map(_chapter => { _bookmarkChapter(_chapter.id); }); + setChapters( chapters.map(chapter => { if (_chapters.some(_c => _c.id === chapter.id)) { @@ -208,19 +210,36 @@ export const useNovel = (novelPath: string, pluginId: string) => { ); }; - const markPreviouschaptersRead = (chapterId: number) => { + const markPreviousChaptersRead = (chapterId: number) => { if (novel) { - _markPreviuschaptersRead(chapterId, novel.id); + _markPreviousChaptersRead(chapterId, novel.id); + + let lastTrackedChapterId: number | null = null; setChapters( - chapters.map(chapter => - chapter.id <= chapterId ? { ...chapter, unread: false } : chapter, - ), + chapters.map(chapter => { + if (chapter.id <= chapterId) { + lastTrackedChapterId = chapter.id; + return { ...chapter, unread: false }; + } + return chapter; + }), ); + // Track progress for the last chapter marked as read + const plugin = getPlugin(novel.pluginId); + if (lastTrackedChapterId !== null && plugin?.trackProgress) { + const lastTrackedChapter = chapters.find( + chapter => chapter.id === lastTrackedChapterId, + ); + if (lastTrackedChapter) { + plugin.trackProgress(novel.path, lastTrackedChapter.path); + } + } } }; const markChapterRead = (chapterId: number) => { _markChapterRead(chapterId); + setChapters( chapters.map(c => { if (c.id !== chapterId) { @@ -236,6 +255,13 @@ export const useNovel = (novelPath: string, pluginId: string) => { const markChaptersRead = (_chapters: ChapterInfo[]) => { const chapterIds = _chapters.map(chapter => chapter.id); + if (novel) { + const plugin = getPlugin(novel.pluginId); + if (plugin?.trackProgress) { + const chapterPath = _chapters.map(chapter => chapter.path).pop()!; + plugin.trackProgress?.(novel.path, chapterPath); + } + } _markChaptersRead(chapterIds); setChapters( @@ -404,7 +430,7 @@ export const useNovel = (novelPath: string, pluginId: string) => { sortAndFilterChapters, followNovel, bookmarkChapters, - markPreviouschaptersRead, + markPreviousChaptersRead, markChaptersRead, markPreviousChaptersUnread, markChaptersUnread, diff --git a/src/screens/novel/NovelScreen.tsx b/src/screens/novel/NovelScreen.tsx index 4937dc824..58dd466ae 100644 --- a/src/screens/novel/NovelScreen.tsx +++ b/src/screens/novel/NovelScreen.tsx @@ -82,7 +82,7 @@ const Novel = ({ route, navigation }: NovelScreenProps) => { bookmarkChapters, markChaptersRead, markChaptersUnread, - markPreviouschaptersRead, + markPreviousChaptersRead, markPreviousChaptersUnread, followNovel, deleteChapter, @@ -261,7 +261,7 @@ const Novel = ({ route, navigation }: NovelScreenProps) => { list.push({ icon: 'playlist-check', onPress: () => { - markPreviouschaptersRead(selected[0].id); + markPreviousChaptersRead(selected[0].id); setSelected([]); }, }); diff --git a/src/screens/reader/hooks/useChapter.ts b/src/screens/reader/hooks/useChapter.ts index a8db6a598..053d168f7 100644 --- a/src/screens/reader/hooks/useChapter.ts +++ b/src/screens/reader/hooks/useChapter.ts @@ -155,11 +155,11 @@ export default function useChapter(webViewRef: RefObject) { if (!incognitoMode && percentage >= 97) { // a relative number - markChapterRead(chapter.id); - updateTracker(); - if (plugin?.trackProgress) { + if (plugin?.trackProgress && chapter.unread) { plugin.trackProgress(novel.path, chapter.path); } + markChapterRead(chapter.id); + updateTracker(); } }, [chapter], From 41a638b7b1a8856c82c577eef8f3d46417234772 Mon Sep 17 00:00:00 2001 From: Batorian Date: Mon, 29 Jul 2024 17:16:13 +0200 Subject: [PATCH 4/5] progress-tracking: complete rework --- src/database/queries/ChapterQueries.ts | 2 +- src/hooks/persisted/useNovel.ts | 130 +++++++++++++++++-------- 2 files changed, 92 insertions(+), 40 deletions(-) diff --git a/src/database/queries/ChapterQueries.ts b/src/database/queries/ChapterQueries.ts index 0fff925f2..149f92c2e 100644 --- a/src/database/queries/ChapterQueries.ts +++ b/src/database/queries/ChapterQueries.ts @@ -406,7 +406,7 @@ export const markPreviousChaptersRead = async ( }; const markPreviousChaptersUnreadQuery = - 'UPDATE Chapter SET `unread` = 1 WHERE id <= ? AND novelId = ?'; + 'UPDATE Chapter SET `unread` = 1 WHERE id >= ? AND novelId = ?'; export const markPreviousChaptersUnread = async ( chapterId: number, diff --git a/src/hooks/persisted/useNovel.ts b/src/hooks/persisted/useNovel.ts index bb54676e6..6148ef817 100644 --- a/src/hooks/persisted/useNovel.ts +++ b/src/hooks/persisted/useNovel.ts @@ -214,24 +214,27 @@ export const useNovel = (novelPath: string, pluginId: string) => { if (novel) { _markPreviousChaptersRead(chapterId, novel.id); - let lastTrackedChapterId: number | null = null; setChapters( chapters.map(chapter => { if (chapter.id <= chapterId) { - lastTrackedChapterId = chapter.id; return { ...chapter, unread: false }; } return chapter; }), ); - // Track progress for the last chapter marked as read + + // Track progress if the plugin supports it const plugin = getPlugin(novel.pluginId); - if (lastTrackedChapterId !== null && plugin?.trackProgress) { - const lastTrackedChapter = chapters.find( - chapter => chapter.id === lastTrackedChapterId, + if (plugin?.trackProgress) { + const chapterPosition = chapters.find( + chapter => chapter.id === chapterId, + )?.position; + const trackedChapter = chapters.find( + chapter => chapter.position === chapterPosition, ); - if (lastTrackedChapter) { - plugin.trackProgress(novel.path, lastTrackedChapter.path); + + if (trackedChapter) { + plugin.trackProgress(novel.path, trackedChapter.path); } } } @@ -254,55 +257,104 @@ export const useNovel = (novelPath: string, pluginId: string) => { }; const markChaptersRead = (_chapters: ChapterInfo[]) => { - const chapterIds = _chapters.map(chapter => chapter.id); if (novel) { + const chapterIds = _chapters.map(chapter => chapter.id); + _markChaptersRead(chapterIds); + + setChapters( + chapters.map(chapter => { + if (chapterIds.includes(chapter.id)) { + return { + ...chapter, + unread: false, + }; + } + return chapter; + }), + ); + + // Track progress if the plugin supports it const plugin = getPlugin(novel.pluginId); if (plugin?.trackProgress) { - const chapterPath = _chapters.map(chapter => chapter.path).pop()!; - plugin.trackProgress?.(novel.path, chapterPath); + // Sort the selected chapters based on the position + const sortedChapters = [..._chapters].sort((a, b) => { + return b.position! - a.position!; + }); + const trackedChapter = sortedChapters[0]; + + plugin.trackProgress?.(novel.path, trackedChapter.path); } } - _markChaptersRead(chapterIds); - - setChapters( - chapters.map(chapter => { - if (chapterIds.includes(chapter.id)) { - return { - ...chapter, - unread: false, - }; - } - return chapter; - }), - ); }; const markPreviousChaptersUnread = (chapterId: number) => { if (novel) { _markPreviousChaptersUnread(chapterId, novel.id); + setChapters( - chapters.map(chapter => - chapter.id <= chapterId ? { ...chapter, unread: true } : chapter, - ), + chapters.map(chapter => { + if (chapter.id >= chapterId) { + return { ...chapter, unread: true }; + } + return chapter; + }), ); + + // Track progress if the plugin supports it + const plugin = getPlugin(novel.pluginId); + if (plugin?.trackProgress) { + const chapterPosition = chapters.find( + chapter => chapter.id === chapterId, + )?.position; + const trackedChapter = + chapters.find(chapter => chapter.position === chapterPosition! - 1) || + chapters.find(chapter => chapter.position === chapterPosition); + + if (trackedChapter) { + plugin.trackProgress(novel.path, trackedChapter.path); + } + } } }; const markChaptersUnread = (_chapters: ChapterInfo[]) => { - const chapterIds = _chapters.map(chapter => chapter.id); - _markChaptersUnread(chapterIds); + if (novel) { + const chapterIds = _chapters.map(chapter => chapter.id); + _markChaptersUnread(chapterIds); - setChapters( - chapters.map(chapter => { - if (chapterIds.includes(chapter.id)) { - return { - ...chapter, - unread: true, - }; + setChapters( + chapters.map(chapter => { + if (chapterIds.includes(chapter.id)) { + return { + ...chapter, + unread: true, + }; + } + return chapter; + }), + ); + + // Track progress if the plugin supports it + const plugin = getPlugin(novel.pluginId); + if (plugin?.trackProgress) { + // Sort the selected chapters based on the position + const sortedChapters = [..._chapters].sort((a, b) => { + return a.position! - b.position!; + }); + const firstChapterPosition = chapters.find( + chapter => chapter.id === sortedChapters[0].id, + )?.position; + const trackedChapter = + chapters.find( + chapter => chapter.position === firstChapterPosition! - 1, + ) || + chapters.find(chapter => chapter.position === firstChapterPosition); + + if (trackedChapter) { + plugin.trackProgress(novel.path, trackedChapter.path); } - return chapter; - }), - ); + } + } }; const deleteChapter = (_chapter: ChapterInfo) => { From 6bec6cef36eaa5ea5934ee66e65b60147a929c5a Mon Sep 17 00:00:00 2001 From: Batorian Date: Mon, 29 Jul 2024 17:41:06 +0200 Subject: [PATCH 5/5] progress-tracking: improvements --- src/hooks/persisted/useNovel.ts | 103 ++++++++++++++----------- src/screens/reader/hooks/useChapter.ts | 6 +- 2 files changed, 60 insertions(+), 49 deletions(-) diff --git a/src/hooks/persisted/useNovel.ts b/src/hooks/persisted/useNovel.ts index 6148ef817..1761de45e 100644 --- a/src/hooks/persisted/useNovel.ts +++ b/src/hooks/persisted/useNovel.ts @@ -212,6 +212,20 @@ export const useNovel = (novelPath: string, pluginId: string) => { const markPreviousChaptersRead = (chapterId: number) => { if (novel) { + // Track progress if the plugin supports it + const plugin = getPlugin(novel.pluginId); + if (plugin?.trackProgress) { + const chapterPosition = chapters.find( + chapter => chapter.id === chapterId, + )?.position; + const trackedChapter = chapters.find( + chapter => chapter.position === chapterPosition, + ); + + if (trackedChapter) { + plugin.trackProgress(novel.path, trackedChapter.path); + } + } _markPreviousChaptersRead(chapterId, novel.id); setChapters( @@ -222,25 +236,23 @@ export const useNovel = (novelPath: string, pluginId: string) => { return chapter; }), ); + } + }; + const markChapterRead = (chapterId: number) => { + if (novel) { // Track progress if the plugin supports it const plugin = getPlugin(novel.pluginId); if (plugin?.trackProgress) { - const chapterPosition = chapters.find( + const selectedChapter = chapters.find( chapter => chapter.id === chapterId, - )?.position; - const trackedChapter = chapters.find( - chapter => chapter.position === chapterPosition, ); - if (trackedChapter) { - plugin.trackProgress(novel.path, trackedChapter.path); + if (selectedChapter) { + plugin.trackProgress(novel.path, selectedChapter.path); } } } - }; - - const markChapterRead = (chapterId: number) => { _markChapterRead(chapterId); setChapters( @@ -258,21 +270,6 @@ export const useNovel = (novelPath: string, pluginId: string) => { const markChaptersRead = (_chapters: ChapterInfo[]) => { if (novel) { - const chapterIds = _chapters.map(chapter => chapter.id); - _markChaptersRead(chapterIds); - - setChapters( - chapters.map(chapter => { - if (chapterIds.includes(chapter.id)) { - return { - ...chapter, - unread: false, - }; - } - return chapter; - }), - ); - // Track progress if the plugin supports it const plugin = getPlugin(novel.pluginId); if (plugin?.trackProgress) { @@ -285,21 +282,24 @@ export const useNovel = (novelPath: string, pluginId: string) => { plugin.trackProgress?.(novel.path, trackedChapter.path); } } + const chapterIds = _chapters.map(chapter => chapter.id); + _markChaptersRead(chapterIds); + + setChapters( + chapters.map(chapter => { + if (chapterIds.includes(chapter.id)) { + return { + ...chapter, + unread: false, + }; + } + return chapter; + }), + ); }; const markPreviousChaptersUnread = (chapterId: number) => { if (novel) { - _markPreviousChaptersUnread(chapterId, novel.id); - - setChapters( - chapters.map(chapter => { - if (chapter.id >= chapterId) { - return { ...chapter, unread: true }; - } - return chapter; - }), - ); - // Track progress if the plugin supports it const plugin = getPlugin(novel.pluginId); if (plugin?.trackProgress) { @@ -314,26 +314,21 @@ export const useNovel = (novelPath: string, pluginId: string) => { plugin.trackProgress(novel.path, trackedChapter.path); } } - } - }; - - const markChaptersUnread = (_chapters: ChapterInfo[]) => { - if (novel) { - const chapterIds = _chapters.map(chapter => chapter.id); - _markChaptersUnread(chapterIds); + _markPreviousChaptersUnread(chapterId, novel.id); setChapters( chapters.map(chapter => { - if (chapterIds.includes(chapter.id)) { - return { - ...chapter, - unread: true, - }; + if (chapter.id >= chapterId) { + return { ...chapter, unread: true }; } return chapter; }), ); + } + }; + const markChaptersUnread = (_chapters: ChapterInfo[]) => { + if (novel) { // Track progress if the plugin supports it const plugin = getPlugin(novel.pluginId); if (plugin?.trackProgress) { @@ -355,6 +350,20 @@ export const useNovel = (novelPath: string, pluginId: string) => { } } } + const chapterIds = _chapters.map(chapter => chapter.id); + _markChaptersUnread(chapterIds); + + setChapters( + chapters.map(chapter => { + if (chapterIds.includes(chapter.id)) { + return { + ...chapter, + unread: true, + }; + } + return chapter; + }), + ); }; const deleteChapter = (_chapter: ChapterInfo) => { diff --git a/src/screens/reader/hooks/useChapter.ts b/src/screens/reader/hooks/useChapter.ts index 053d168f7..7033df1a8 100644 --- a/src/screens/reader/hooks/useChapter.ts +++ b/src/screens/reader/hooks/useChapter.ts @@ -147,17 +147,19 @@ export default function useChapter(webViewRef: RefObject) { const saveProgress = useCallback( (percentage: number) => { - const plugin = getPlugin(novel.pluginId); - if (!incognitoMode) { updateChapterProgress(chapter.id, percentage > 100 ? 100 : percentage); } if (!incognitoMode && percentage >= 97) { // a relative number + + // Track progress if the plugin supports it + const plugin = getPlugin(novel.pluginId); if (plugin?.trackProgress && chapter.unread) { plugin.trackProgress(novel.path, chapter.path); } + markChapterRead(chapter.id); updateTracker(); }