* Loads custom themes from settings. * @param customThemesSettings Custom themes from settings.
(customThemesSettings?: Record<string, CustomTheme>)
| 66 | * @param customThemesSettings Custom themes from settings. |
| 67 | */ |
| 68 | loadCustomThemes(customThemesSettings?: Record<string, CustomTheme>): void { |
| 69 | this.customThemes.clear(); |
| 70 | |
| 71 | if (!customThemesSettings) { |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | for (const [name, customThemeConfig] of Object.entries( |
| 76 | customThemesSettings, |
| 77 | )) { |
| 78 | const validation = validateCustomTheme(customThemeConfig); |
| 79 | if (validation.isValid) { |
| 80 | if (validation.warning) { |
| 81 | console.warn(`Theme "${name}": ${validation.warning}`); |
| 82 | } |
| 83 | const themeWithDefaults: CustomTheme = { |
| 84 | ...DEFAULT_THEME.colors, |
| 85 | ...customThemeConfig, |
| 86 | name: customThemeConfig.name || name, |
| 87 | type: 'custom', |
| 88 | }; |
| 89 | |
| 90 | try { |
| 91 | const theme = createCustomTheme(themeWithDefaults); |
| 92 | this.customThemes.set(name, theme); |
| 93 | } catch (error) { |
| 94 | console.warn(`Failed to load custom theme "${name}":`, error); |
| 95 | } |
| 96 | } else { |
| 97 | console.warn(`Invalid custom theme "${name}": ${validation.error}`); |
| 98 | } |
| 99 | } |
| 100 | // If the current active theme is a custom theme, keep it if still valid |
| 101 | if ( |
| 102 | this.activeTheme && |
| 103 | this.activeTheme.type === 'custom' && |
| 104 | this.customThemes.has(this.activeTheme.name) |
| 105 | ) { |
| 106 | this.activeTheme = this.customThemes.get(this.activeTheme.name)!; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Sets the active theme. |
no test coverage detected