From c25a4046983ef80409cbc4546f944231e8655604 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 19 Feb 2024 16:20:34 +0100 Subject: [PATCH] refactor(ui): revert wrongly introduced code to handle multiples UI Server MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- ui/web/src/composables/UIClient.ts | 15 +++++---------- ui/web/src/main.ts | 5 +---- ui/web/src/types/ConfigurationType.ts | 2 +- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/ui/web/src/composables/UIClient.ts b/ui/web/src/composables/UIClient.ts index e2266855..9a692041 100644 --- a/ui/web/src/composables/UIClient.ts +++ b/ui/web/src/composables/UIClient.ts @@ -16,7 +16,7 @@ type ResponseHandler = { } export class UIClient { - private static readonly instances: Map = new Map() + private static instance: UIClient | null = null private ws!: WebSocket private responseHandlers: Map @@ -26,16 +26,11 @@ export class UIClient { this.responseHandlers = new Map() } - public static getInstance( - serverId: number, - uiServerConfiguration?: UIServerConfigurationSection - ): UIClient { - if (!UIClient.instances.has(serverId) && uiServerConfiguration != null) { - UIClient.instances.set(serverId, new UIClient(uiServerConfiguration)) - } else if (!UIClient.instances.has(serverId)) { - throw new Error(`UI client instance not found for server id: ${serverId}`) + public static getInstance(uiServerConfiguration: UIServerConfigurationSection): UIClient { + if (UIClient.instance === null) { + UIClient.instance = new UIClient(uiServerConfiguration) } - return UIClient.instances.get(serverId)! + return UIClient.instance } public registerWSEventListener( diff --git a/ui/web/src/main.ts b/ui/web/src/main.ts index ddef6f36..97f0167a 100644 --- a/ui/web/src/main.ts +++ b/ui/web/src/main.ts @@ -14,10 +14,7 @@ const initializeApp = (config: ConfigurationData) => { console.info('Error info:', info) // TODO: add code for UI notifications or other error handling logic } - if (Array.isArray(config.uiServer)) { - throw new Error('Multiple UI server configurations is not yet supported') - } - app.config.globalProperties.$uiClient = UIClient.getInstance(0, config.uiServer) + app.config.globalProperties.$uiClient = UIClient.getInstance(config.uiServer) app.config.globalProperties.$uiClient.registerWSEventListener('open', () => { app.config.globalProperties.$uiClient .listChargingStations() diff --git a/ui/web/src/types/ConfigurationType.ts b/ui/web/src/types/ConfigurationType.ts index 51bd2138..5d0f7679 100644 --- a/ui/web/src/types/ConfigurationType.ts +++ b/ui/web/src/types/ConfigurationType.ts @@ -1,7 +1,7 @@ import type { AuthenticationType, Protocol, ProtocolVersion } from './UIProtocol' export type ConfigurationData = { - uiServer: UIServerConfigurationSection | UIServerConfigurationSection[] + uiServer: UIServerConfigurationSection } export type UIServerConfigurationSection = { -- 2.34.1