mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 15:26:36 +00:00
Show error screen when connection fails (#11030)
This commit is contained in:
parent
322d965539
commit
3e062ba673
@ -34,8 +34,6 @@ const panelUrl = (path: string) => {
|
|||||||
export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
|
export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
|
||||||
@state() private _route: Route;
|
@state() private _route: Route;
|
||||||
|
|
||||||
@state() private _error = false;
|
|
||||||
|
|
||||||
private _panelUrl: string;
|
private _panelUrl: string;
|
||||||
|
|
||||||
private _haVersion?: string;
|
private _haVersion?: string;
|
||||||
@ -44,8 +42,6 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
|
|||||||
|
|
||||||
private _visiblePromiseResolve?: () => void;
|
private _visiblePromiseResolve?: () => void;
|
||||||
|
|
||||||
private _visibleLaunchScreen = true;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
const path = curPath();
|
const path = curPath();
|
||||||
@ -62,8 +58,7 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
|
|||||||
this._panelUrl = panelUrl(path);
|
this._panelUrl = panelUrl(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render() {
|
protected renderHass() {
|
||||||
if (this._isHassComplete() && this.hass) {
|
|
||||||
return html`
|
return html`
|
||||||
<home-assistant-main
|
<home-assistant-main
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
@ -72,17 +67,13 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
update(changedProps) {
|
update(changedProps) {
|
||||||
super.update(changedProps);
|
if (this.hass?.states && this.hass.config && this.hass.services) {
|
||||||
|
this.render = this.renderHass;
|
||||||
// Remove launch screen if main gui is loaded
|
this.update = super.update;
|
||||||
if (this._isHassComplete() && this._visibleLaunchScreen) {
|
|
||||||
this._visibleLaunchScreen = false;
|
|
||||||
removeLaunchScreen();
|
removeLaunchScreen();
|
||||||
}
|
}
|
||||||
|
super.update(changedProps);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected firstUpdated(changedProps) {
|
protected firstUpdated(changedProps) {
|
||||||
@ -129,10 +120,9 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Render launch screen info box (loading data / error message)
|
// Render launch screen info box (loading data / error message)
|
||||||
if (!this._isHassComplete() && this._visibleLaunchScreen) {
|
// if Home Assistant is not loaded yet.
|
||||||
renderLaunchScreenInfoBox(
|
if (this.render !== this.renderHass) {
|
||||||
html`<ha-init-page .error=${this._error}></ha-init-page>`
|
this._renderInitInfo(false);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +178,7 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
|
|||||||
if (window.hassConnection) {
|
if (window.hassConnection) {
|
||||||
result = await window.hassConnection;
|
result = await window.hassConnection;
|
||||||
} else {
|
} else {
|
||||||
// In the edge case that
|
// In the edge case that core.ts loads before app.ts
|
||||||
result = await new Promise((resolve) => {
|
result = await new Promise((resolve) => {
|
||||||
window.hassConnectionReady = resolve;
|
window.hassConnectionReady = resolve;
|
||||||
});
|
});
|
||||||
@ -198,7 +188,7 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
|
|||||||
this._haVersion = conn.haVersion;
|
this._haVersion = conn.haVersion;
|
||||||
this.initializeHass(auth, conn);
|
this.initializeHass(auth, conn);
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
this._error = true;
|
this._renderInitInfo(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,12 +245,10 @@ export class HomeAssistantAppEl extends QuickBarMixin(HassElement) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _isHassComplete(): boolean {
|
private _renderInitInfo(error: boolean) {
|
||||||
if (this.hass?.states && this.hass.config && this.hass.services) {
|
renderLaunchScreenInfoBox(
|
||||||
return true;
|
html`<ha-init-page .error=${error}></ha-init-page>`
|
||||||
}
|
);
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,9 +7,9 @@ export const removeLaunchScreen = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const renderLaunchScreenInfoBox = (element: TemplateResult) => {
|
export const renderLaunchScreenInfoBox = (content: TemplateResult) => {
|
||||||
const infoBoxElement = document.getElementById("ha-launch-screen-info-box");
|
const infoBoxElement = document.getElementById("ha-launch-screen-info-box");
|
||||||
if (infoBoxElement) {
|
if (infoBoxElement) {
|
||||||
render(element, infoBoxElement);
|
render(content, infoBoxElement);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user