Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
Fix for config load (#44)
Browse files Browse the repository at this point in the history
* Fix for config load

* Small fix

* Small fix 2 :D

* Fix hass

* Fail safe

Co-authored-by: Ryan Meek <[email protected]>
  • Loading branch information
RomRider and maykar authored Jan 4, 2021
1 parent 3369544 commit d3c97ab
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions kiosk-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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"]);
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit d3c97ab

Please sign in to comment.