0e79968462d64a39b87bd39afc86d0b3feaea48a
1 import { type App
as AppType
, createApp
} from
'vue'
2 import ToastPlugin from
'vue-toast-notification'
3 import type { ConfigurationData
, ResponsePayload
} from
'@/types'
4 import { router
} from
'@/router'
5 import { UIClient
, getFromLocalStorage
, setToLocalStorage
} from
'@/composables'
6 import App from
'@/App.vue'
7 import 'vue-toast-notification/dist/theme-bootstrap.css'
9 const app
= createApp(App
)
11 const initializeApp
= (app
: AppType
, config
: ConfigurationData
) => {
12 app
.config
.errorHandler
= (error
, instance
, info
) => {
13 console
.error('Error:', error
)
14 console
.info('Vue instance:', instance
)
15 console
.info('Error info:', info
)
16 // TODO: add code for UI notifications or other error handling logic
18 if (!Array.isArray(config
.uiServer
)) {
19 config
.uiServer
= [config
.uiServer
]
21 if (app
.config
.globalProperties
.$configuration
== null) {
22 app
.config
.globalProperties
.$configuration
= config
24 if (!Array.isArray(app
.config
.globalProperties
.$chargingStations
)) {
25 app
.config
.globalProperties
.$chargingStations
= []
28 getFromLocalStorage
<number | undefined>('uiServerConfigurationIndex', undefined) == null ||
29 getFromLocalStorage
<number>('uiServerConfigurationIndex', 0) >
30 app
.config
.globalProperties
.$configuration
.uiServer
.length
- 1
32 setToLocalStorage
<number>('uiServerConfigurationIndex', 0)
34 if (app
.config
.globalProperties
.$uiClient
== null) {
35 app
.config
.globalProperties
.$uiClient
= UIClient
.getInstance(
36 app
.config
.globalProperties
.$configuration
.uiServer
[
37 getFromLocalStorage
<number>('uiServerConfigurationIndex', 0)
40 app
.config
.globalProperties
.$uiClient
.registerWSEventListener(
43 app
.config
.globalProperties
.$uiClient
44 .listChargingStations()
45 .then((response
: ResponsePayload
) => {
46 app
.config
.globalProperties
.$chargingStations
= response
.chargingStations
48 .catch((error
: Error) => {
49 // TODO: add code for UI notifications or other error handling logic
50 console
.error('Error at fetching charging stations:', error
)
53 app
.use(router
).use(ToastPlugin
).mount('#app')
64 // TODO: add code for UI notifications or other error handling logic
65 console
.error('Failed to fetch app configuration')
72 initializeApp(app
, config
)
74 // TODO: add code for UI notifications or other error handling logic
75 console
.error('Error at initializing app:', error
)
79 // TODO: add code for UI notifications or other error handling logic
80 console
.error('Error at deserializing JSON app configuration:', error
)
84 // TODO: add code for UI notifications or other error handling logic
85 console
.error('Error at fetching app configuration:', error
)