Huge restructuring of frontend code. 1.2.0 prerelease

This commit is contained in:
2020-10-24 00:32:14 +02:00
parent b645a1ff94
commit 91a4cea453
12 changed files with 506 additions and 413 deletions

30
js/browser.js Normal file
View File

@@ -0,0 +1,30 @@
import { fireEvent } from "card-tools/src/event";
export const BrowserModBrowserMixin = (C) => class extends C {
constructor() {
super();
document.addEventListener("visibilitychange", () => this.sensor_update());
window.addEventListener("location-changed", () => this.sensor_update());
window.setInterval(() => this.sensor_update(), 10000);
}
sensor_update() {
this.sendUpdate({browser: {
path: window.location.pathname,
visibility: document.visibilityState,
userAgent: navigator.userAgent,
currentUser: this._hass &&this._hass.user && this._hass.user.name,
fullyKiosk: this.isFully,
width: window.innerWidth,
height: window.innerHeight,
}});
}
do_navigate(path) {
if (!path) return;
history.pushState(null, "", path);
fireEvent("location-changed", {}, document.querySelector("home-assistant"));
}
}