Skip to content

Commit

Permalink
Studio V6 Integration (#1288)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
paulr34 authored Apr 9, 2024
1 parent 61d328c commit 0af7250
Showing 1 changed file with 61 additions and 26 deletions.
87 changes: 61 additions & 26 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,26 @@ const restApi = require(`../src-shared/rest-api.js`)
const observable = require('./util/observable.js')
const dbEnum = require(`../src-shared/db-enum.js`)
const storage = require('./util/storage.js')
const querystring = require('querystring')

window.addEventListener('message', (event) => {
window.addEventListener(
'message',
(event) => {
const eventData = event?.data?.eventData
switch (event?.data?.eventId) {
case 'theme':
window[rendApi.GLOBAL_SYMBOL_EXECUTE](rendApi.id.setDarkTheme, eventData.theme === 'dark')
window[rendApi.GLOBAL_SYMBOL_EXECUTE](
rendApi.id.setDarkTheme,
eventData.theme === 'dark'
)
break
case 'save':
if (eventData.shouldSave) {
window[rendApi.GLOBAL_SYMBOL_EXECUTE](rendApi.id.save)
}
break
}
},
},
false
)

Expand Down Expand Up @@ -136,6 +142,45 @@ export default defineComponent({
},
},
methods: {
parseQueryString() {
let search = window.location.search

if (search[0] === '?') {
search = search.substring(1)
}
this.query = querystring.parse(search)
},

setSessionUuid() {
if (window.sessionStorage.getItem('session_uuid') == null) {
window.sessionStorage.setItem('session_uuid', uuidv4())
}
if (this.query[`stsApplicationId`]) {
let currentSessionUuid =
window.sessionStorage.getItem('session_uuid') || ''
let updatedSessionUuid =
this.query[`stsApplicationId`] + currentSessionUuid
window.sessionStorage.setItem('session_uuid', updatedSessionUuid)
}
},

setTheme() {
window[rendApi.GLOBAL_SYMBOL_EXECUTE](
rendApi.id.setDarkTheme,
storage.getItem(rendApi.storageKey.isDarkThemeActive)
)
},

routePage() {
if (window.location.hash == '#/preferences/about') {
this.$router.push({ path: '/preferences/about' })
} else if (this.isZapConfigSelected != true) {
this.$router.push({ path: '/config' })
} else {
this.$router.push({ path: '/' })
this.getAppData()
}
},
setGenerationInProgress(progressMessage) {
if (progressMessage != null && progressMessage.length > 0) {
this.$q.loading.show({
Expand Down Expand Up @@ -168,7 +213,6 @@ export default defineComponent({
}

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

if (search[0] === '?') {
Expand Down Expand Up @@ -231,12 +275,9 @@ export default defineComponent({
}
)

this.$onWebSocket(
dbEnum.wsCategory.dirtyFlag,
(resp) => {
this.$store.dispatch('zap/setDirtyState', resp)
}
)
this.$onWebSocket(dbEnum.wsCategory.dirtyFlag, (resp) => {
this.$store.dispatch('zap/setDirtyState', resp)
})
},
addClassToBody() {
if (this.uiThemeCategory === 'zigbee') {
Expand All @@ -249,28 +290,22 @@ export default defineComponent({
},
},
created() {
window[rendApi.GLOBAL_SYMBOL_EXECUTE](
rendApi.id.setDarkTheme,
storage.getItem(rendApi.storageKey.isDarkThemeActive)
)
if (window.location.hash == '#/preferences/about') {
this.$router.push({ path: '/preferences/about' })
} else if (this.isZapConfigSelected != true) {
this.$router.push({ path: '/config' })
} else {
this.$router.push({ path: '/' })
this.getAppData()
}
this.parseQueryString()
this.setSessionUuid()
this.setTheme()
this.routePage()
},
mounted() {
this.addClassToBody()
window?.parent?.postMessage({
window?.parent?.postMessage(
{
eventId: 'mounted',
eventData: {
hasMounted: true
}
hasMounted: true,
},
},
'*')
'*'
)
},
unmounted() {
if (this.uiThemeCategory === 'zigbee') {
Expand Down

0 comments on commit 0af7250

Please sign in to comment.