mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-13 17:22:08 -04:00
theme: improve handling of custom themes with variants and accents in
light/dark mode (e.g. catpuccin will react to light/dark changes and remember theme per-mode) fixes #1094
This commit is contained in:
@@ -2210,19 +2210,34 @@ Singleton {
|
||||
Theme.reloadCustomThemeVariant();
|
||||
}
|
||||
|
||||
function getRegistryThemeMultiVariant(themeId, defaults) {
|
||||
function getRegistryThemeMultiVariant(themeId, defaults, mode) {
|
||||
var stored = registryThemeVariants[themeId];
|
||||
if (stored && typeof stored === "object")
|
||||
return stored;
|
||||
return defaults || {};
|
||||
if (!stored || typeof stored !== "object")
|
||||
return defaults || {};
|
||||
if ((stored.dark && typeof stored.dark === "object") || (stored.light && typeof stored.light === "object")) {
|
||||
if (!mode)
|
||||
return stored.dark || stored.light || defaults || {};
|
||||
var modeData = stored[mode];
|
||||
if (modeData && typeof modeData === "object")
|
||||
return modeData;
|
||||
return defaults || {};
|
||||
}
|
||||
return stored;
|
||||
}
|
||||
|
||||
function setRegistryThemeMultiVariant(themeId, flavor, accent) {
|
||||
function setRegistryThemeMultiVariant(themeId, flavor, accent, mode) {
|
||||
var variants = JSON.parse(JSON.stringify(registryThemeVariants));
|
||||
variants[themeId] = {
|
||||
flavor: flavor,
|
||||
accent: accent
|
||||
};
|
||||
var existing = variants[themeId];
|
||||
var perMode = {};
|
||||
if (existing && typeof existing === "object") {
|
||||
if ((existing.dark && typeof existing.dark === "object") || (existing.light && typeof existing.light === "object")) {
|
||||
perMode = existing;
|
||||
} else if (typeof existing.flavor === "string") {
|
||||
perMode.dark = {flavor: existing.flavor, accent: existing.accent || ""};
|
||||
}
|
||||
}
|
||||
perMode[mode || "dark"] = {flavor: flavor, accent: accent};
|
||||
variants[themeId] = perMode;
|
||||
registryThemeVariants = variants;
|
||||
saveSettings();
|
||||
if (typeof Theme !== "undefined")
|
||||
|
||||
@@ -971,7 +971,7 @@ Singleton {
|
||||
if (themeData.variants.type === "multi" && themeData.variants.flavors && themeData.variants.accents) {
|
||||
const defaults = themeData.variants.defaults || {};
|
||||
const modeDefaults = defaults[colorMode] || defaults.dark || {};
|
||||
const stored = typeof SettingsData !== "undefined" ? SettingsData.getRegistryThemeMultiVariant(themeId, modeDefaults) : modeDefaults;
|
||||
const stored = typeof SettingsData !== "undefined" ? SettingsData.getRegistryThemeMultiVariant(themeId, modeDefaults, colorMode) : modeDefaults;
|
||||
var flavorId = stored.flavor || modeDefaults.flavor || "";
|
||||
const accentId = stored.accent || modeDefaults.accent || "";
|
||||
var flavor = findVariant(themeData.variants.flavors, flavorId);
|
||||
@@ -1365,8 +1365,8 @@ Singleton {
|
||||
const defaults = customThemeRawData.variants.defaults || {};
|
||||
const darkDefaults = defaults.dark || {};
|
||||
const lightDefaults = defaults.light || defaults.dark || {};
|
||||
const storedDark = typeof SettingsData !== "undefined" ? SettingsData.getRegistryThemeMultiVariant(themeId, darkDefaults) : darkDefaults;
|
||||
const storedLight = typeof SettingsData !== "undefined" ? SettingsData.getRegistryThemeMultiVariant(themeId, lightDefaults) : lightDefaults;
|
||||
const storedDark = typeof SettingsData !== "undefined" ? SettingsData.getRegistryThemeMultiVariant(themeId, darkDefaults, "dark") : darkDefaults;
|
||||
const storedLight = typeof SettingsData !== "undefined" ? SettingsData.getRegistryThemeMultiVariant(themeId, lightDefaults, "light") : lightDefaults;
|
||||
const darkFlavorId = storedDark.flavor || darkDefaults.flavor || "";
|
||||
const lightFlavorId = storedLight.flavor || lightDefaults.flavor || "";
|
||||
const accentId = storedDark.accent || darkDefaults.accent || "";
|
||||
|
||||
Reference in New Issue
Block a user