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

Commit

Permalink
Merge pull request #25 from maykar/dev
Browse files Browse the repository at this point in the history
Dev to Master
  • Loading branch information
maykar authored Nov 6, 2020
2 parents baef1e7 + 957f74d commit 31411cc
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions kiosk-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,48 +92,53 @@ new MutationObserver(lovelaceWatch).observe(panel, { childList: true });

// If new lovelace panel was added watch for hui-root to appear.
function lovelaceWatch(mutations) {
mutations.forEach(({ addedNodes }) => {
addedNodes.forEach((e) => {
if (e.localName == "ha-panel-lovelace") {
new MutationObserver(rootWatch).observe(e.shadowRoot, {
for (let mutation of mutations) {
for (let node of mutation.addedNodes) {
if (node.localName == "ha-panel-lovelace") {
new MutationObserver(rootWatch).observe(node.shadowRoot, {
childList: true,
});
return;
}
});
});
}
}
}

// When hui-root appears watch it's children.
function rootWatch(mutations) {
mutations.forEach(({ addedNodes }) => {
addedNodes.forEach((e) => {
if (e.localName == "hui-root") {
new MutationObserver(appLayoutWatch).observe(e.shadowRoot, {
for (let mutation of mutations) {
for (let node of mutation.addedNodes) {
if (node.localName == "hui-root") {
new MutationObserver(appLayoutWatch).observe(node.shadowRoot, {
childList: true,
});
return;
}
});
});
}
}
}

// When ha-app-layout appears we can run.
function appLayoutWatch(mutations) {
mutations.forEach(({ addedNodes }) => {
addedNodes.forEach((e) => {
if (e.localName == "ha-app-layout") kiosk_mode();
});
});
for (let mutation of mutations) {
for (let node of mutation.addedNodes) {
if (node.localName == "ha-app-layout") {
kiosk_mode();
return;
}
}
}
}

// Overly complicated console tag.
const conInfo = { header: "%c☰ KIOSK-MODE".padEnd(23), ver: "%cVersion: *DEV " };
const conInfo = { header: "%c≡ kiosk-mode".padEnd(23), ver: "%cversion *DEV " };
const br = "%c\n";
const maxLen = Math.max(...Object.values(conInfo).map((el) => el.length));
for (const [key] of Object.entries(conInfo)) {
if (conInfo[key].length <= maxLen) conInfo[key] = conInfo[key].padEnd(maxLen);
if (key == "header") conInfo[key] = `${conInfo[key].slice(0, -2)}⋮ `;
if (key == "header") conInfo[key] = `${conInfo[key].slice(0, -1)}⋮ `;
}
const header =
"display:inline-block;border-width:1px 1px 0 1px;border-style:solid;border-color:#424242;color:white;background:#03a9f4;font-size:12px;padding:4px 4.5px 5px 6px;";
const info = "border-width:0px 1px 1px 1px;padding:6px;background:white;color:#424242;line-height:0.7;";
const info = "border-width:0px 1px 1px 1px;padding:7px;background:white;color:#424242;line-height:0.7;";
console.info(conInfo.header + br + conInfo.ver, header, "", `${header} ${info}`);

0 comments on commit 31411cc

Please sign in to comment.