Split js parts

This commit is contained in:
2022-04-29 19:34:21 +00:00
parent edd03225d2
commit 69e9642b4b
14 changed files with 42 additions and 8 deletions

43
js/plugin/browser.ts Normal file
View File

@@ -0,0 +1,43 @@
import { fireEvent } from "card-tools/src/event";
import { ha_element } from "card-tools/src/hass";
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() {
const update = async () => {
const battery = (<any>navigator).getBattery?.();
this.sendUpdate({
browser: {
path: window.location.pathname,
visibility: document.visibilityState,
userAgent: navigator.userAgent,
currentUser: this.hass?.user?.name,
fullyKiosk: this.isFully,
width: window.innerWidth,
height: window.innerHeight,
battery_level:
window.fully?.getBatteryLevel() ?? battery?.level * 100,
charging: window.fully?.isPlugged() ?? battery?.charging,
darkMode: this.hass?.themes?.darkMode,
userData: this.hass?.user,
config: this.config,
},
});
};
update();
}
do_navigate(path) {
if (!path) return;
history.pushState(null, "", path);
fireEvent("location-changed", {}, ha_element());
}
};