From d3c97abfe284e0671743123d578ff60a5b27f529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20W?= Date: Mon, 4 Jan 2021 21:48:11 +0100 Subject: [PATCH] Fix for config load (#44) * Fix for config load * Small fix * Small fix 2 :D * Fix hass * Fail safe Co-authored-by: Ryan Meek <25127328+maykar@users.noreply.github.com> --- kiosk-mode.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/kiosk-mode.js b/kiosk-mode.js index 2cb381e..ccc7203 100644 --- a/kiosk-mode.js +++ b/kiosk-mode.js @@ -11,7 +11,7 @@ function getConfig() { try { const llConfig = ll.lovelace.config; config = llConfig.kiosk_mode || {}; - llAttempts = 0; + kiosk_mode(); } catch { if (llAttempts < 40) setTimeout(() => getConfig(), 50) } @@ -52,15 +52,19 @@ if (window.location.search.includes("clear_km_cache")) { ["kmHeader", "kmSidebar"].forEach((k) => setCache(k, "false")); } -function kiosk_mode() { +function loadConfig() { ll = main.querySelector("ha-panel-lovelace") const url = window.location.search; - const hass = ha.hass; // Return if not a Lovelace page or disabled via query string. if (url.includes("disable_km") || !ll) return; getConfig(); +} + +function kiosk_mode() { + const hass = ha.hass; + llAttempts = 0; // Retrieve localStorage values & query string options. let hide_header = cacheAsBool("kmHeader") || locIncludes(["kiosk", "hide_header"]); @@ -127,7 +131,7 @@ function kiosk_mode() { } // Initial run. -kiosk_mode(); +loadConfig(); // Watch for changes in partial-panel-resolver's children. new MutationObserver(lovelaceWatch).observe(panel, { childList: true }); @@ -165,8 +169,8 @@ function appLayoutWatch(mutations) { for (let mutation of mutations) { for (let node of mutation.addedNodes) { if (node.localName == "ha-app-layout") { - config = null; - kiosk_mode(); + config = {}; + loadConfig(); return; } }