Commit | Line | Data |
---|---|---|
0344ad2b | 1 | import { type App as AppType, createApp } from 'vue' |
cea23fa0 | 2 | import ToastPlugin from 'vue-toast-notification' |
916fe456 | 3 | import type { ConfigurationData } from '@/types' |
13c19b7b | 4 | import { router } from '@/router' |
0344ad2b | 5 | import { UIClient, getFromLocalStorage, setToLocalStorage } from '@/composables' |
9d76f5ec | 6 | import App from '@/App.vue' |
dd9a3329 | 7 | import 'vue-toast-notification/dist/theme-bootstrap.css' |
32de5a57 | 8 | |
0344ad2b JB |
9 | const app = createApp(App) |
10 | ||
11 | const initializeApp = (app: AppType, config: ConfigurationData) => { | |
a64b9a64 JB |
12 | app.config.errorHandler = (error, instance, info) => { |
13 | console.error('Error:', error) | |
14 | console.info('Vue instance:', instance) | |
15 | console.info('Error info:', info) | |
c317ae3e | 16 | // TODO: add code for UI notifications or other error handling logic |
a64b9a64 | 17 | } |
0344ad2b JB |
18 | if (!Array.isArray(config.uiServer)) { |
19 | config.uiServer = [config.uiServer] | |
20 | } | |
21 | if (app.config.globalProperties.$configuration == null) { | |
22 | app.config.globalProperties.$configuration = config | |
23 | } | |
3b0c6e17 JB |
24 | if (!Array.isArray(app.config.globalProperties.$templates)) { |
25 | app.config.globalProperties.$templates = [] | |
26 | } | |
0344ad2b JB |
27 | if (!Array.isArray(app.config.globalProperties.$chargingStations)) { |
28 | app.config.globalProperties.$chargingStations = [] | |
29 | } | |
30 | if ( | |
31 | getFromLocalStorage<number | undefined>('uiServerConfigurationIndex', undefined) == null || | |
32 | getFromLocalStorage<number>('uiServerConfigurationIndex', 0) > | |
33 | app.config.globalProperties.$configuration.uiServer.length - 1 | |
34 | ) { | |
35 | setToLocalStorage<number>('uiServerConfigurationIndex', 0) | |
36 | } | |
37 | if (app.config.globalProperties.$uiClient == null) { | |
38 | app.config.globalProperties.$uiClient = UIClient.getInstance( | |
39 | app.config.globalProperties.$configuration.uiServer[ | |
40 | getFromLocalStorage<number>('uiServerConfigurationIndex', 0) | |
41 | ] | |
42 | ) | |
0344ad2b | 43 | } |
916fe456 | 44 | app.use(router).use(ToastPlugin).mount('#app') |
a64b9a64 | 45 | } |
9d76f5ec JB |
46 | |
47 | fetch('/config.json') | |
53694372 JB |
48 | .then(response => { |
49 | if (!response.ok) { | |
50 | // TODO: add code for UI notifications or other error handling logic | |
51 | console.error('Failed to fetch app configuration') | |
52 | return | |
53 | } | |
54 | response | |
55 | .json() | |
56 | .then(config => { | |
916fe456 | 57 | initializeApp(app, config) |
53694372 JB |
58 | }) |
59 | .catch(error => { | |
60 | // TODO: add code for UI notifications or other error handling logic | |
bcb671db | 61 | console.error('Error at deserializing JSON app configuration:', error) |
53694372 | 62 | }) |
a64b9a64 JB |
63 | }) |
64 | .catch(error => { | |
53694372 JB |
65 | // TODO: add code for UI notifications or other error handling logic |
66 | console.error('Error at fetching app configuration:', error) | |
9d76f5ec | 67 | }) |