Skip to content

Commit

Permalink
Disable user background when setting our own
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastProject committed Jan 8, 2020
1 parent 7259a09 commit 61a5951
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions media-art-background.js
Expand Up @@ -24,9 +24,11 @@ function setupStyle(lovelace, bgroundElem) {
bgroundElem.style.zIndex = -1; // below view elements
}

function setBackground(root, lovelace, bgroundElem) {
function setBackground(root, appLayout, lovelace, bgroundElem) {
const hass = root.hass;

const viewRoot = appLayout.querySelector("hui-view");

// load config entries
let maxOpacity = lovelace.config.media_art_background.opacity || '1'; // default -> fully opaque

Expand All @@ -53,9 +55,14 @@ function setBackground(root, lovelace, bgroundElem) {
bgroundElem.style.backgroundImage = `url('${backgroundUrl}')`
bgroundElem.style.opacity = maxOpacity;

// disable user background
viewRoot.style.backgroundImage = 'none';

return; // abort after first element with valid background
}

// restore user background
viewRoot.style.backgroundImage = '';
setupStyle(lovelace, bgroundElem);
};

Expand All @@ -73,5 +80,5 @@ setupStyle(lovelace, bgroundElem);
appLayout.appendChild(bgroundElem);
appLayout.shadowRoot.querySelector("#contentContainer").style.transform = "none";

setInterval(function () { setBackground(root, lovelace, bgroundElem) }, 5000);
setInterval(function () { setBackground(root, appLayout, lovelace, bgroundElem) }, 5000);
setBackground(root, lovelace, bgroundElem);

0 comments on commit 61a5951

Please sign in to comment.