mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Add safe mode theme and alert dialog
This commit is contained in:
parent
eb35eb3de5
commit
67517643ef
@ -12,6 +12,7 @@ import { domainToName } from "../data/integration";
|
||||
import { Constructor } from "../types";
|
||||
import { showToast } from "../util/toast";
|
||||
import { HassBaseEl } from "./hass-base-mixin";
|
||||
import { navigate } from "../common/navigate";
|
||||
|
||||
export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
class extends superClass {
|
||||
@ -28,40 +29,62 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
updated(changedProperties) {
|
||||
super.updated(changedProperties);
|
||||
const oldHass = changedProperties.get("hass");
|
||||
if (
|
||||
!changedProperties.has("hass") ||
|
||||
!this.hass!.config ||
|
||||
oldHass?.config?.state === this.hass!.config.state
|
||||
) {
|
||||
if (!changedProperties.has("hass") || !this.hass!.config) {
|
||||
return;
|
||||
}
|
||||
if (this.hass!.config.state === STATE_NOT_RUNNING) {
|
||||
showToast(this, {
|
||||
message:
|
||||
this.hass!.localize("ui.notification_toast.starting") ||
|
||||
"Home Assistant is starting, not everything will be available until it is finished.",
|
||||
duration: 0,
|
||||
dismissable: false,
|
||||
action: {
|
||||
text:
|
||||
this.hass!.localize("ui.notification_toast.dismiss") || "Dismiss",
|
||||
action: () => {
|
||||
this._unsubscribeBootstrapIntegrations();
|
||||
if (oldHass?.config?.state !== this.hass!.config.state) {
|
||||
if (this.hass!.config.state === STATE_NOT_RUNNING) {
|
||||
showToast(this, {
|
||||
message:
|
||||
this.hass!.localize("ui.notification_toast.starting") ||
|
||||
"Home Assistant is starting, not everything will be available until it is finished.",
|
||||
duration: 0,
|
||||
dismissable: false,
|
||||
action: {
|
||||
text:
|
||||
this.hass!.localize("ui.notification_toast.dismiss") ||
|
||||
"Dismiss",
|
||||
action: () => {
|
||||
this._unsubscribeBootstrapIntegrations();
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
this._subscribeBootstrapIntegrations();
|
||||
} else if (
|
||||
oldHass?.config &&
|
||||
oldHass.config.state === STATE_NOT_RUNNING &&
|
||||
(this.hass!.config.state === STATE_STARTING ||
|
||||
this.hass!.config.state === STATE_RUNNING)
|
||||
});
|
||||
this._subscribeBootstrapIntegrations();
|
||||
} else if (
|
||||
oldHass?.config &&
|
||||
oldHass.config.state === STATE_NOT_RUNNING &&
|
||||
(this.hass!.config.state === STATE_STARTING ||
|
||||
this.hass!.config.state === STATE_RUNNING)
|
||||
) {
|
||||
this._unsubscribeBootstrapIntegrations();
|
||||
showToast(this, {
|
||||
message: this.hass!.localize("ui.notification_toast.started"),
|
||||
duration: 5000,
|
||||
});
|
||||
}
|
||||
}
|
||||
if (
|
||||
this.hass!.config.safe_mode &&
|
||||
oldHass?.config?.safe_mode !== this.hass!.config.safe_mode
|
||||
) {
|
||||
this._unsubscribeBootstrapIntegrations();
|
||||
showToast(this, {
|
||||
message: this.hass!.localize("ui.notification_toast.started"),
|
||||
duration: 5000,
|
||||
});
|
||||
import("../dialogs/generic/show-dialog-box").then(
|
||||
({ showAlertDialog }) => {
|
||||
showAlertDialog(this, {
|
||||
title:
|
||||
this.hass!.localize("ui.dialogs.safe_mode.title") ||
|
||||
"Safe mode",
|
||||
text:
|
||||
this.hass!.localize("ui.dialogs.safe_mode.text") ||
|
||||
"Home Assistant is running in safe mode, custom integrations and modules are not available. Restart Home Assistant to exit safe mode.",
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
if (
|
||||
this.hass!.config.recovery_mode &&
|
||||
oldHass?.config?.recovery_mode !== this.hass!.config.recovery_mode
|
||||
) {
|
||||
navigate("/");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,18 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
}
|
||||
|
||||
let themeSettings: Partial<HomeAssistant["selectedTheme"]> =
|
||||
this.hass.selectedTheme;
|
||||
this.hass.config.recovery_mode || this.hass.config.safe_mode
|
||||
? {
|
||||
...this.hass.selectedTheme,
|
||||
theme: "default",
|
||||
primaryColor: this.hass.config.recovery_mode
|
||||
? "#db4437"
|
||||
: "#e48629",
|
||||
accentColor: this.hass.config.recovery_mode
|
||||
? "#ffca28"
|
||||
: "#db4437",
|
||||
}
|
||||
: this.hass.selectedTheme;
|
||||
|
||||
const themeName =
|
||||
themeSettings?.theme ||
|
||||
@ -90,7 +101,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
darkMode = false;
|
||||
}
|
||||
|
||||
themeSettings = { ...this.hass.selectedTheme, dark: darkMode };
|
||||
themeSettings = { ...themeSettings, dark: darkMode };
|
||||
this._updateHass({
|
||||
themes: { ...this.hass.themes!, theme: themeName },
|
||||
});
|
||||
|
@ -786,6 +786,10 @@
|
||||
}
|
||||
},
|
||||
"dialogs": {
|
||||
"safe_mode": {
|
||||
"title": "Safe mode",
|
||||
"text": "Home Assistant is running in safe mode, custom integrations and frontend modules are not available. Restart Home Assistant to exit safe mode."
|
||||
},
|
||||
"quick-bar": {
|
||||
"commands": {
|
||||
"reload": {
|
||||
@ -1236,9 +1240,9 @@
|
||||
},
|
||||
"restart-safe-mode": {
|
||||
"title": "Restart Home Assistant in safe mode",
|
||||
"description": "Restart Home Assistant without loading any custom integrations and modules.",
|
||||
"description": "Restart Home Assistant without loading any custom integrations and frontend modules.",
|
||||
"confirm_title": "Restart Home Assistant in safe mode?",
|
||||
"confirm_description": "This will restart Home Assistant without loading any custom integrations and modules.",
|
||||
"confirm_description": "This will restart Home Assistant without loading any custom integrations and frontend modules.",
|
||||
"confirm_action": "Restart",
|
||||
"failed": "Failed to restart Home Assistant"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user