fix(audiobook): improve audiobook streaming and player UI (#513)

This commit is contained in:
brios
2026-04-22 17:27:34 -04:00
committed by Zach Yale
parent 649c485c2d
commit 3e988077e0
9 changed files with 226 additions and 142 deletions
@@ -83,10 +83,10 @@
@if (audiobookInfo.folderBased && currentTrack) {
<span class="track-title">{{ currentTrack.title }}</span>
<span class="track-number">{{ t('trackInfo.trackOf', { current: currentTrackIndex + 1, total: audiobookInfo.tracks?.length }) }}</span>
} @else if (getCurrentChapter()) {
<span class="track-title">{{ getCurrentChapter()?.title }}</span>
} @else if (currentChapter) {
<span class="track-title">{{ currentChapter.title }}</span>
@if (hasMultipleChapters()) {
<span class="track-number">{{ t('trackInfo.chapterOf', { current: getCurrentChapterIndex() + 1, total: audiobookInfo.chapters?.length }) }}</span>
<span class="track-number">{{ t('trackInfo.chapterOf', { current: currentChapterIdx + 1, total: audiobookInfo.chapters?.length }) }}</span>
}
}
</div>
@@ -329,7 +329,7 @@
@for (chapter of audiobookInfo.chapters; track chapter.index) {
<li
class="track-item"
[class.active]="getCurrentChapter()?.index === chapter.index"
[class.active]="currentChapter?.index === chapter.index"
(click)="selectChapter(chapter)"
(keydown.enter)="selectChapter(chapter)"
role="button"
@@ -340,7 +340,7 @@
<span class="track-name">{{ chapter.title }}</span>
<span class="track-duration">{{ formatDuration(chapter.durationMs) }}</span>
</div>
@if (getCurrentChapter()?.index === chapter.index && isPlaying) {
@if (currentChapter?.index === chapter.index && isPlaying) {
<i class="pi pi-volume-up playing-indicator"></i>
}
</li>
@@ -1,9 +1,10 @@
import {Component, ElementRef, inject, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, DestroyRef, ElementRef, inject, OnDestroy, OnInit, ViewChild} from '@angular/core';
import {Location} from '@angular/common';
import {ActivatedRoute} from '@angular/router';
import {FormsModule} from '@angular/forms';
import {from, Observable, of, Subject} from 'rxjs';
import {catchError, filter, map, switchMap, takeUntil, tap} from 'rxjs/operators';
import {from, Observable, of} from 'rxjs';
import {catchError, filter, map, switchMap, tap} from 'rxjs/operators';
import {takeUntilDestroyed} from '@angular/core/rxjs-interop';
import {Button} from 'primeng/button';
import {Slider, SliderChangeEvent} from 'primeng/slider';
@@ -38,12 +39,13 @@ import {API_CONFIG} from '../../../core/config/api-config';
TranslocoDirective
],
templateUrl: './audiobook-player.component.html',
styleUrls: ['./audiobook-player.component.scss']
styleUrls: ['./audiobook-player.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AudiobookPlayerComponent implements OnInit, OnDestroy {
@ViewChild('audioElement') audioElement!: ElementRef<HTMLAudioElement>;
private destroy$ = new Subject<void>();
private readonly destroyRef = inject(DestroyRef);
private audiobookService = inject(AudiobookService);
private bookService = inject(BookService);
private bookMarkService = inject(BookMarkService);
@@ -54,7 +56,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
private audiobookSessionService = inject(AudiobookSessionService);
private pageTitle = inject(PageTitleService);
private readonly t = inject(TranslocoService);
private readonly cdr = inject(ChangeDetectorRef);
isLoading = true;
audioLoading = false;
audioInitialized = false;
@@ -76,6 +78,8 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
private savedPosition = 0;
currentTrackIndex = 0;
currentChapter?: AudiobookChapter;
currentChapterIdx = 0;
audioSrc = '';
showTrackList = false;
@@ -117,7 +121,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
];
this.route.paramMap.pipe(
takeUntil(this.destroy$),
takeUntilDestroyed(this.destroyRef),
map(params => Number(params.get('bookId'))),
filter(bookId => !Number.isNaN(bookId)),
switchMap(bookId => this.loadAudiobook(bookId))
@@ -125,9 +129,6 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
}
ngOnDestroy(): void {
this.destroy$.next();
this.destroy$.complete();
if (this.progressSaveInterval) {
clearInterval(this.progressSaveInterval);
}
@@ -153,10 +154,15 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
this.isLoading = true;
return this.audiobookService.getAudiobookInfo(bookId).pipe(
tap((info) => {
switchMap(info =>
from(this.bookService.fetchFreshBookDetail(bookId, false)).pipe(
map(book => ({info, book})),
catchError(() => of({info, book: null as Book | null}))
)
),
tap(({info, book}) => {
this.audiobookInfo = info;
if (info.folderBased && info.tracks && info.tracks.length > 0) {
// Prepare the source URL but don't load it yet
this.audioSrc = this.audiobookService.getTrackStreamUrl(bookId, 0);
const track = info.tracks[0];
if (track?.durationMs) {
@@ -169,21 +175,24 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
}
}
// Load cover URLs - prefer stored audiobook cover, fall back to embedded, then book cover
const token = this.authService.getInternalAccessToken();
this.bookCoverUrl = `${API_CONFIG.BASE_URL}/api/v1/media/book/${bookId}/cover?token=${encodeURIComponent(token || '')}`;
this.coverUrl = `${API_CONFIG.BASE_URL}/api/v1/media/book/${bookId}/audiobook-cover?token=${encodeURIComponent(token || '')}`;
this.isLoading = false;
if (book) {
this.applyBookDetails(book, info);
}
this.loadBookmarks();
// Defer the branch flip to a new macrotask so Angular's CD cycle
// sees a consistent @if state (prevents NG0100).
setTimeout(() => {
this.isLoading = false;
this.cdr.markForCheck();
});
}),
switchMap(info =>
from(this.bookService.fetchFreshBookDetail(bookId, false)).pipe(
tap(book => this.applyBookDetails(book, info)),
map(() => void 0),
catchError(() => of(void 0))
)
),
map(() => void 0),
catchError(() => {
this.messageService.add({
severity: 'error',
@@ -192,6 +201,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
});
this.isLoading = false;
this.audioLoading = false;
this.cdr.markForCheck();
return of(void 0);
})
);
@@ -229,6 +239,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
if (this.savedPosition > 0) {
this.currentTime = this.savedPosition;
}
this.updateCurrentChapter();
}
private loadTrack(index: number, showLoading = true): void {
@@ -290,16 +301,19 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
this.setupMediaSession();
}
this.cdr.markForCheck();
}
onTimeUpdate(): void {
const audio = this.audioElement?.nativeElement;
if (audio) {
const previousChapterIndex = this.getCurrentChapterIndex();
const previousChapterIndex = this.currentChapterIdx;
if (!this.isSeeking) {
this.currentTime = audio.currentTime;
}
this.updateCurrentChapter();
this.audiobookSessionService.updatePosition(
Math.round(this.currentTime * 1000),
this.audiobookInfo?.folderBased ? this.currentTrackIndex : undefined
@@ -309,11 +323,12 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
this.updateMediaSessionPositionState();
}
if (!this.audiobookInfo.folderBased && this.getCurrentChapterIndex() !== previousChapterIndex) {
if (!this.audiobookInfo.folderBased && this.currentChapterIdx !== previousChapterIndex) {
this.updateMediaSessionMetadata();
}
this.checkSleepTimerEndOfChapter();
this.cdr.markForCheck();
}
}
@@ -321,6 +336,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
const audio = this.audioElement?.nativeElement;
if (audio && audio.buffered.length > 0) {
this.buffered = audio.buffered.end(audio.buffered.length - 1);
this.cdr.markForCheck();
}
}
@@ -342,6 +358,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
this.updateMediaSessionPlaybackState();
this.audiobookSessionService.pauseSession(Math.round(this.currentTime * 1000));
}
this.cdr.markForCheck();
}
onAudioError(): void {
@@ -351,6 +368,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
summary: this.t.translate('common.error'),
detail: this.t.translate('readerAudiobook.toast.audioLoadFailed')
});
this.cdr.markForCheck();
}
private setupMediaSession(): void {
@@ -395,7 +413,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
if (!('mediaSession' in navigator)) return;
const chapters = this.audiobookInfo.chapters;
const chapterTitle = chapters && chapters.length > 1 ? this.getCurrentChapter()?.title : null;
const chapterTitle = chapters && chapters.length > 1 ? this.currentChapter?.title : null;
const title = this.audiobookInfo.folderBased
? this.currentTrack?.title
@@ -460,6 +478,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
this.audiobookInfo?.folderBased ? this.currentTrackIndex : undefined
);
}
this.cdr.markForCheck();
};
audio.addEventListener('canplay', playWhenReady);
return;
@@ -487,6 +506,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
}
this.isPlaying = !this.isPlaying;
this.updateMediaSessionPlaybackState();
this.cdr.markForCheck();
}
seek(event: SliderChangeEvent): void {
@@ -494,6 +514,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
const seekTime = event.value as number;
this.isSeeking = true;
this.currentTime = seekTime;
this.updateCurrentChapter();
if (this.seekDebounceTimeout) {
clearTimeout(this.seekDebounceTimeout);
@@ -514,6 +535,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
const newTime = Math.max(0, Math.min(this.duration, audio.currentTime + seconds));
audio.currentTime = newTime;
this.currentTime = newTime;
this.updateCurrentChapter();
}
}
@@ -564,6 +586,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
setTimeout(() => {
this.audioElement?.nativeElement?.play();
this.updateMediaSessionMetadata();
this.cdr.markForCheck();
}, 100);
}
}
@@ -578,6 +601,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
setTimeout(() => {
this.audioElement?.nativeElement?.play();
this.updateMediaSessionMetadata();
this.cdr.markForCheck();
}, 100);
}
}
@@ -617,6 +641,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
this.audiobookInfo?.bookFileId, track.index
);
}
this.cdr.markForCheck();
}, 100);
}
@@ -635,6 +660,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
audio.removeEventListener('canplay', seekAndPlay);
audio.currentTime = chapter.startTimeMs / 1000;
this.currentTime = chapter.startTimeMs / 1000;
this.updateCurrentChapter();
audio.play();
this.isPlaying = true;
this.startProgressSaveInterval();
@@ -648,6 +674,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
this.audiobookInfo?.bookFileId
);
}
this.cdr.markForCheck();
};
audio.addEventListener('canplay', seekAndPlay);
this.showTrackList = false;
@@ -656,6 +683,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
audio.currentTime = chapter.startTimeMs / 1000;
this.currentTime = chapter.startTimeMs / 1000;
this.updateCurrentChapter();
this.showTrackList = false;
this.updateMediaSessionMetadata();
if (!this.isPlaying) {
@@ -674,17 +702,17 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
}
}
getCurrentChapter(): AudiobookChapter | undefined {
if (!this.audiobookInfo?.chapters) return undefined;
private updateCurrentChapter(): void {
if (!this.audiobookInfo?.chapters) {
this.currentChapter = undefined;
this.currentChapterIdx = 0;
return;
}
const currentMs = this.currentTime * 1000;
return this.audiobookInfo.chapters.find(
this.currentChapter = this.audiobookInfo.chapters.find(
ch => currentMs >= ch.startTimeMs && currentMs < ch.endTimeMs
);
}
getCurrentChapterIndex(): number {
const chapter = this.getCurrentChapter();
return chapter?.index ?? 0;
this.currentChapterIdx = this.currentChapter?.index ?? 0;
}
hasMultipleChapters(): boolean {
@@ -692,22 +720,21 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
}
canGoPreviousChapter(): boolean {
return this.getCurrentChapterIndex() > 0;
return this.currentChapterIdx > 0;
}
canGoNextChapter(): boolean {
const chapters = this.audiobookInfo?.chapters;
if (!chapters) return false;
return this.getCurrentChapterIndex() < chapters.length - 1;
return this.currentChapterIdx < chapters.length - 1;
}
previousChapter(): void {
const chapters = this.audiobookInfo?.chapters;
if (!chapters) return;
const currentIndex = this.getCurrentChapterIndex();
if (currentIndex > 0) {
const prevChapter = chapters[currentIndex - 1];
if (this.currentChapterIdx > 0) {
const prevChapter = chapters[this.currentChapterIdx - 1];
this.selectChapter(prevChapter);
}
}
@@ -716,9 +743,8 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
const chapters = this.audiobookInfo?.chapters;
if (!chapters) return;
const currentIndex = this.getCurrentChapterIndex();
if (currentIndex < chapters.length - 1) {
const nextChapter = chapters[currentIndex + 1];
if (this.currentChapterIdx < chapters.length - 1) {
const nextChapter = chapters[this.currentChapterIdx + 1];
this.selectChapter(nextChapter);
}
}
@@ -861,6 +887,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
if (this.sleepTimerRemaining <= 0) {
this.triggerSleepTimerStop();
}
this.cdr.markForCheck();
}, 1000);
this.messageService.add({
@@ -945,10 +972,9 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
private checkSleepTimerEndOfChapter(): void {
if (!this.sleepTimerEndOfChapter || !this.sleepTimerActive) return;
const currentChapter = this.getCurrentChapter();
if (currentChapter) {
if (this.currentChapter) {
const currentMs = this.currentTime * 1000;
if (currentMs >= currentChapter.endTimeMs - 1000) {
if (currentMs >= this.currentChapter.endTimeMs - 1000) {
this.triggerSleepTimerStop();
}
}
@@ -956,9 +982,10 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
loadBookmarks(): void {
this.bookMarkService.getBookmarksForBook(this.bookId)
.pipe(takeUntil(this.destroy$))
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(bookmarks => {
this.bookmarks = bookmarks;
this.cdr.markForCheck();
});
}
@@ -970,14 +997,13 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
}
addBookmark(): void {
const currentChapter = this.getCurrentChapter();
const currentTrack = this.currentTrack;
let title: string;
if (this.audiobookInfo.folderBased && currentTrack) {
title = `${currentTrack.title} - ${this.formatTime(this.currentTime)}`;
} else if (currentChapter) {
title = `${currentChapter.title} - ${this.formatTime(this.currentTime)}`;
} else if (this.currentChapter) {
title = `${this.currentChapter.title} - ${this.formatTime(this.currentTime)}`;
} else {
title = this.t.translate('readerAudiobook.bookmarks.bookmarkAt', {time: this.formatTime(this.currentTime)});
}
@@ -990,7 +1016,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
};
this.bookMarkService.createBookmark(request)
.pipe(takeUntil(this.destroy$))
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe({
next: (bookmark) => {
this.bookmarks = [...this.bookmarks, bookmark];
@@ -999,6 +1025,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
summary: this.t.translate('readerAudiobook.toast.bookmarkAdded'),
detail: title
});
this.cdr.markForCheck();
},
error: (err) => {
const isDuplicate = err?.status === 409;
@@ -1046,6 +1073,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
this.audiobookInfo?.folderBased ? bookmark.trackIndex : undefined
);
}
this.cdr.markForCheck();
};
audio.addEventListener('canplay', seekAndPlay);
this.showBookmarkList = false;
@@ -1082,6 +1110,7 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
this.audiobookInfo?.folderBased ? bookmark.trackIndex : undefined
);
}
this.cdr.markForCheck();
}, 100);
}
}
@@ -1089,13 +1118,14 @@ export class AudiobookPlayerComponent implements OnInit, OnDestroy {
deleteBookmark(event: MouseEvent, bookmarkId: number): void {
event.stopPropagation();
this.bookMarkService.deleteBookmark(bookmarkId)
.pipe(takeUntil(this.destroy$))
.pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => {
this.bookmarks = this.bookmarks.filter(b => b.id !== bookmarkId);
this.messageService.add({
severity: 'info',
summary: this.t.translate('readerAudiobook.toast.bookmarkDeleted')
});
this.cdr.markForCheck();
});
}
@@ -1,4 +1,4 @@
import { Component, effect, ElementRef, HostListener, inject, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, effect, ElementRef, HostListener, inject, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { forkJoin, from, Subject } from 'rxjs';
import { debounceTime, map, switchMap, takeUntil, tap } from 'rxjs/operators';
@@ -62,7 +62,8 @@ import {
CbxQuickSettingsService
],
templateUrl: './cbx-reader.component.html',
styleUrl: './cbx-reader.component.scss'
styleUrl: './cbx-reader.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class CbxReaderComponent implements OnInit, OnDestroy {
private static readonly PRELOAD_PAGE_WINDOW = 5;
@@ -230,6 +231,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
protected readonly cbxQuickSettingsState = this.quickSettingsService.state;
private pageDimensionService = inject(CbxPageDimensionService);
private wakeLockService = inject(WakeLockService);
private cdr = inject(ChangeDetectorRef);
private readerPreferencesService = inject(ReaderPreferencesService);
protected readonly CbxScrollMode = CbxScrollMode;
@@ -252,7 +254,10 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
/** Run after the browser has applied layout (two frames — common Angular/DOM pattern). */
private afterNextPaint(fn: () => void): void {
requestAnimationFrame(() => requestAnimationFrame(fn));
requestAnimationFrame(() => requestAnimationFrame(() => {
fn();
this.cdr.markForCheck();
}));
}
constructor() {
@@ -425,11 +430,13 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
const percentage = this.pages.length > 0 ? Math.round(((this.currentPage + 1) / this.pages.length) * 1000) / 10 : 0;
this.readingSessionService.startSession(this.bookId, "CBX", (this.currentPage + 1).toString(), percentage);
this.cdr.markForCheck();
},
error: (err) => {
const errorMessage = err?.error?.message || this.t.translate('shared.reader.failedToLoadPages');
this.messageService.add({ severity: 'error', summary: this.t.translate('common.error'), detail: errorMessage });
this.isLoading = false;
this.cdr.markForCheck();
}
});
},
@@ -437,6 +444,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
const errorMessage = err?.error?.message || this.t.translate('shared.reader.failedToLoadBook');
this.messageService.add({ severity: 'error', summary: this.t.translate('common.error'), detail: errorMessage });
this.isLoading = false;
this.cdr.markForCheck();
}
});
}
@@ -486,6 +494,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
this.showShortcutsHelp = true;
this.cdr.markForCheck();
});
}
@@ -580,6 +589,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
this.brightness = value;
this.quickSettingsService.setBrightness(value);
this.updateViewerSetting();
this.cdr.markForCheck();
});
this.quickSettingsService.emulateBookChange$
@@ -588,6 +598,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
this.emulateBook = value;
this.quickSettingsService.setEmulateBook(value);
this.updateViewerSetting();
this.cdr.markForCheck();
});
this.quickSettingsService.clickToPaginateChange$
@@ -596,6 +607,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
this.clickToPaginate = value;
this.quickSettingsService.setClickToPaginate(value);
this.updateViewerSetting();
this.cdr.markForCheck();
});
this.quickSettingsService.autoCloseMenuChange$
@@ -604,6 +616,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
this.autoCloseMenu = value;
this.quickSettingsService.setAutoCloseMenu(value);
this.updateViewerSetting();
this.cdr.markForCheck();
});
this.quickSettingsService.stripMaxWidthChange$
@@ -864,7 +877,9 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
setTimeout(() => {
this.isPageTransitioning = false;
this.previousImageUrls = [];
this.cdr.markForCheck();
}, 150);
this.cdr.markForCheck();
}
};
img.onerror = () => {
@@ -874,6 +889,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
this.imagesLoaded = true;
this.isPageTransitioning = false;
this.previousImageUrls = [];
this.cdr.markForCheck();
}
};
img.src = url;
@@ -882,6 +898,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
onImageLoad(): void {
this.imagesLoaded = true;
this.cdr.markForCheck();
}
get isTwoPageView(): boolean {
@@ -1029,6 +1046,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
if (this.isSlideshowActive && this.currentPage >= this.pages.length - 1) {
this.stopSlideshow();
}
this.cdr.markForCheck();
}
private getPageStep(): number {
@@ -1059,6 +1077,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
this.fitMode = mode;
this.quickSettingsService.setFitMode(mode);
this.updateViewerSetting();
this.cdr.markForCheck();
}
onScrollModeChange(mode: CbxScrollMode): void {
@@ -1093,6 +1112,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
this.updateCurrentImageUrls();
this.preloadAdjacentPages();
}
this.cdr.markForCheck();
}
onPageViewModeChange(mode: CbxPageViewMode): void {
@@ -1104,6 +1124,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
this.preloadAdjacentPages();
this.footerService.setTwoPageView(this.isTwoPageView);
this.updateViewerSetting();
this.cdr.markForCheck();
}
onPageSpreadChange(spread: CbxPageSpread): void {
@@ -1113,12 +1134,14 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
this.updateCurrentImageUrls();
this.preloadAdjacentPages();
this.updateViewerSetting();
this.cdr.markForCheck();
}
onBackgroundColorChange(color: CbxBackgroundColor): void {
this.backgroundColor = color;
this.quickSettingsService.setBackgroundColor(color);
this.updateViewerSetting();
this.cdr.markForCheck();
}
private initializeInfiniteScroll(): void {
@@ -1350,6 +1373,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
if (this.longStripIntersectionObserver) {
this.longStripIntersectionObserver.observe(img);
}
this.cdr.markForCheck();
}
/**
@@ -1384,6 +1408,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
this.longStripAllImagesLoaded = true;
this.longStripDoScroll(this.currentPage, 'instant', layoutGen);
this.longStripInitFinished = true;
this.cdr.markForCheck();
};
if (img.complete) {
@@ -1446,6 +1471,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
private longStripHandleIntersection(entries: IntersectionObserverEntry[]): void {
if (!this.longStripAllImagesLoaded || this.longStripIsScrolling) return;
let changed = false;
for (const entry of entries) {
if (entry.isIntersecting) {
const pageAttr = entry.target.getAttribute('data-page');
@@ -1453,9 +1479,13 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
const page = parseInt(pageAttr, 10);
// Prefetch more images when a page enters the viewport
this.longStripPrefetchAround(page);
changed = true;
}
}
}
if (changed) {
this.cdr.markForCheck();
}
}
private longStripAttachScrollListeners(): void {
@@ -1466,6 +1496,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
if (this.longStripScrollDebounceTimer) clearTimeout(this.longStripScrollDebounceTimer);
this.longStripScrollDebounceTimer = setTimeout(() => {
this.longStripOnScroll(container);
this.cdr.markForCheck();
}, 20);
};
@@ -1474,6 +1505,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
if (this.longStripScrollEndDebounceTimer) clearTimeout(this.longStripScrollEndDebounceTimer);
this.longStripScrollEndDebounceTimer = setTimeout(() => {
this.longStripOnScrollEnd(container);
this.cdr.markForCheck();
}, supportsScrollEnd ? 20 : 100);
};
@@ -1638,6 +1670,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
this.updateSessionProgress();
this.updateFooterPage();
}
this.cdr.markForCheck();
}
firstPage(): void {
@@ -1970,6 +2003,7 @@ export class CbxReaderComponent implements OnInit, OnDestroy {
this.footerService.setSeriesBooks(this.previousBookInSeries, this.nextBookInSeries);
this.footerService.setHasSeries(true);
this.cdr.markForCheck();
},
error: (err) => {
console.error('[SeriesNav] Failed to load series information:', err);