From 9b98facf2dbde8cce54e3f8628035b08171dfeae Mon Sep 17 00:00:00 2001 From: Ryan Meek <25127328+maykar@users.noreply.github.com> Date: Fri, 15 Jan 2021 19:54:11 -0500 Subject: [PATCH] Dashboard change fix --- kiosk-mode.js | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/kiosk-mode.js b/kiosk-mode.js index a1b77ac..831cba6 100644 --- a/kiosk-mode.js +++ b/kiosk-mode.js @@ -13,9 +13,7 @@ Promise.resolve(customElements.whenDefined("hui-view")).then(() => { entityWatch(); }); -function run() { - const lovelace = main.querySelector("ha-panel-lovelace"); - +function run(lovelace = main.querySelector("ha-panel-lovelace")) { // Don't run if disabled via query string or not on a lovelace page. if (queryString("disable_km") || !lovelace) return; @@ -202,36 +200,16 @@ async function entityWatch() { ); } -// Run on element changes. +// Run on dashboard change. function observer() { - new MutationObserver(lovelaceWatch).observe(panel, { childList: true }); - - // If new lovelace panel was added watch for hui-root to appear. function lovelaceWatch(mutations) { - mutationWatch(mutations, "ha-panel-lovelace", rootWatch); - } - - // When hui-root appears watch it's children. - function rootWatch(mutations) { - mutationWatch(mutations, "hui-root", appLayoutWatch); - } - - // When ha-app-layout appears we can run. - function appLayoutWatch(mutations) { - mutationWatch(mutations, "ha-app-layout", null); - } - - // Reusable function for observers. - function mutationWatch(mutations, nodename, observeElem) { mutations.forEach((mutation) => { mutation.addedNodes.forEach((node) => { - if (node.localName == nodename) { - if (observeElem) new MutationObserver(observeElem).observe(node.shadowRoot, { childList: true }); - else run(); - } + if (node.localName == "ha-panel-lovelace") run(node); }); }); } + new MutationObserver(lovelaceWatch).observe(panel, { childList: true }); } // Overly complicated console tag.