From: Jérôme Benoit Date: Wed, 18 Mar 2026 23:23:29 +0000 (+0100) Subject: feat(ui): add configurable theme support X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9e90933044fa4dc28d51efb4701a2fc90290db91;p=e-mobility-charging-stations-simulator.git feat(ui): add configurable theme support Add theme field to ConfigurationData. Theme CSS files are loaded dynamically from assets/themes/ at startup. Falls back to tokyo-night-storm when not configured or theme not found. Move theme.css to assets/themes/tokyo-night-storm.css. --- diff --git a/ui/web/src/assets/config-template.json b/ui/web/src/assets/config-template.json index 1542583a..2fc411e1 100644 --- a/ui/web/src/assets/config-template.json +++ b/ui/web/src/assets/config-template.json @@ -1,4 +1,5 @@ { + "theme": "tokyo-night-storm", "uiServer": { "host": "localhost", "port": 8080, diff --git a/ui/web/src/assets/theme.css b/ui/web/src/assets/themes/tokyo-night-storm.css similarity index 100% rename from ui/web/src/assets/theme.css rename to ui/web/src/assets/themes/tokyo-night-storm.css diff --git a/ui/web/src/main.ts b/ui/web/src/main.ts index d40f9a25..6a22da45 100644 --- a/ui/web/src/main.ts +++ b/ui/web/src/main.ts @@ -9,11 +9,21 @@ import { router } from '@/router' import 'vue-toast-notification/dist/theme-bootstrap.css' -import '@/assets/theme.css' +const DEFAULT_THEME = 'tokyo-night-storm' + +const loadTheme = async (theme: string): Promise => { + try { + await import(`./assets/themes/${theme}.css`) + } catch { + console.error(`Theme '${theme}' not found, falling back to '${DEFAULT_THEME}'`) + await import(`./assets/themes/${DEFAULT_THEME}.css`) + } +} const app = createApp(App as Component) -const initializeApp = (app: AppType, config: ConfigurationData) => { +const initializeApp = async (app: AppType, config: ConfigurationData): Promise => { + await loadTheme(config.theme ?? DEFAULT_THEME) app.config.errorHandler = (error, instance, info) => { console.error('Error:', error) console.info('Vue instance:', instance) @@ -57,8 +67,8 @@ fetch('/config.json') response .json() // eslint-disable-next-line promise/no-nesting - .then(config => { - initializeApp(app, config as ConfigurationData) + .then(async config => { + await initializeApp(app, config as ConfigurationData) return undefined }) // eslint-disable-next-line promise/no-nesting diff --git a/ui/web/src/types/ConfigurationType.ts b/ui/web/src/types/ConfigurationType.ts index 40586918..b76fc240 100644 --- a/ui/web/src/types/ConfigurationType.ts +++ b/ui/web/src/types/ConfigurationType.ts @@ -1,6 +1,7 @@ import type { AuthenticationType, Protocol, ProtocolVersion } from './UIProtocol' export interface ConfigurationData { + theme?: string uiServer: UIServerConfigurationSection | UIServerConfigurationSection[] }