1 import type { ChargingStationData
, ConfigurationData
, UIServerConfigurationSection
} from
'@/types'
3 import App from
'@/App.vue'
4 import { getFromLocalStorage
, setToLocalStorage
, UIClient
} from
'@/composables'
5 import { router
} from
'@/router'
6 import { type App
as AppType
, type Component
, createApp
, ref
} from
'vue'
7 import ToastPlugin from
'vue-toast-notification'
8 import 'vue-toast-notification/dist/theme-bootstrap.css'
10 const app
= createApp(App
as Component
)
12 const initializeApp
= (app
: AppType
, config
: ConfigurationData
) => {
13 app
.config
.errorHandler
= (error
, instance
, info
) => {
14 console
.error('Error:', error
)
15 console
.info('Vue instance:', instance
)
16 console
.info('Error info:', info
)
17 // TODO: add code for UI notifications or other error handling logic
19 if (!Array.isArray(config
.uiServer
)) {
20 config
.uiServer
= [config
.uiServer
]
22 if (app
.config
.globalProperties
.$configuration
== null) {
23 app
.config
.globalProperties
.$configuration
= ref
<ConfigurationData
>(config
)
25 if (!Array.isArray(app
.config
.globalProperties
.$templates
?.value
)) {
26 app
.config
.globalProperties
.$templates
= ref
<string[]>([])
28 if (!Array.isArray(app
.config
.globalProperties
.$chargingStations
?.value
)) {
29 app
.config
.globalProperties
.$chargingStations
= ref
<ChargingStationData
[]>([])
32 getFromLocalStorage
<number | undefined>('uiServerConfigurationIndex', undefined) == null ||
33 getFromLocalStorage
<number>('uiServerConfigurationIndex', 0) >
34 (app
.config
.globalProperties
.$configuration
.value
.uiServer
as UIServerConfigurationSection
[])
38 setToLocalStorage
<number>('uiServerConfigurationIndex', 0)
40 if (app
.config
.globalProperties
.$uiClient
== null) {
41 app
.config
.globalProperties
.$uiClient
= UIClient
.getInstance(
42 (app
.config
.globalProperties
.$configuration
.value
.uiServer
as UIServerConfigurationSection
[])[
43 getFromLocalStorage
<number>('uiServerConfigurationIndex', 0)
47 app
.use(router
).use(ToastPlugin
).mount('#app')
53 // TODO: add code for UI notifications or other error handling logic
54 console
.error('Failed to fetch app configuration')
59 // eslint-disable-next-line promise/no-nesting
61 initializeApp(app
, config
as ConfigurationData
)
64 // eslint-disable-next-line promise/no-nesting
65 .catch((error
: unknown
) => {
66 // TODO: add code for UI notifications or other error handling logic
67 console
.error('Error at deserializing JSON app configuration:', error
)
71 .catch((error
: unknown
) => {
72 // TODO: add code for UI notifications or other error handling logic
73 console
.error('Error at fetching app configuration:', error
)