@@ -41,20 +41,26 @@ const restApi = require(`../src-shared/rest-api.js`)
41
41
const observable = require('./util/observable.js')
42
42
const dbEnum = require(`../src-shared/db-enum.js`)
43
43
const storage = require('./util/storage.js')
44
+ const querystring = require('querystring')
44
45
45
- window.addEventListener('message', (event) => {
46
+ window.addEventListener(
47
+ 'message',
48
+ (event) => {
46
49
const eventData = event?.data?.eventData
47
50
switch (event?.data?.eventId) {
48
51
case 'theme':
49
- window[rendApi.GLOBAL_SYMBOL_EXECUTE](rendApi.id.setDarkTheme, eventData.theme === 'dark')
52
+ window[rendApi.GLOBAL_SYMBOL_EXECUTE](
53
+ rendApi.id.setDarkTheme,
54
+ eventData.theme === 'dark'
55
+ )
50
56
break
51
57
case 'save':
52
58
if (eventData.shouldSave) {
53
59
window[rendApi.GLOBAL_SYMBOL_EXECUTE](rendApi.id.save)
54
60
}
55
61
break
56
62
}
57
- },
63
+ },
58
64
false
59
65
)
60
66
@@ -136,6 +142,45 @@ export default defineComponent({
136
142
},
137
143
},
138
144
methods: {
145
+ parseQueryString() {
146
+ let search = window.location.search
147
+
148
+ if (search[0] === '?') {
149
+ search = search.substring(1)
150
+ }
151
+ this.query = querystring.parse(search)
152
+ },
153
+
154
+ setSessionUuid() {
155
+ if (window.sessionStorage.getItem('session_uuid') == null) {
156
+ window.sessionStorage.setItem('session_uuid', uuidv4())
157
+ }
158
+ if (this.query[`stsApplicationId`]) {
159
+ let currentSessionUuid =
160
+ window.sessionStorage.getItem('session_uuid') || ''
161
+ let updatedSessionUuid =
162
+ this.query[`stsApplicationId`] + currentSessionUuid
163
+ window.sessionStorage.setItem('session_uuid', updatedSessionUuid)
164
+ }
165
+ },
166
+
167
+ setTheme() {
168
+ window[rendApi.GLOBAL_SYMBOL_EXECUTE](
169
+ rendApi.id.setDarkTheme,
170
+ storage.getItem(rendApi.storageKey.isDarkThemeActive)
171
+ )
172
+ },
173
+
174
+ routePage() {
175
+ if (window.location.hash == '#/preferences/about') {
176
+ this.$router.push({ path: '/preferences/about' })
177
+ } else if (this.isZapConfigSelected != true) {
178
+ this.$router.push({ path: '/config' })
179
+ } else {
180
+ this.$router.push({ path: '/' })
181
+ this.getAppData()
182
+ }
183
+ },
139
184
setGenerationInProgress(progressMessage) {
140
185
if (progressMessage != null && progressMessage.length > 0) {
141
186
this.$q.loading.show({
@@ -168,7 +213,6 @@ export default defineComponent({
168
213
}
169
214
170
215
// Parse the query string into the front end.
171
- const querystring = require('querystring')
172
216
let search = window.location.search
173
217
174
218
if (search[0] === '?') {
@@ -231,12 +275,9 @@ export default defineComponent({
231
275
}
232
276
)
233
277
234
- this.$onWebSocket(
235
- dbEnum.wsCategory.dirtyFlag,
236
- (resp) => {
237
- this.$store.dispatch('zap/setDirtyState', resp)
238
- }
239
- )
278
+ this.$onWebSocket(dbEnum.wsCategory.dirtyFlag, (resp) => {
279
+ this.$store.dispatch('zap/setDirtyState', resp)
280
+ })
240
281
},
241
282
addClassToBody() {
242
283
if (this.uiThemeCategory === 'zigbee') {
@@ -249,28 +290,22 @@ export default defineComponent({
249
290
},
250
291
},
251
292
created() {
252
- window[rendApi.GLOBAL_SYMBOL_EXECUTE](
253
- rendApi.id.setDarkTheme,
254
- storage.getItem(rendApi.storageKey.isDarkThemeActive)
255
- )
256
- if (window.location.hash == '#/preferences/about') {
257
- this.$router.push({ path: '/preferences/about' })
258
- } else if (this.isZapConfigSelected != true) {
259
- this.$router.push({ path: '/config' })
260
- } else {
261
- this.$router.push({ path: '/' })
262
- this.getAppData()
263
- }
293
+ this.parseQueryString()
294
+ this.setSessionUuid()
295
+ this.setTheme()
296
+ this.routePage()
264
297
},
265
298
mounted() {
266
299
this.addClassToBody()
267
- window?.parent?.postMessage({
300
+ window?.parent?.postMessage(
301
+ {
268
302
eventId: 'mounted',
269
303
eventData: {
270
- hasMounted: true
271
- }
304
+ hasMounted: true,
305
+ },
272
306
},
273
- '*')
307
+ '*'
308
+ )
274
309
},
275
310
unmounted() {
276
311
if (this.uiThemeCategory === 'zigbee') {
0 commit comments