Properly lock theme into themes dark or light mode

This commit is contained in:
schroda
2024-09-06 23:29:16 +02:00
parent 290f031479
commit 81fe710531
2 changed files with 4 additions and 3 deletions

View File

@@ -829,7 +829,7 @@
}, },
"info": { "info": {
"creating_theme": "Create a custom theme with the <2>MUI Theme Creator</2>, copy everything after \"themeOptions\" from \"{\" to \"}\" and paste it into the \"theme\" text field.", "creating_theme": "Create a custom theme with the <2>MUI Theme Creator</2>, copy everything after \"themeOptions\" from \"{\" to \"}\" and paste it into the \"theme\" text field.",
"theme_mode_lock": "In case the \"mode\" is defined in the \"palette\" object, the theme will be locked into this mode and will not change regardless of the apps device theme" "theme_mode_lock": "In case \"mode\" or \"type\" is defined in the \"palette\" object, the theme will be locked into this mode and will not change regardless of the selected apps device theme"
}, },
"theme_name": "Name" "theme_name": "Name"
}, },

View File

@@ -29,8 +29,9 @@ export const createTheme = (
) => { ) => {
const systemMode = MediaQuery.getSystemThemeMode(); const systemMode = MediaQuery.getSystemThemeMode();
const isStaticThemeMode = !!appTheme.muiTheme.palette?.mode; const appThemeType = (appTheme.muiTheme.palette as any)?.type ?? appTheme.muiTheme.palette?.mode;
const appThemeMode = appTheme.muiTheme.palette?.mode === 'dark' ? ThemeMode.DARK : ThemeMode.LIGHT; const isStaticThemeMode = !!appThemeType;
const appThemeMode = appThemeType === 'dark' ? ThemeMode.DARK : ThemeMode.LIGHT;
const staticThemeMode = isStaticThemeMode ? appThemeMode : undefined; const staticThemeMode = isStaticThemeMode ? appThemeMode : undefined;
const mode = staticThemeMode ?? (themeMode === ThemeMode.SYSTEM ? systemMode : themeMode); const mode = staticThemeMode ?? (themeMode === ThemeMode.SYSTEM ? systemMode : themeMode);