Skip to content

Commit

Permalink
Add safe mode theme and alert dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
bramkragten committed Oct 24, 2023
1 parent eb35eb3 commit 6751764
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 34 deletions.
83 changes: 53 additions & 30 deletions src/state/disconnect-toast-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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("/");
}
}

Expand Down
15 changes: 13 additions & 2 deletions src/state/themes-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand All @@ -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 },
});
Expand Down
8 changes: 6 additions & 2 deletions src/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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"
}
Expand Down

0 comments on commit 6751764

Please sign in to comment.