Skip to content

Commit 0af7250

Browse files
authored
Studio V6 Integration (#1288)
* changing session storage depending on what is given from parent iframe * add stsApplicationId as a prefix to sessio uuid * keeping session uuid code together * PR review
1 parent 61d328c commit 0af7250

File tree

1 file changed

+61
-26
lines changed

1 file changed

+61
-26
lines changed

src/App.vue

+61-26
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,26 @@ const restApi = require(`../src-shared/rest-api.js`)
4141
const observable = require('./util/observable.js')
4242
const dbEnum = require(`../src-shared/db-enum.js`)
4343
const storage = require('./util/storage.js')
44+
const querystring = require('querystring')
4445

45-
window.addEventListener('message', (event) => {
46+
window.addEventListener(
47+
'message',
48+
(event) => {
4649
const eventData = event?.data?.eventData
4750
switch (event?.data?.eventId) {
4851
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+
)
5056
break
5157
case 'save':
5258
if (eventData.shouldSave) {
5359
window[rendApi.GLOBAL_SYMBOL_EXECUTE](rendApi.id.save)
5460
}
5561
break
5662
}
57-
},
63+
},
5864
false
5965
)
6066

@@ -136,6 +142,45 @@ export default defineComponent({
136142
},
137143
},
138144
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+
},
139184
setGenerationInProgress(progressMessage) {
140185
if (progressMessage != null && progressMessage.length > 0) {
141186
this.$q.loading.show({
@@ -168,7 +213,6 @@ export default defineComponent({
168213
}
169214

170215
// Parse the query string into the front end.
171-
const querystring = require('querystring')
172216
let search = window.location.search
173217

174218
if (search[0] === '?') {
@@ -231,12 +275,9 @@ export default defineComponent({
231275
}
232276
)
233277

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+
})
240281
},
241282
addClassToBody() {
242283
if (this.uiThemeCategory === 'zigbee') {
@@ -249,28 +290,22 @@ export default defineComponent({
249290
},
250291
},
251292
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()
264297
},
265298
mounted() {
266299
this.addClassToBody()
267-
window?.parent?.postMessage({
300+
window?.parent?.postMessage(
301+
{
268302
eventId: 'mounted',
269303
eventData: {
270-
hasMounted: true
271-
}
304+
hasMounted: true,
305+
},
272306
},
273-
'*')
307+
'*'
308+
)
274309
},
275310
unmounted() {
276311
if (this.uiThemeCategory === 'zigbee') {

0 commit comments

Comments
 (0)