Skip to content

Commit

Permalink
fix(injection): wait a little before injecting to let card define itself
Browse files Browse the repository at this point in the history
  • Loading branch information
thatkookooguy committed Nov 19, 2020
1 parent 4729835 commit ab19bc1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion kb-frosted-cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ cardMods.set('ha-dialog', '.mdc-dialog__surface { backdrop-filter: blur(5px); }'

const injectPromises = Array.from( cardMods ).map(([cardName, cssRule]) => addCssToCard(cardName, cssRule));

Promise.all(injectPromises)
Promise.resolve()
.then(() => wait())
.then(() => Promise.all(injectPromises))
.then(() => {
// Force lovelace to redraw everything
const ev = new Event("ll-rebuild", {
Expand All @@ -29,6 +31,12 @@ Promise.all(injectPromises)
if (root) root.dispatchEvent(ev);
});

function wait(timeout) {
return new Promise((resolve) => {
setTimeout(() => resolve(), timeout || 3000);
});
}

function addCssToCard(cardName, cssRule) {
return Promise.resolve()
.then(() => customElements.whenDefined(cardName))
Expand Down

0 comments on commit ab19bc1

Please sign in to comment.