feat: update progress indicator to use dynamic page calculation

- Import getCurrentPageFromScroll for viewport-based page calculation
- Replace spine index with actual calculated page numbers when available
- Fix bug where currentPage was assigned to itself (no-op)
- Add fallback to estimated pages while calculation is in progress
This commit is contained in:
2026-04-05 21:14:44 -04:00
parent edc733947b
commit caacf12003
+21 -7
View File
@@ -1,4 +1,5 @@
import type { ReaderContext } from "../core/reader-context"; import type { ReaderContext } from "../core/reader-context";
import { getCurrentPageFromScroll } from "../ebook/page-calculator";
interface ProgressDisplay { interface ProgressDisplay {
mode: "pages" | "chapter" | "percentage" | "time-left"; mode: "pages" | "chapter" | "percentage" | "time-left";
text: string; text: string;
@@ -111,14 +112,27 @@ function updateProgressDisplay(context: ReaderContext): void {
let currentPage = 0; let currentPage = 0;
let totalPages = 0; let totalPages = 0;
if (state.currentReader.type === "ebook") { if (state.currentReader.type === "ebook") {
currentPage = state.currentReader.currentSpineIndex + 1; const reader = state.currentReader as any;
totalPages = state.currentReader.cif.spine.length; const pageInfo = reader.pageCalculationResult;
} else if (state.currentReader.type === "pdf") {
currentPage = state.currentReader.currentPage; if (pageInfo && pageInfo.totalPages > 0) {
totalPages = state.readerMetadata?.total_pages || 0; const container = document.getElementById("reader-content");
const viewportHeight = window.innerHeight;
currentPage = getCurrentPageFromScroll(
pageInfo,
reader.currentSpineIndex,
container?.scrollTop || 0,
viewportHeight,
);
totalPages = pageInfo.totalPages;
} else { } else {
currentPage = state.currentReader.currentPage; // Fallback to estimated pages while calculating
totalPages = state.currentReader.images.length; currentPage = reader.currentSpineIndex + 1;
totalPages =
state.readerMetadata?.total_pages ||
state.currentReader.cif.locations?.estimatedPages ||
state.currentReader.cif.spine.length;
}
} }
getReadingSpeed().then((speed) => { getReadingSpeed().then((speed) => {
const result = calculateProgress( const result = calculateProgress(