fix(audiobook): improve audiobook streaming and player UI (#513)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user