From 1a2312460ad9edf8704066236a267ef5e13796ee Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Fri, 27 Oct 2023 13:29:00 +0200 Subject: [PATCH] Disable resource panel in safe mode (#18437) --- .../resources/ha-config-lovelace-resources.ts | 62 ++++++++++++++++++- src/panels/lovelace/common/load-resources.ts | 5 -- src/translations/en.json | 2 + 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/src/panels/config/lovelace/resources/ha-config-lovelace-resources.ts b/src/panels/config/lovelace/resources/ha-config-lovelace-resources.ts index a1733e094040..5dc3abbcfe75 100644 --- a/src/panels/config/lovelace/resources/ha-config-lovelace-resources.ts +++ b/src/panels/config/lovelace/resources/ha-config-lovelace-resources.ts @@ -1,5 +1,12 @@ import { mdiPlus } from "@mdi/js"; -import { html, LitElement, PropertyValues, TemplateResult } from "lit"; +import { + css, + CSSResultGroup, + html, + LitElement, + PropertyValues, + TemplateResult, +} from "lit"; import { customElement, property, state } from "lit/decorators"; import memoize from "memoize-one"; import { stringCompare } from "../../../../common/string/compare"; @@ -7,6 +14,7 @@ import { DataTableColumnContainer, RowClickedEvent, } from "../../../../components/data-table/ha-data-table"; +import "../../../../components/ha-card"; import "../../../../components/ha-fab"; import "../../../../components/ha-svg-icon"; import { @@ -21,7 +29,9 @@ import { showConfirmationDialog, } from "../../../../dialogs/generic/show-dialog-box"; import "../../../../layouts/hass-loading-screen"; +import "../../../../layouts/hass-subpage"; import "../../../../layouts/hass-tabs-subpage-data-table"; +import { haStyle } from "../../../../resources/styles"; import { HomeAssistant, Route } from "../../../../types"; import { loadLovelaceResources } from "../../../lovelace/common/load-resources"; import { lovelaceTabs } from "../ha-config-lovelace"; @@ -72,6 +82,36 @@ export class HaConfigLovelaceRescources extends LitElement { return html` `; } + if (this.hass.config.safe_mode) { + return html` + +
+ +
+

+ ${this.hass.localize( + "ui.panel.config.lovelace.resources.unavailable" + )} +

+

+ ${this.hass.localize( + "ui.panel.config.lovelace.resources.unavailable_safe_mode" + )} +

+
+
+
+
+ `; + } + return html` , hass: HomeAssistant ) => { - // Don't load ressources on safe mode - // Sometimes, hass.config is null but it should not. - if (hass.config?.safe_mode) { - return; - } resources.forEach((resource) => { const normalizedUrl = new URL( resource.url, diff --git a/src/translations/en.json b/src/translations/en.json index c99285a8c0b9..13edc9aa8ec5 100644 --- a/src/translations/en.json +++ b/src/translations/en.json @@ -2140,6 +2140,8 @@ "js": "JavaScript file (deprecated)", "module": "JavaScript module" }, + "unavailable": "Resources unavailable", + "unavailable_safe_mode": "Resources are not available in safe mode", "picker": { "headers": { "url": "URL",