mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 11:16:35 +00:00
Reload frontend if backend changes (#5489)
* Reload frontend if backend changes * Better implementation * Store ha version
This commit is contained in:
parent
ee278f111f
commit
0c1714ef78
@ -5,7 +5,10 @@ import "./home-assistant-main";
|
|||||||
import "./ha-init-page";
|
import "./ha-init-page";
|
||||||
import "../resources/ha-style";
|
import "../resources/ha-style";
|
||||||
import "../resources/custom-card-support";
|
import "../resources/custom-card-support";
|
||||||
import { registerServiceWorker } from "../util/register-service-worker";
|
import {
|
||||||
|
registerServiceWorker,
|
||||||
|
supportsServiceWorker,
|
||||||
|
} from "../util/register-service-worker";
|
||||||
|
|
||||||
import { Route, HomeAssistant } from "../types";
|
import { Route, HomeAssistant } from "../types";
|
||||||
import { navigate } from "../common/navigate";
|
import { navigate } from "../common/navigate";
|
||||||
@ -16,6 +19,7 @@ export class HomeAssistantAppEl extends HassElement {
|
|||||||
@property() private _route?: Route;
|
@property() private _route?: Route;
|
||||||
@property() private _error = false;
|
@property() private _error = false;
|
||||||
@property() private _panelUrl?: string;
|
@property() private _panelUrl?: string;
|
||||||
|
private _haVersion?: string;
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
const hass = this.hass;
|
const hass = this.hass;
|
||||||
@ -64,9 +68,29 @@ export class HomeAssistantAppEl extends HassElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected hassReconnected() {
|
||||||
|
super.hassReconnected();
|
||||||
|
|
||||||
|
// If backend has been upgraded, make sure we update frontend
|
||||||
|
if (this.hass!.connection.haVersion !== this._haVersion) {
|
||||||
|
if (supportsServiceWorker()) {
|
||||||
|
navigator.serviceWorker.getRegistration().then((registration) => {
|
||||||
|
if (registration) {
|
||||||
|
registration.update();
|
||||||
|
} else {
|
||||||
|
location.reload(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
location.reload(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected async _initialize() {
|
protected async _initialize() {
|
||||||
try {
|
try {
|
||||||
const { auth, conn } = await window.hassConnection;
|
const { auth, conn } = await window.hassConnection;
|
||||||
|
this._haVersion = conn.haVersion;
|
||||||
this.initializeHass(auth, conn);
|
this.initializeHass(auth, conn);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this._error = true;
|
this._error = true;
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import { HassElement } from "../state/hass-element";
|
import { HassElement } from "../state/hass-element";
|
||||||
import { showToast } from "./toast";
|
import { showToast } from "./toast";
|
||||||
|
|
||||||
|
export const supportsServiceWorker = () =>
|
||||||
|
"serviceWorker" in navigator &&
|
||||||
|
(location.protocol === "https:" || location.hostname === "localhost");
|
||||||
|
|
||||||
export const registerServiceWorker = (notifyUpdate = true) => {
|
export const registerServiceWorker = (notifyUpdate = true) => {
|
||||||
if (
|
if (!supportsServiceWorker()) {
|
||||||
!("serviceWorker" in navigator) ||
|
|
||||||
(location.protocol !== "https:" && location.hostname !== "localhost")
|
|
||||||
) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user