Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MainUI] Expose UI command handling to native wrappers #2622

Merged
merged 5 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions bundles/org.openhab.ui/web/src/components/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,19 @@ export default {

// special treatment for this option because it's needed to configure the app initialization
this.themeOptions.pageTransitionAnimation = localStorage.getItem('openhab.ui:theme.pagetransition') || 'default'
// tell the app to go fullscreen (if the OHApp is supported)
if (window.OHApp && typeof window.OHApp.goFullscreen === 'function') {
try {
window.OHApp.goFullscreen()
} catch {}

// load 2-way communication for native wrappers
if (window.OHApp) {
// tell the app to go fullscreen (if the OHApp is supported)
if (typeof window.OHApp.goFullscreen === 'function') {
try {
window.OHApp.goFullscreen()
} catch {}
// expose external calls
window.MainUI = {
handleCommand: this.handleCommand
}
}
}

const refreshToken = this.getRefreshToken()
Expand Down
128 changes: 66 additions & 62 deletions bundles/org.openhab.ui/web/src/components/sse-events-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,68 +36,7 @@ export default {
break
case topicCommand:
const payload = JSON.parse(event.payload)
const [command, ...segments] = payload.value.trim().split(':') // NOT use a RegEx lookbehind assertions here, because they are unsupported on Safari < 16.4, i.e. iOS 15.x
const combined = segments.join(':')
switch (command) {
case 'navigate':
this.$f7.views.main.router.navigate(combined)
break
case 'popup':
case 'popover':
case 'sheet':
if (combined.indexOf('page:') !== 0 && combined.indexOf('widget:') !== 0 && combined.indexOf('oh-') !== 0) {
console.error('Action target is not of the format page:uid or widget:uid or oh-')
return
}
console.debug(`Opening ${combined} in ${command} modal`)
let modalRoute = {
url: combined + '/' + command,
route: {
}
}
if (command === 'popup') modalRoute.route.popup = { component: OhPopup }
if (command === 'popover') modalRoute.route.popup = { component: OhPopover }
if (command === 'sheet') modalRoute.route.popup = { component: OhSheet }
let modalProps = {
props: {
uid: combined,
modalParams: {}
}
}
this.closePopups()
this.$f7.views.main.router.navigate(modalRoute, modalProps)
break
case 'close':
this.closePopups()
break
case 'back':
this.$f7.views.main.router.back()
break
case 'reload':
window.location.reload()
break
case 'notification':
const payload = {
text: segments[0],
closeButton: true,
swipeToClose: true,
closeTimeout: 5000
}
if (segments.length > 1) {
payload.title = segments[1]
}
if (segments.length > 2) {
payload.subtitle = segments[2]
}
if (segments.length > 3) {
payload.titleRightText = segments[3]
}
if (segments.length > 4) {
payload.closeTimeout = parseInt(segments[4])
}
this.$f7.notification.create(payload).open()
break
}
this.handleCommand(payload.value)
break
}
})
Expand Down Expand Up @@ -164,6 +103,71 @@ export default {
if (sheetEl) {
this.$f7.sheet.close(sheetEl)
}
},
handleCommand (commandString) {
console.log('Handling command: ' + commandString)
const [command, ...segments] = commandString.trim().split(':') // NOT use a RegEx lookbehind assertions here, because they are unsupported on Safari < 16.4, i.e. iOS 15.x
const combined = segments.join(':')
switch (command) {
case 'navigate':
this.$f7.views.main.router.navigate(combined)
break
case 'popup':
case 'popover':
case 'sheet':
if (combined.indexOf('page:') !== 0 && combined.indexOf('widget:') !== 0 && combined.indexOf('oh-') !== 0) {
console.error('Action target is not of the format page:uid or widget:uid or oh-')
return
}
console.debug(`Opening ${combined} in ${command} modal`)
const modalRoute = {
url: combined + '/' + command,
route: {
}
}
if (command === 'popup') modalRoute.route.popup = { component: OhPopup }
if (command === 'popover') modalRoute.route.popup = { component: OhPopover }
if (command === 'sheet') modalRoute.route.popup = { component: OhSheet }
const modalProps = {
props: {
uid: combined,
modalParams: {}
}
}
this.closePopups()
this.$f7.views.main.router.navigate(modalRoute, modalProps)
break
case 'close':
this.closePopups()
break
case 'back':
this.$f7.views.main.router.back()
break
case 'reload':
window.location.reload()
break
case 'notification':
const payload = {
text: segments[0],
closeButton: true,
swipeToClose: true,
closeTimeout: 5000
}
if (segments.length > 1) {
payload.title = segments[1]
}
if (segments.length > 2) {
payload.subtitle = segments[2]
}
if (segments.length > 3) {
payload.titleRightText = segments[3]
}
if (segments.length > 4) {
payload.closeTimeout = parseInt(segments[4])
}
this.$f7.notification.create(payload).open()
break
}
}
}
}