Commit | Line | Data |
---|---|---|
66a7748d | 1 | import { createApp } from 'vue' |
cea23fa0 | 2 | import ToastPlugin from 'vue-toast-notification' |
57c0ba05 | 3 | import type { ConfigurationData, ResponsePayload } from './types' |
13c19b7b | 4 | import { router } from '@/router' |
9d76f5ec JB |
5 | import { UIClient } from '@/composables' |
6 | import App from '@/App.vue' | |
cea23fa0 | 7 | import 'vue-toast-notification/dist/theme-default.css' |
32de5a57 | 8 | |
57c0ba05 | 9 | const initializeApp = (config: ConfigurationData) => { |
a64b9a64 JB |
10 | const app = createApp(App) |
11 | app.config.errorHandler = (error, instance, info) => { | |
12 | console.error('Error:', error) | |
13 | console.info('Vue instance:', instance) | |
14 | console.info('Error info:', info) | |
c317ae3e | 15 | // TODO: add code for UI notifications or other error handling logic |
a64b9a64 | 16 | } |
f292861c JB |
17 | if (Array.isArray(config.uiServer)) { |
18 | throw new Error('Multiple UI server configurations is not yet supported') | |
19 | } | |
20 | app.config.globalProperties.$uiClient = UIClient.getInstance(0, config.uiServer) | |
ca1e5439 | 21 | app.config.globalProperties.$uiClient.registerWSEventListener('open', () => { |
57c0ba05 JB |
22 | app.config.globalProperties.$uiClient |
23 | .listChargingStations() | |
24 | .then((response: ResponsePayload) => { | |
25 | app.config.globalProperties.$chargingStations = response.chargingStations | |
26 | }) | |
27 | .catch((error: Error) => { | |
c317ae3e | 28 | // TODO: add code for UI notifications or other error handling logic |
57c0ba05 JB |
29 | console.error('Error at fetching charging stations:', error) |
30 | throw error | |
31 | }) | |
32 | .finally(() => { | |
cea23fa0 | 33 | app.use(router).use(ToastPlugin).mount('#app') |
57c0ba05 JB |
34 | }) |
35 | }) | |
a64b9a64 | 36 | } |
9d76f5ec JB |
37 | |
38 | fetch('/config.json') | |
39 | .then(response => response.json()) | |
a64b9a64 JB |
40 | .catch(error => { |
41 | console.error('Error at fetching app configuration:', error) | |
42 | throw error | |
43 | }) | |
9d76f5ec | 44 | .then(config => { |
a64b9a64 JB |
45 | initializeApp(config) |
46 | }) | |
47 | .catch(error => { | |
48 | console.error('Error at initializing app:', error) | |
9e1d6e03 | 49 | throw error |
9d76f5ec | 50 | }) |