From 3b9dae5c14f80316e45da09dc39cddadf5d5f9bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juraj=20Nyi=CC=81ri?= Date: Fri, 1 Oct 2021 23:09:23 +0200 Subject: [PATCH] Fix: Edge case on Windows where only one poster in horizontal scroll was displayed --- dist/plex-meets-homeassistant.js | 21 +++++++++++++-------- src/plex-meets-homeassistant.ts | 13 ++++++++----- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/dist/plex-meets-homeassistant.js b/dist/plex-meets-homeassistant.js index 79aa5ff..14033b6 100644 --- a/dist/plex-meets-homeassistant.js +++ b/dist/plex-meets-homeassistant.js @@ -21543,6 +21543,7 @@ style.textContent = css ` class PlexMeetsHomeAssistant extends HTMLElement { constructor() { super(...arguments); + this.renderPageRetries = 0; this.searchInputElem = document.createElement('input'); this.plexProtocol = 'http'; this.useHorizontalScroll = false; @@ -21994,13 +21995,13 @@ class PlexMeetsHomeAssistant extends HTMLElement { else { this.contentContainer.style.width = `${parseFloat(this.contentContainer.style.width) + getWidth(movieElem) + - 10}px`; + 10.15}px`; } } this.renderedItems += 1; } } - if (shouldRender && lastRowTop !== movieElem.getBoundingClientRect().top) { + if (shouldRender && lastRowTop !== movieElem.getBoundingClientRect().top && !this.useHorizontalScroll) { this.renderedRows += 1; if (lastRowTop !== 0 && this.columnsCount === 0) { this.columnsCount = this.renderedItems - 1; @@ -22010,14 +22011,13 @@ class PlexMeetsHomeAssistant extends HTMLElement { this.maxRenderCount = this.renderedItems - 1 + this.columnsCount * loadAdditionalRowsCount; } } - if (this.maxRows && this.renderedRows > this.maxRows) { + if (this.maxRows && this.renderedRows > this.maxRows && !this.useHorizontalScroll) { movieElem.remove(); } return true; } return false; }); - this.contentContainer.style.width = `${parseFloat(this.contentContainer.style.width) + 5}px`; } const contentbg = this.getElementsByClassName('contentbg')[0]; this.contentBGHeight = getHeight(contentbg); @@ -22041,10 +22041,15 @@ class PlexMeetsHomeAssistant extends HTMLElement { CSS_STYLE.episodeWidth = Math.floor(areaSize / episodesInRow - marginRight); CSS_STYLE.episodeHeight = Math.round(CSS_STYLE.episodeWidth * CSS_STYLE.episodeRatio); } - else { - setTimeout(() => { - this.renderPage(); - }, 250); + else if (this.renderPageRetries < 10) { + { + // sometimes it loop forever, todo: properly fix! + setTimeout(() => { + this.renderPageRetries += 1; + console.log('retry'); + this.renderPage(); + }, 250); + } } } this.renderedItems = 0; diff --git a/src/plex-meets-homeassistant.ts b/src/plex-meets-homeassistant.ts index 73c051c..bf440f3 100644 --- a/src/plex-meets-homeassistant.ts +++ b/src/plex-meets-homeassistant.ts @@ -30,6 +30,8 @@ declare global { } class PlexMeetsHomeAssistant extends HTMLElement { + renderPageRetries = 0; + searchInputElem = document.createElement('input'); plexProtocol: 'http' | 'https' = 'http'; @@ -607,14 +609,14 @@ class PlexMeetsHomeAssistant extends HTMLElement { } else { this.contentContainer.style.width = `${parseFloat(this.contentContainer.style.width) + getWidth(movieElem) + - 10}px`; + 10.15}px`; } } this.renderedItems += 1; } } - if (shouldRender && lastRowTop !== movieElem.getBoundingClientRect().top) { + if (shouldRender && lastRowTop !== movieElem.getBoundingClientRect().top && !this.useHorizontalScroll) { this.renderedRows += 1; if (lastRowTop !== 0 && this.columnsCount === 0) { this.columnsCount = this.renderedItems - 1; @@ -624,14 +626,13 @@ class PlexMeetsHomeAssistant extends HTMLElement { this.maxRenderCount = this.renderedItems - 1 + this.columnsCount * loadAdditionalRowsCount; } } - if (this.maxRows && this.renderedRows > this.maxRows) { + if (this.maxRows && this.renderedRows > this.maxRows && !this.useHorizontalScroll) { movieElem.remove(); } return true; } return false; }); - this.contentContainer.style.width = `${parseFloat(this.contentContainer.style.width) + 5}px`; } const contentbg = this.getElementsByClassName('contentbg')[0] as HTMLElement; @@ -658,8 +659,10 @@ class PlexMeetsHomeAssistant extends HTMLElement { CSS_STYLE.episodeWidth = Math.floor(areaSize / episodesInRow - marginRight); CSS_STYLE.episodeHeight = Math.round(CSS_STYLE.episodeWidth * CSS_STYLE.episodeRatio); - } else { + } else if (this.renderPageRetries < 10) { + // sometimes it loop forever, todo: properly fix! setTimeout(() => { + this.renderPageRetries += 1; this.renderPage(); }, 250); }