mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 03:06:41 +00:00
Ensure current active dark modes gets used for manually set themes (#10307)
This commit is contained in:
parent
f1cb21e7fc
commit
bdb3c04037
@ -113,12 +113,6 @@ export class HassioMain extends SupervisorBaseElement {
|
|||||||
: this.hass.themes.default_theme);
|
: this.hass.themes.default_theme);
|
||||||
|
|
||||||
themeSettings = this.hass.selectedTheme;
|
themeSettings = this.hass.selectedTheme;
|
||||||
if (themeSettings?.dark === undefined) {
|
|
||||||
themeSettings = {
|
|
||||||
...this.hass.selectedTheme,
|
|
||||||
dark: this.hass.themes.darkMode,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
themeName =
|
themeName =
|
||||||
(this.hass.selectedTheme as unknown as string) ||
|
(this.hass.selectedTheme as unknown as string) ||
|
||||||
|
@ -36,55 +36,62 @@ export const applyThemesOnElement = (
|
|||||||
let cacheKey = selectedTheme;
|
let cacheKey = selectedTheme;
|
||||||
let themeRules: Partial<ThemeVars> = {};
|
let themeRules: Partial<ThemeVars> = {};
|
||||||
|
|
||||||
if (themeSettings) {
|
// If there is no explicitly desired dark mode provided, we automatically
|
||||||
if (themeSettings.dark) {
|
// use the active one from hass.themes.
|
||||||
cacheKey = `${cacheKey}__dark`;
|
if (!themeSettings || themeSettings?.dark === undefined) {
|
||||||
themeRules = { ...darkStyles };
|
themeSettings = {
|
||||||
|
...themeSettings,
|
||||||
|
dark: themes.darkMode,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (themeSettings.dark) {
|
||||||
|
cacheKey = `${cacheKey}__dark`;
|
||||||
|
themeRules = { ...darkStyles };
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedTheme === "default") {
|
||||||
|
// Determine the primary and accent colors from the current settings.
|
||||||
|
// Fallbacks are implicitly the HA default blue and orange or the
|
||||||
|
// derived "darkStyles" values, depending on the light vs dark mode.
|
||||||
|
const primaryColor = themeSettings.primaryColor;
|
||||||
|
const accentColor = themeSettings.accentColor;
|
||||||
|
|
||||||
|
if (themeSettings.dark && primaryColor) {
|
||||||
|
themeRules["app-header-background-color"] = hexBlend(
|
||||||
|
primaryColor,
|
||||||
|
"#121212",
|
||||||
|
8
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedTheme === "default") {
|
if (primaryColor) {
|
||||||
// Determine the primary and accent colors from the current settings.
|
cacheKey = `${cacheKey}__primary_${primaryColor}`;
|
||||||
// Fallbacks are implicitly the HA default blue and orange or the
|
const rgbPrimaryColor = hex2rgb(primaryColor);
|
||||||
// derived "darkStyles" values, depending on the light vs dark mode.
|
const labPrimaryColor = rgb2lab(rgbPrimaryColor);
|
||||||
const primaryColor = themeSettings.primaryColor;
|
themeRules["primary-color"] = primaryColor;
|
||||||
const accentColor = themeSettings.accentColor;
|
const rgbLightPrimaryColor = lab2rgb(labBrighten(labPrimaryColor));
|
||||||
|
themeRules["light-primary-color"] = rgb2hex(rgbLightPrimaryColor);
|
||||||
|
themeRules["dark-primary-color"] = lab2hex(labDarken(labPrimaryColor));
|
||||||
|
themeRules["text-primary-color"] =
|
||||||
|
rgbContrast(rgbPrimaryColor, [33, 33, 33]) < 6 ? "#fff" : "#212121";
|
||||||
|
themeRules["text-light-primary-color"] =
|
||||||
|
rgbContrast(rgbLightPrimaryColor, [33, 33, 33]) < 6
|
||||||
|
? "#fff"
|
||||||
|
: "#212121";
|
||||||
|
themeRules["state-icon-color"] = themeRules["dark-primary-color"];
|
||||||
|
}
|
||||||
|
if (accentColor) {
|
||||||
|
cacheKey = `${cacheKey}__accent_${accentColor}`;
|
||||||
|
themeRules["accent-color"] = accentColor;
|
||||||
|
const rgbAccentColor = hex2rgb(accentColor);
|
||||||
|
themeRules["text-accent-color"] =
|
||||||
|
rgbContrast(rgbAccentColor, [33, 33, 33]) < 6 ? "#fff" : "#212121";
|
||||||
|
}
|
||||||
|
|
||||||
if (themeSettings.dark && primaryColor) {
|
// Nothing was changed
|
||||||
themeRules["app-header-background-color"] = hexBlend(
|
if (element._themes?.cacheKey === cacheKey) {
|
||||||
primaryColor,
|
return;
|
||||||
"#121212",
|
|
||||||
8
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (primaryColor) {
|
|
||||||
cacheKey = `${cacheKey}__primary_${primaryColor}`;
|
|
||||||
const rgbPrimaryColor = hex2rgb(primaryColor);
|
|
||||||
const labPrimaryColor = rgb2lab(rgbPrimaryColor);
|
|
||||||
themeRules["primary-color"] = primaryColor;
|
|
||||||
const rgbLightPrimaryColor = lab2rgb(labBrighten(labPrimaryColor));
|
|
||||||
themeRules["light-primary-color"] = rgb2hex(rgbLightPrimaryColor);
|
|
||||||
themeRules["dark-primary-color"] = lab2hex(labDarken(labPrimaryColor));
|
|
||||||
themeRules["text-primary-color"] =
|
|
||||||
rgbContrast(rgbPrimaryColor, [33, 33, 33]) < 6 ? "#fff" : "#212121";
|
|
||||||
themeRules["text-light-primary-color"] =
|
|
||||||
rgbContrast(rgbLightPrimaryColor, [33, 33, 33]) < 6
|
|
||||||
? "#fff"
|
|
||||||
: "#212121";
|
|
||||||
themeRules["state-icon-color"] = themeRules["dark-primary-color"];
|
|
||||||
}
|
|
||||||
if (accentColor) {
|
|
||||||
cacheKey = `${cacheKey}__accent_${accentColor}`;
|
|
||||||
themeRules["accent-color"] = accentColor;
|
|
||||||
const rgbAccentColor = hex2rgb(accentColor);
|
|
||||||
themeRules["text-accent-color"] =
|
|
||||||
rgbContrast(rgbAccentColor, [33, 33, 33]) < 6 ? "#fff" : "#212121";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Nothing was changed
|
|
||||||
if (element._themes?.cacheKey === cacheKey) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,12 +91,6 @@ class SupervisorErrorScreen extends LitElement {
|
|||||||
: this.hass.themes.default_theme);
|
: this.hass.themes.default_theme);
|
||||||
|
|
||||||
themeSettings = this.hass.selectedTheme;
|
themeSettings = this.hass.selectedTheme;
|
||||||
if (themeName === "default" && themeSettings?.dark === undefined) {
|
|
||||||
themeSettings = {
|
|
||||||
...this.hass.selectedTheme,
|
|
||||||
dark: this.hass.themes.darkMode,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
themeName =
|
themeName =
|
||||||
(this.hass.selectedTheme as unknown as string) ||
|
(this.hass.selectedTheme as unknown as string) ||
|
||||||
|
Loading…
x
Reference in New Issue
Block a user