mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +00:00
Disable dashboard resources in safe mode (#18382)
This commit is contained in:
parent
8350d71f6e
commit
eb35eb3de5
@ -309,7 +309,7 @@ export class HcMain extends HassElement {
|
|||||||
? await fetchResources(this.hass!.connection)
|
? await fetchResources(this.hass!.connection)
|
||||||
: (this._lovelaceConfig as LegacyLovelaceConfig).resources;
|
: (this._lovelaceConfig as LegacyLovelaceConfig).resources;
|
||||||
if (resources) {
|
if (resources) {
|
||||||
loadLovelaceResources(resources, this.hass!.auth.data.hassUrl);
|
loadLovelaceResources(resources, this.hass!);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@
|
|||||||
"fuse.js": "6.6.2",
|
"fuse.js": "6.6.2",
|
||||||
"google-timezones-json": "1.2.0",
|
"google-timezones-json": "1.2.0",
|
||||||
"hls.js": "1.4.12",
|
"hls.js": "1.4.12",
|
||||||
"home-assistant-js-websocket": "9.0.0",
|
"home-assistant-js-websocket": "9.1.0",
|
||||||
"idb-keyval": "6.2.1",
|
"idb-keyval": "6.2.1",
|
||||||
"intl-messageformat": "10.5.4",
|
"intl-messageformat": "10.5.4",
|
||||||
"js-yaml": "4.1.0",
|
"js-yaml": "4.1.0",
|
||||||
|
@ -22,6 +22,7 @@ export const demoConfig: HassConfig = {
|
|||||||
allowlist_external_urls: [],
|
allowlist_external_urls: [],
|
||||||
config_source: "storage",
|
config_source: "storage",
|
||||||
recovery_mode: false,
|
recovery_mode: false,
|
||||||
|
safe_mode: false,
|
||||||
state: STATE_RUNNING,
|
state: STATE_RUNNING,
|
||||||
internal_url: "http://homeassistant.local:8123",
|
internal_url: "http://homeassistant.local:8123",
|
||||||
external_url: null,
|
external_url: null,
|
||||||
|
@ -144,14 +144,14 @@ export class HaConfigLovelaceRescources extends LitElement {
|
|||||||
this._resources = this._resources!.concat(created).sort((res1, res2) =>
|
this._resources = this._resources!.concat(created).sort((res1, res2) =>
|
||||||
stringCompare(res1.url, res2.url, this.hass!.locale.language)
|
stringCompare(res1.url, res2.url, this.hass!.locale.language)
|
||||||
);
|
);
|
||||||
loadLovelaceResources([created], this.hass!.auth.data.hassUrl);
|
loadLovelaceResources([created], this.hass!);
|
||||||
},
|
},
|
||||||
updateResource: async (values) => {
|
updateResource: async (values) => {
|
||||||
const updated = await updateResource(this.hass!, resource!.id, values);
|
const updated = await updateResource(this.hass!, resource!.id, values);
|
||||||
this._resources = this._resources!.map((res) =>
|
this._resources = this._resources!.map((res) =>
|
||||||
res === resource ? updated : res
|
res === resource ? updated : res
|
||||||
);
|
);
|
||||||
loadLovelaceResources([updated], this.hass!.auth.data.hassUrl);
|
loadLovelaceResources([updated], this.hass!);
|
||||||
},
|
},
|
||||||
removeResource: async () => {
|
removeResource: async () => {
|
||||||
if (
|
if (
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { loadCSS, loadJS, loadModule } from "../../../common/dom/load_resource";
|
import { loadCSS, loadJS, loadModule } from "../../../common/dom/load_resource";
|
||||||
import { LovelaceResource } from "../../../data/lovelace";
|
import { LovelaceResource } from "../../../data/lovelace";
|
||||||
|
import type { HomeAssistant } from "../../../types";
|
||||||
|
|
||||||
// CSS and JS should only be imported once. Modules and HTML are safe.
|
// CSS and JS should only be imported once. Modules and HTML are safe.
|
||||||
const CSS_CACHE = {};
|
const CSS_CACHE = {};
|
||||||
@ -7,10 +8,17 @@ const JS_CACHE = {};
|
|||||||
|
|
||||||
export const loadLovelaceResources = (
|
export const loadLovelaceResources = (
|
||||||
resources: NonNullable<LovelaceResource[]>,
|
resources: NonNullable<LovelaceResource[]>,
|
||||||
hassUrl: string
|
hass: HomeAssistant
|
||||||
) =>
|
) => {
|
||||||
|
// Don't load ressources on safe mode
|
||||||
|
if (hass.config.safe_mode) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
resources.forEach((resource) => {
|
resources.forEach((resource) => {
|
||||||
const normalizedUrl = new URL(resource.url, hassUrl).toString();
|
const normalizedUrl = new URL(
|
||||||
|
resource.url,
|
||||||
|
hass.auth.data.hassUrl
|
||||||
|
).toString();
|
||||||
switch (resource.type) {
|
switch (resource.type) {
|
||||||
case "css":
|
case "css":
|
||||||
if (normalizedUrl in CSS_CACHE) {
|
if (normalizedUrl in CSS_CACHE) {
|
||||||
@ -35,3 +43,4 @@ export const loadLovelaceResources = (
|
|||||||
console.warn(`Unknown resource type specified: ${resource.type}`);
|
console.warn(`Unknown resource type specified: ${resource.type}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
@ -229,10 +229,9 @@ export class LovelacePanel extends LitElement {
|
|||||||
}
|
}
|
||||||
if (!resourcesLoaded) {
|
if (!resourcesLoaded) {
|
||||||
resourcesLoaded = true;
|
resourcesLoaded = true;
|
||||||
(llWindow.llResProm || fetchResources(this.hass!.connection)).then(
|
const resources = await (llWindow.llResProm ||
|
||||||
(resources) =>
|
fetchResources(this.hass!.connection));
|
||||||
loadLovelaceResources(resources, this.hass!.auth.data.hassUrl)
|
loadLovelaceResources(resources, this.hass!);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.urlPath !== null || !confProm) {
|
if (this.urlPath !== null || !confProm) {
|
||||||
|
10
yarn.lock
10
yarn.lock
@ -9789,7 +9789,7 @@ __metadata:
|
|||||||
gulp-rename: 2.0.0
|
gulp-rename: 2.0.0
|
||||||
gulp-zopfli-green: 6.0.1
|
gulp-zopfli-green: 6.0.1
|
||||||
hls.js: 1.4.12
|
hls.js: 1.4.12
|
||||||
home-assistant-js-websocket: 9.0.0
|
home-assistant-js-websocket: 9.1.0
|
||||||
html-minifier-terser: 7.2.0
|
html-minifier-terser: 7.2.0
|
||||||
husky: 8.0.3
|
husky: 8.0.3
|
||||||
idb-keyval: 6.2.1
|
idb-keyval: 6.2.1
|
||||||
@ -9865,10 +9865,10 @@ __metadata:
|
|||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
"home-assistant-js-websocket@npm:9.0.0":
|
"home-assistant-js-websocket@npm:9.1.0":
|
||||||
version: 9.0.0
|
version: 9.1.0
|
||||||
resolution: "home-assistant-js-websocket@npm:9.0.0"
|
resolution: "home-assistant-js-websocket@npm:9.1.0"
|
||||||
checksum: c1543483f55c1d135400b9bd6dce084b5942f57dc8098f4c84c6ece7b8289c558dc6578c45c94eecde99fec134041d8c4f458492e2573875bfb706df70ffd902
|
checksum: 4692b856b1e89c05ec772e7e3590d6b0cd0f6ef711eac9fa888d62c21fe4f9c669ab7ae8b7b5c52af58e4821c7cecb4167ec8a617426bff17b8095fd44a9c8e4
|
||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user