mirror of
https://github.com/home-assistant/frontend.git
synced 2025-09-23 20:09:49 +00:00
Compare commits
13 Commits
20241010.0
...
waitfor-in
Author | SHA1 | Date | |
---|---|---|---|
![]() |
d82f87f72f | ||
![]() |
4aa759f7f5 | ||
![]() |
774393a515 | ||
![]() |
9ced09035f | ||
![]() |
6988cc6170 | ||
![]() |
56a3c8c0c0 | ||
![]() |
1519355d76 | ||
![]() |
72d086210d | ||
![]() |
f812d25024 | ||
![]() |
821be14dcb | ||
![]() |
6eac30a022 | ||
![]() |
eac156d53b | ||
![]() |
b169ae55e1 |
@@ -27,20 +27,26 @@ import "../../../src/layouts/hass-loading-screen";
|
|||||||
import "../../../src/layouts/hass-subpage";
|
import "../../../src/layouts/hass-subpage";
|
||||||
import { HomeAssistant, Route } from "../../../src/types";
|
import { HomeAssistant, Route } from "../../../src/types";
|
||||||
|
|
||||||
|
const STATUS_BAD_GATEWAY = 502;
|
||||||
|
const TIMEOUT = 60000;
|
||||||
|
|
||||||
@customElement("hassio-ingress-view")
|
@customElement("hassio-ingress-view")
|
||||||
class HassioIngressView extends LitElement {
|
class HassioIngressView extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
@property({ attribute: false }) public supervisor!: Supervisor;
|
@property({ attribute: false }) public supervisor!: Supervisor;
|
||||||
|
|
||||||
@property() public route!: Route;
|
@property({ attribute: false }) public route!: Route;
|
||||||
|
|
||||||
@property() public ingressPanel = false;
|
@property({ type: Boolean }) public narrow = false;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public ingressPanel = false;
|
||||||
|
|
||||||
@state() private _addon?: HassioAddonDetails;
|
@state() private _addon?: HassioAddonDetails;
|
||||||
|
|
||||||
@property({ type: Boolean })
|
@state() private _resolveIngressStatus?: number;
|
||||||
public narrow = false;
|
|
||||||
|
private _resolveIngressTime?: number;
|
||||||
|
|
||||||
private _sessionKeepAlive?: number;
|
private _sessionKeepAlive?: number;
|
||||||
|
|
||||||
@@ -51,11 +57,76 @@ class HassioIngressView extends LitElement {
|
|||||||
clearInterval(this._sessionKeepAlive);
|
clearInterval(this._sessionKeepAlive);
|
||||||
this._sessionKeepAlive = undefined;
|
this._sessionKeepAlive = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._resolveIngressStatus = undefined;
|
||||||
|
this._resolveIngressTime = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private async _resolveURL(addonSlug: string): Promise<void> {
|
||||||
|
await this._fetchData(addonSlug);
|
||||||
|
if (!this._addon) {
|
||||||
|
window.setTimeout(async () => {
|
||||||
|
this._resolveURL(addonSlug);
|
||||||
|
}, 1000);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this._resolveIngressTime) {
|
||||||
|
this._resolveIngressTime = new Date().getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
this._resolveIngressStatus &&
|
||||||
|
this._resolveIngressStatus !== STATUS_BAD_GATEWAY
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
this._resolveIngressTime &&
|
||||||
|
new Date().getTime() > this._resolveIngressTime + TIMEOUT
|
||||||
|
) {
|
||||||
|
await showAlertDialog(this, {
|
||||||
|
text:
|
||||||
|
this.hass.localize("ingress.timeout") ||
|
||||||
|
"Timeout while waiting for add-on to start, check the add-on logs",
|
||||||
|
title: this._addon.name,
|
||||||
|
confirmText:
|
||||||
|
this.hass.localize("ingress.go_to_logs") || "Go to add-on logs",
|
||||||
|
});
|
||||||
|
await nextRender();
|
||||||
|
navigate(`/hassio/addon/${this._addon.slug}/logs`, { replace: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch(this._addon.ingress_url!);
|
||||||
|
this._resolveIngressStatus = response.status;
|
||||||
|
} catch (err) {
|
||||||
|
// eslint-disable-next-line
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
window.setTimeout(async () => {
|
||||||
|
await this._resolveURL(this._addon!.slug);
|
||||||
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
if (!this._addon) {
|
if (!this._addon || this._resolveIngressStatus === STATUS_BAD_GATEWAY) {
|
||||||
return html` <hass-loading-screen></hass-loading-screen> `;
|
return html`
|
||||||
|
<hass-loading-screen
|
||||||
|
.narrow=${this.narrow}
|
||||||
|
.header=${this._addon?.name}
|
||||||
|
>
|
||||||
|
${this._resolveIngressStatus === STATUS_BAD_GATEWAY
|
||||||
|
? html`<p>
|
||||||
|
${this.hass.localize("ingress.waiting") ||
|
||||||
|
"Waiting for add-on to start"}
|
||||||
|
</p>`
|
||||||
|
: ""}
|
||||||
|
</hass-loading-screen>
|
||||||
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const iframe = html`<iframe src=${this._addon.ingress_url!}></iframe>`;
|
const iframe = html`<iframe src=${this._addon.ingress_url!}></iframe>`;
|
||||||
@@ -134,20 +205,22 @@ class HassioIngressView extends LitElement {
|
|||||||
const oldAddon = oldRoute ? oldRoute.path.substr(1) : undefined;
|
const oldAddon = oldRoute ? oldRoute.path.substr(1) : undefined;
|
||||||
|
|
||||||
if (addon && addon !== oldAddon) {
|
if (addon && addon !== oldAddon) {
|
||||||
this._fetchData(addon);
|
this._resolveURL(addon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _fetchData(addonSlug: string) {
|
private async _fetchData(addonSlug: string) {
|
||||||
const createSessionPromise = createHassioSession(this.hass);
|
const createSessionPromise = createHassioSession(this.hass);
|
||||||
|
|
||||||
let addon;
|
let addon: HassioAddonDetails;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
addon = await fetchHassioAddonInfo(this.hass, addonSlug);
|
addon = await fetchHassioAddonInfo(this.hass, addonSlug);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await showAlertDialog(this, {
|
await showAlertDialog(this, {
|
||||||
text: "Unable to fetch add-on info to start Ingress",
|
text:
|
||||||
|
this.hass.localize("ingress.unable_to_fetch") ||
|
||||||
|
"Unable to fetch add-on info to start Ingress",
|
||||||
title: "Supervisor",
|
title: "Supervisor",
|
||||||
});
|
});
|
||||||
await nextRender();
|
await nextRender();
|
||||||
@@ -157,7 +230,9 @@ class HassioIngressView extends LitElement {
|
|||||||
|
|
||||||
if (!addon.ingress_url) {
|
if (!addon.ingress_url) {
|
||||||
await showAlertDialog(this, {
|
await showAlertDialog(this, {
|
||||||
text: "Add-on does not support Ingress",
|
text:
|
||||||
|
this.hass.localize("ingress.no_ingress") ||
|
||||||
|
"Add-on does not support Ingress",
|
||||||
title: addon.name,
|
title: addon.name,
|
||||||
});
|
});
|
||||||
await nextRender();
|
await nextRender();
|
||||||
@@ -167,7 +242,9 @@ class HassioIngressView extends LitElement {
|
|||||||
|
|
||||||
if (addon.state !== "started") {
|
if (addon.state !== "started") {
|
||||||
await showAlertDialog(this, {
|
await showAlertDialog(this, {
|
||||||
text: "Add-on is not running. Please start it first",
|
text:
|
||||||
|
this.hass.localize("ingress.not_running") ||
|
||||||
|
"The add-on is not running, please start it.",
|
||||||
title: addon.name,
|
title: addon.name,
|
||||||
});
|
});
|
||||||
await nextRender();
|
await nextRender();
|
||||||
@@ -181,7 +258,9 @@ class HassioIngressView extends LitElement {
|
|||||||
session = await createSessionPromise;
|
session = await createSessionPromise;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await showAlertDialog(this, {
|
await showAlertDialog(this, {
|
||||||
text: "Unable to create an Ingress session",
|
text:
|
||||||
|
this.hass.localize("ingress.unable_to_create") ||
|
||||||
|
"Unable to create an Ingress session",
|
||||||
title: addon.name,
|
title: addon.name,
|
||||||
});
|
});
|
||||||
await nextRender();
|
await nextRender();
|
||||||
@@ -189,16 +268,15 @@ class HassioIngressView extends LitElement {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._sessionKeepAlive) {
|
if (!this._sessionKeepAlive) {
|
||||||
clearInterval(this._sessionKeepAlive);
|
this._sessionKeepAlive = window.setInterval(async () => {
|
||||||
|
try {
|
||||||
|
await validateHassioSession(this.hass, session);
|
||||||
|
} catch (err) {
|
||||||
|
session = await createHassioSession(this.hass);
|
||||||
|
}
|
||||||
|
}, 60000);
|
||||||
}
|
}
|
||||||
this._sessionKeepAlive = window.setInterval(async () => {
|
|
||||||
try {
|
|
||||||
await validateHassioSession(this.hass, session);
|
|
||||||
} catch (err) {
|
|
||||||
session = await createHassioSession(this.hass);
|
|
||||||
}
|
|
||||||
}, 60000);
|
|
||||||
|
|
||||||
this._addon = addon;
|
this._addon = addon;
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,8 @@ class HassLoadingScreen extends LitElement {
|
|||||||
|
|
||||||
@property({ type: Boolean }) public rootnav = false;
|
@property({ type: Boolean }) public rootnav = false;
|
||||||
|
|
||||||
|
@property() public header?: string;
|
||||||
|
|
||||||
@property() public narrow?: boolean;
|
@property() public narrow?: boolean;
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
@@ -36,9 +38,13 @@ class HassLoadingScreen extends LitElement {
|
|||||||
@click=${this._handleBack}
|
@click=${this._handleBack}
|
||||||
></ha-icon-button-arrow-prev>
|
></ha-icon-button-arrow-prev>
|
||||||
`}
|
`}
|
||||||
|
${this.header
|
||||||
|
? html`<div class="main-title">${this.header}</div>`
|
||||||
|
: ""}
|
||||||
</div>`}
|
</div>`}
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<ha-circular-progress active></ha-circular-progress>
|
<ha-circular-progress active></ha-circular-progress>
|
||||||
|
<slot class="description"></slot>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
@@ -76,9 +82,14 @@ class HassLoadingScreen extends LitElement {
|
|||||||
.content {
|
.content {
|
||||||
height: calc(100% - var(--header-height));
|
height: calc(100% - var(--header-height));
|
||||||
display: flex;
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
.description {
|
||||||
|
margin-top: 12px;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@@ -4016,5 +4016,15 @@
|
|||||||
"device_path": "Device path"
|
"device_path": "Device path"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"ingress": {
|
||||||
|
"not_running": "[%key:supervisor::my::error_addon_not_started%]",
|
||||||
|
"waiting": "Waiting for add-on to start",
|
||||||
|
"unable_to_create": "Unable to create an Ingress session",
|
||||||
|
"no_ingress": "[%key:supervisor::my::error_addon_no_ingress%]",
|
||||||
|
"unable_to_fetch": "Unable to fetch add-on info to start Ingress",
|
||||||
|
"timeout": "Timeout while waiting for add-on to start, check the add-on logs",
|
||||||
|
"go_to_dashboard": "Go to add-on dashboard",
|
||||||
|
"go_to_logs": "Go to add-on logs"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user