Make Hass.io menu toggle button work in pre and post 90 release (#2959)

This commit is contained in:
Paulus Schoutsen 2019-03-18 00:53:25 -07:00 committed by Pascal Vizeli
parent 42c7879c4d
commit 2fe0398f37
2 changed files with 11 additions and 41 deletions

View File

@ -1,41 +0,0 @@
import { html } from "@polymer/polymer/lib/utils/html-tag";
import { PolymerElement } from "@polymer/polymer/polymer-element";
import "./hassio-main";
import "./resources/hassio-icons";
class HassioApp extends PolymerElement {
static get template() {
return html`
<template is="dom-if" if="[[hass]]">
<hassio-main hass="[[hass]]" route="[[route]]"></hassio-main>
</template>
`;
}
static get properties() {
return {
hass: Object,
route: Object,
hassioPanel: {
type: Object,
value: window.parent.hassioPanel,
},
};
}
ready() {
super.ready();
window.setProperties = this.setProperties.bind(this);
this.addEventListener("location-changed", () => this._locationChanged());
this.addEventListener("hass-toggle-menu", (ev) =>
this.hassioPanel.fire("hass-toggle-menu", ev.detail)
);
}
_locationChanged() {
this.hassioPanel.navigate(window.location.pathname);
}
}
customElements.define("hassio-app", HassioApp);

View File

@ -79,6 +79,17 @@ class HassioMain extends EventsMixin(NavigateMixin(PolymerElement)) {
super.ready();
applyThemesOnElement(this, this.hass.themes, this.hass.selectedTheme, true);
this.addEventListener("hass-api-called", (ev) => this.apiCalled(ev));
// Paulus - March 17, 2019
// We went to a single hass-toggle-menu event in HA 0.90. However, the
// supervisor UI can also run under older versions of Home Assistant.
// So here we are going to translate toggle events into the appropriate
// open and close events. These events are a no-op in newer versions of
// Home Assistant.
this.addEventListener("hass-toggle-menu", () => {
window.parent.customPanel.fire(
this.hass.dockedSidebar ? "hass-close-menu" : "hass-open-menu"
);
});
}
connectedCallback() {