From 8395eb307ea827fa4628a7e08c7859523ff3279a Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Fri, 4 Dec 2020 17:04:59 -0500 Subject: [PATCH 1/3] Fix comics player --- src/plugins/comicsPlayer/plugin.js | 87 ++++++++++++++---------------- 1 file changed, 39 insertions(+), 48 deletions(-) diff --git a/src/plugins/comicsPlayer/plugin.js b/src/plugins/comicsPlayer/plugin.js index 89e110cec3..030687dd08 100644 --- a/src/plugins/comicsPlayer/plugin.js +++ b/src/plugins/comicsPlayer/plugin.js @@ -5,6 +5,9 @@ import dialogHelper from '../../components/dialogHelper/dialogHelper'; import keyboardnavigation from '../../scripts/keyboardNavigation'; import { appRouter } from '../../components/appRouter'; import ServerConnections from '../../components/ServerConnections'; +// eslint-disable-next-line import/named, import/namespace +import { Swiper } from 'swiper/swiper-bundle.esm'; +import 'swiper/swiper-bundle.css'; export class ComicsPlayer { constructor() { @@ -28,6 +31,8 @@ export class ComicsPlayer { stop() { this.unbindEvents(); + this.archiveSource?.release(); + const elem = this.mediaElement; if (elem) { dialogHelper.close(elem); @@ -101,41 +106,36 @@ export class ComicsPlayer { workerUrl: appRouter.baseUrl() + '/libraries/worker-bundle.js' }); - return new Promise((resolve, reject) => { - const downloadUrl = apiClient.getItemDownloadUrl(item.Id); - const archiveSource = new ArchiveSource(downloadUrl); + const downloadUrl = apiClient.getItemDownloadUrl(item.Id); + this.archiveSource = new ArchiveSource(downloadUrl); - const instance = this; - import('swiper').then(({default: Swiper}) => { - archiveSource.load().then(() => { - loading.hide(); - this.swiperInstance = new Swiper(elem.querySelector('.slideshowSwiperContainer'), { - direction: 'horizontal', - // loop is disabled due to the lack of support in virtual slides - loop: false, - zoom: { - minRatio: 1, - toggle: true, - containerClass: 'slider-zoom-container' - }, - autoplay: false, - keyboard: { - enabled: true - }, - preloadImages: true, - slidesPerView: 1, - slidesPerColumn: 1, - initialSlide: 0, - // reduces memory consumption for large libraries while allowing preloading of images - virtual: { - slides: archiveSource.urls, - cache: true, - renderSlide: instance.getImgFromUrl, - addSlidesBefore: 1, - addSlidesAfter: 1 - } - }); - }); + return this.archiveSource.load().then(() => { + loading.hide(); + this.swiperInstance = new Swiper(elem.querySelector('.slideshowSwiperContainer'), { + direction: 'horizontal', + // loop is disabled due to the lack ofSwiper support in virtual slides + loop: false, + zoom: { + minRatio: 1, + toggle: true, + containerClass: 'slider-zoom-container' + }, + autoplay: false, + keyboard: { + enabled: true + }, + preloadImages: true, + slidesPerView: 1, + slidesPerColumn: 1, + initialSlide: 0, + // reduces memory consumption for large libraries while allowing preloading of images + virtual: { + slides: this.archiveSource.urls, + cache: true, + renderSlide: this.getImgFromUrl, + addSlidesBefore: 1, + addSlidesAfter: 1 + } }); }); } @@ -166,8 +166,6 @@ class ArchiveSource { this.url = url; this.files = []; this.urls = []; - this.loadPromise = this.load(); - this.itemsLoaded = 0; } async load() { @@ -179,7 +177,6 @@ class ArchiveSource { const blob = await res.blob(); this.archive = await Archive.open(blob); this.raw = await this.archive.getFilesArray(); - this.numberOfFiles = this.raw.length; await this.archive.extractFiles(); const files = await this.archive.getFilesArray(); @@ -198,17 +195,11 @@ class ArchiveSource { } } - getLength() { - return this.raw.length; - } - - async item(index) { - if (this.urls[index]) { - return this.urls[index]; - } - - await this.loadPromise; - return this.urls[index]; + release() { + this.files = []; + /* eslint-disable-next-line compat/compat */ + this.urls.map(URL.revokeObjectURL); + this.urls = []; } } From 4dc726d781dd5f7982eb8a4d036b985f79827546 Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Fri, 4 Dec 2020 17:14:16 -0500 Subject: [PATCH 2/3] Fix sonarqube bug --- src/plugins/comicsPlayer/plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/comicsPlayer/plugin.js b/src/plugins/comicsPlayer/plugin.js index 030687dd08..e512201325 100644 --- a/src/plugins/comicsPlayer/plugin.js +++ b/src/plugins/comicsPlayer/plugin.js @@ -198,7 +198,7 @@ class ArchiveSource { release() { this.files = []; /* eslint-disable-next-line compat/compat */ - this.urls.map(URL.revokeObjectURL); + this.urls.forEach(URL.revokeObjectURL); this.urls = []; } } From e1ce1a2f3b02655f08b00c3ecea9043716e599a3 Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Fri, 4 Dec 2020 18:19:08 -0500 Subject: [PATCH 3/3] Update src/plugins/comicsPlayer/plugin.js Co-authored-by: Dmitry Lyzo <56478732+dmitrylyzo@users.noreply.github.com> --- src/plugins/comicsPlayer/plugin.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/comicsPlayer/plugin.js b/src/plugins/comicsPlayer/plugin.js index e512201325..d940377cb3 100644 --- a/src/plugins/comicsPlayer/plugin.js +++ b/src/plugins/comicsPlayer/plugin.js @@ -113,7 +113,7 @@ export class ComicsPlayer { loading.hide(); this.swiperInstance = new Swiper(elem.querySelector('.slideshowSwiperContainer'), { direction: 'horizontal', - // loop is disabled due to the lack ofSwiper support in virtual slides + // loop is disabled due to the lack of Swiper support in virtual slides loop: false, zoom: { minRatio: 1,