diff --git a/bundles/org.openhab.ui/web/src/components/app.vue b/bundles/org.openhab.ui/web/src/components/app.vue index 4bc09e1b45..5d1db1d8e0 100644 --- a/bundles/org.openhab.ui/web/src/components/app.vue +++ b/bundles/org.openhab.ui/web/src/components/app.vue @@ -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() diff --git a/bundles/org.openhab.ui/web/src/components/sse-events-mixin.js b/bundles/org.openhab.ui/web/src/components/sse-events-mixin.js index 1498a91c17..a1f6a1f74d 100644 --- a/bundles/org.openhab.ui/web/src/components/sse-events-mixin.js +++ b/bundles/org.openhab.ui/web/src/components/sse-events-mixin.js @@ -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 } }) @@ -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 + } } } }