Skip to content

Commit

Permalink
Fixed memory management
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtSoft committed Mar 23, 2024
1 parent 668bcff commit 736d44f
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions immich-slideshow.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var ImmichSlideshowVersion = "1.0.0";
var ImmichSlideshowVersion = "1.1.0";
var PlaceholderSrc = "/local/immich-slideshow/placeholder.png";

import {
Expand All @@ -20,8 +20,8 @@ class ImmichSlideshow extends LitElement {
return html`
<ha-card style="overflow:hidden;">
<div class="wrapper" style="height:${this.config.height}">
<img class="bottom" src="${PlaceholderSrc}" alt="immich-slideshow">
<img class="top hidden" @transitionend="${this._onTransitionEnd}" src="${PlaceholderSrc}" alt="immich-slideshow">
<img class="bottom" @load="${this._onBottomLoad}" src="${PlaceholderSrc}" alt="immich-slideshow">
<img class="top hidden" @transitionend="${this._onTopTransitionEnd}" src="${PlaceholderSrc}" alt="immich-slideshow">
</div>
</ha-card>
`;
Expand All @@ -35,7 +35,14 @@ class ImmichSlideshow extends LitElement {
return this.renderRoot.querySelector(".wrapper img." + className);
}

_onTransitionEnd(e) {
_onBottomLoad(e) {
var bottom = this._getImg("bottom");
if (!bottom.src.endsWith(PlaceholderSrc)) {
URL.revokeObjectURL(bottom.src);
}
}

_onTopTransitionEnd(e) {
var top = this._getImg("top");
var bottom = this._getImg("bottom");
bottom.src = top.src;
Expand All @@ -48,10 +55,12 @@ class ImmichSlideshow extends LitElement {
clearTimeout(this._slideshow);
this._slideshow = null;
}

this._nextImage();

this._slideshow = setTimeout(() => {
this._doSlideshow();
this._slideshow = null;
this._doSlideshow();
}, this.config.slideshow_interval * 1000);
}

Expand All @@ -76,14 +85,6 @@ class ImmichSlideshow extends LitElement {
if (!isconfig.slideshow_interval || isconfig.slideshow_interval < 6)
isconfig.slideshow_interval = 6;

//console.groupCollapsed("immich-slideshow setting (usunąć to jak już będzie wszystko ok)");
//console.log("apikey:"+isconfig.apikey);
//console.log("host:"+isconfig.host);
//console.log("height:"+isconfig.height);
//console.log("slideshow_interval:"+isconfig.slideshow_interval);
//console.log("--------------------------");
//console.log("PrevConfig:"+this.config);
//console.groupEnd();
this.config = isconfig;
}

Expand Down

0 comments on commit 736d44f

Please sign in to comment.