Compare commits

...

13 Commits

Author SHA1 Message Date
Joakim Sørensen
d82f87f72f Update hassio/src/ingress-view/hassio-ingress-view.ts
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2021-07-08 16:24:11 +02:00
Joakim Sørensen
4aa759f7f5 Add type 2021-06-30 08:57:09 +00:00
Joakim Sørensen
774393a515 adjust it 2021-06-30 08:48:40 +00:00
Joakim Sørensen
9ced09035f Merge branch 'dev' of https://github.com/home-assistant/frontend into waitfor-ingress 2021-06-30 08:26:13 +00:00
Joakim Sørensen
6988cc6170 Rename localize key 2021-06-21 08:10:19 +00:00
Joakim Sørensen
56a3c8c0c0 Check status 2021-06-18 14:11:09 +00:00
Joakim Sørensen
1519355d76 prettier 2021-06-18 13:37:51 +00:00
Joakim Sørensen
72d086210d Update hassio/src/ingress-view/hassio-ingress-view.ts
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
2021-06-17 19:39:12 +02:00
Joakim Sørensen
f812d25024 Update hassio/src/ingress-view/hassio-ingress-view.ts 2021-06-17 15:33:26 +02:00
Joakim Sørensen
821be14dcb Update hassio/src/ingress-view/hassio-ingress-view.ts 2021-06-17 15:28:17 +02:00
Joakim Sørensen
6eac30a022 use const 2021-06-16 15:25:28 +00:00
Joakim Sørensen
eac156d53b Reuse keys 2021-06-16 15:14:31 +00:00
Joakim Sørensen
b169ae55e1 Show loading screen while waiting for ingress to be able to show 2021-06-16 15:09:15 +00:00
3 changed files with 120 additions and 21 deletions

View File

@@ -27,20 +27,26 @@ import "../../../src/layouts/hass-loading-screen";
import "../../../src/layouts/hass-subpage";
import { HomeAssistant, Route } from "../../../src/types";
const STATUS_BAD_GATEWAY = 502;
const TIMEOUT = 60000;
@customElement("hassio-ingress-view")
class HassioIngressView extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
@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;
@property({ type: Boolean })
public narrow = false;
@state() private _resolveIngressStatus?: number;
private _resolveIngressTime?: number;
private _sessionKeepAlive?: number;
@@ -51,11 +57,76 @@ class HassioIngressView extends LitElement {
clearInterval(this._sessionKeepAlive);
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 {
if (!this._addon) {
return html` <hass-loading-screen></hass-loading-screen> `;
if (!this._addon || this._resolveIngressStatus === STATUS_BAD_GATEWAY) {
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>`;
@@ -134,20 +205,22 @@ class HassioIngressView extends LitElement {
const oldAddon = oldRoute ? oldRoute.path.substr(1) : undefined;
if (addon && addon !== oldAddon) {
this._fetchData(addon);
this._resolveURL(addon);
}
}
private async _fetchData(addonSlug: string) {
const createSessionPromise = createHassioSession(this.hass);
let addon;
let addon: HassioAddonDetails;
try {
addon = await fetchHassioAddonInfo(this.hass, addonSlug);
} catch (err) {
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",
});
await nextRender();
@@ -157,7 +230,9 @@ class HassioIngressView extends LitElement {
if (!addon.ingress_url) {
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,
});
await nextRender();
@@ -167,7 +242,9 @@ class HassioIngressView extends LitElement {
if (addon.state !== "started") {
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,
});
await nextRender();
@@ -181,7 +258,9 @@ class HassioIngressView extends LitElement {
session = await createSessionPromise;
} catch (err) {
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,
});
await nextRender();
@@ -189,16 +268,15 @@ class HassioIngressView extends LitElement {
return;
}
if (this._sessionKeepAlive) {
clearInterval(this._sessionKeepAlive);
if (!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;
}

View File

@@ -16,6 +16,8 @@ class HassLoadingScreen extends LitElement {
@property({ type: Boolean }) public rootnav = false;
@property() public header?: string;
@property() public narrow?: boolean;
protected render(): TemplateResult {
@@ -36,9 +38,13 @@ class HassLoadingScreen extends LitElement {
@click=${this._handleBack}
></ha-icon-button-arrow-prev>
`}
${this.header
? html`<div class="main-title">${this.header}</div>`
: ""}
</div>`}
<div class="content">
<ha-circular-progress active></ha-circular-progress>
<slot class="description"></slot>
</div>
`;
}
@@ -76,9 +82,14 @@ class HassLoadingScreen extends LitElement {
.content {
height: calc(100% - var(--header-height));
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.description {
margin-top: 12px;
display: block;
}
`,
];
}

View File

@@ -4016,5 +4016,15 @@
"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"
}
}