diff --git a/app/ui.js b/app/ui.js index 5dc6681d..c706c3eb 100644 --- a/app/ui.js +++ b/app/ui.js @@ -30,14 +30,6 @@ window.updateSetting = (name, value) => { } } -window.showKeyboardControlsPanel = () => { - document.querySelector(".keyboard-controls").classList.add("is-visible"); -} - -window.hideKeyboardControlsPanel = () => { - document.querySelector(".keyboard-controls").classList.remove("is-visible"); -} - import "core-js/stable"; import "regenerator-runtime/runtime"; import * as Log from '../core/util/logging.js'; @@ -163,13 +155,22 @@ const UI = { UI.openConnectPanel(); } - if ( !isWindows() && ( - (window.parent.KASM_INITIAL_KEYBOARD_CONTROLS_MODE === "on") || - (window.parent.KASM_INITIAL_KEYBOARD_CONTROLS_MODE === "auto" && isTouchDevice) - ) - ) { - showKeyboardControlsPanel(); - } + window.parent.postMessage({ + action: "noVNC_initialized", + value: null + }, "*"); + + window.addEventListener("message", (e) => { + if (typeof e.data !== "object" || !e.data.action) { + return; + } + + if (e.data.action === "show_keyboard_controls") { + UI.showKeyboardControls(); + } else if (e.data.action === "hide_keyboard_controls") { + UI.hideKeyboardControls(); + } + }); return Promise.resolve(UI.rfb); }, @@ -1871,6 +1872,14 @@ const UI = { UI.rfb.translateShortcuts = UI.getSetting('translate_shortcuts'); }, + showKeyboardControls() { + document.querySelector(".keyboard-controls").classList.add("is-visible"); + }, + + hideKeyboardControls() { + document.querySelector(".keyboard-controls").classList.remove("is-visible"); + }, + showVirtualKeyboard() { const input = document.getElementById('noVNC_keyboardinput'); diff --git a/core/rfb.js b/core/rfb.js index 957971df..3a081809 100644 --- a/core/rfb.js +++ b/core/rfb.js @@ -966,13 +966,14 @@ export default class RFB extends EventTargetMixin { _focusCanvas(event) { // Hack: - // On most mobile phones it's only possible to play audio - // only if it's triggered by a user action. Moreover, since it's also - // impossible to listen for touch events on child frames (only on mobile phones) - // we delegate the audio unlocking to the parent window. - if (window.parent && !window.parent.KASM_AUDIO_UNLOCKED) { - window.parent.unlockAudio && window.parent.unlockAudio(); - } + // On most mobile phones it's possible to play audio + // only if it's triggered by user action. It's also + // impossible to listen for touch events on child frames (on mobile phones) + // so we catch those events here but forward the audio unlocking to the parent window + window.parent.postMessage({ + action: "enable_audio", + value: null + }, "*"); if (!this.focusOnClick) { return;