Skip to content

Commit

Permalink
modified: immich-slideshow.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtSoft committed Apr 1, 2024
1 parent 8bade62 commit 9f2bc1e
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions immich-slideshow.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var ImmichSlideshowVersion = "1.1.0";
var ImmichSlideshowVersion = "1.2.0";
var PlaceholderSrc = "/local/immich-slideshow/placeholder.png";

import {
Expand All @@ -21,7 +21,7 @@ class ImmichSlideshow extends LitElement {
<ha-card style="overflow:hidden;">
<div class="wrapper" style="height:${this.config.height}">
<img class="bottom" @load="${this._onBottomLoad}" src="${PlaceholderSrc}" alt="immich-slideshow">
<img class="top hidden" @transitionend="${this._onTopTransitionEnd}" src="${PlaceholderSrc}" alt="immich-slideshow">
<img class="top hidden" @error="${this._onTopError}" @load="${this._onTopLoad}" @transitionend="${this._onTopTransitionEnd}" src="${PlaceholderSrc}" alt="immich-slideshow">
</div>
</ha-card>
`;
Expand All @@ -42,6 +42,25 @@ class ImmichSlideshow extends LitElement {
}
}

_imgErrorCount = 0;
_onTopError(e) {
this._imgErrorCount++;
if (this._imgErrorCount <= 3) {
console.log("Immich-Slideshow -> Image load error, loading new image.");
var top = this._getImg("top");
URL.revokeObjectURL(top.src);
top.classList.replace("visible", "hidden");
this._nextImage();
}
else {
console.log("Immich-Slideshow -> Image load error #" + this._imgErrorCount);
}
}

_onTopLoad(e) {
this._imgErrorCount = 0;
}

_onTopTransitionEnd(e) {
var top = this._getImg("top");
var bottom = this._getImg("bottom");
Expand All @@ -65,9 +84,9 @@ class ImmichSlideshow extends LitElement {
}

async _nextImage() {
var top_img = this._getImg("top");
top_img.src = await this._getNextImageURL();
top_img.classList.replace("hidden", "visible");
var top = this._getImg("top");
top.src = await this._getNextImageURL();
top.classList.replace("hidden", "visible");
}

setConfig(config) {
Expand Down

0 comments on commit 9f2bc1e

Please sign in to comment.