From e08cdd6e169a488825de9d22b8751214148128bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20Favr=C3=A9aux?= Date: Wed, 25 Sep 2024 11:55:43 +0200 Subject: [PATCH] Always translate home into meta+enter Meta+enter is always a valid shortcut to the physical home button, so there is no need for differentiating between desktop+saas and paas. Note the proper fix would be sending HOMEPAGE and map it to HOME, but this would require adding the mapping to webrtcd, so we went the easier route instead. --- README.md | 8 -------- index.d.ts | 1 - src/DeviceRenderer.js | 2 +- src/DeviceRendererFactory.js | 2 -- src/plugins/ButtonsEvents.js | 20 +++++++++++--------- tests/unit/buttonsevent.test.js | 27 +-------------------------- 6 files changed, 13 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 6a9b9320..461d4e05 100644 --- a/README.md +++ b/README.md @@ -598,14 +598,6 @@ Enables or disables the phone widget. This widget can be used to send SMS or pho - **Details:** Enable or disable fingerprints widget. This widget can be used to manage fingerprint reading requests. Available for Android 9 and above -### `translateHomeKey` - -- **Type:** `Boolean` -- **Default:** `false` -- **Compatibility:** `PaaS` -- **Details:** - Translate home key to `META` + `ENTER` - ### `connectionFailedURL` - **Type:** `String` diff --git a/index.d.ts b/index.d.ts index 315d89aa..3e87e5bb 100644 --- a/index.d.ts +++ b/index.d.ts @@ -116,7 +116,6 @@ interface RendererSetupOptions { template?: Template; // Default: 'renderer' token?: string; touch?: boolean; // Default: true - translateHomeKey?: boolean; // Default: false turn?: { urls?: string[]; username?: string; diff --git a/src/DeviceRenderer.js b/src/DeviceRenderer.js index e106ea49..8810f334 100644 --- a/src/DeviceRenderer.js +++ b/src/DeviceRenderer.js @@ -124,7 +124,7 @@ module.exports = class DeviceRenderer { { enabled: this.options.buttons, class: ButtonsEvents, - params: [this.options.i18n, this.options.translateHomeKey], + params: [this.options.i18n], }, ]; diff --git a/src/DeviceRendererFactory.js b/src/DeviceRendererFactory.js index 8f316744..47d75f54 100644 --- a/src/DeviceRendererFactory.js +++ b/src/DeviceRendererFactory.js @@ -43,7 +43,6 @@ const defaultOptions = { diskIO: true, gamepad: true, biometrics: true, - translateHomeKey: false, token: '', i18n: {}, stun: { @@ -108,7 +107,6 @@ module.exports = class DeviceRendererFactory { * @param {boolean} options.streamResolution Stream resolution control support activated. Default: true. * @param {boolean} options.diskIO Disk I/O throttling support activated. Default: true. * @param {boolean} options.gamepad Experimental gamepad support activated. Default: false. - * @param {boolean} options.translateHomeKey Whether or not the HOME key button should be decompose to META + ENTER. Default: false. * @param {string} options.token Instance access token (JWT). Default: ''. * @param {Object} options.i18n Translations keys for the UI. Default: {}. * @param {Object} options.stun WebRTC STUN servers configuration. diff --git a/src/plugins/ButtonsEvents.js b/src/plugins/ButtonsEvents.js index 95a733f4..a96103b7 100644 --- a/src/plugins/ButtonsEvents.js +++ b/src/plugins/ButtonsEvents.js @@ -5,7 +5,7 @@ const ENTER_KEYCODE = '0x01000005'; const VOLUME_DOWN_KEYCODE = '0x01000070'; const VOLUME_UP_KEYCODE = '0x01000072'; const RECENT_APP_KEYCODE = '0x010000be'; -const HOME_KEYCODE = '0x01000010'; +const HOMEPAGE_KEYCODE = '0x01000090'; const BACK_KEYCODE = '0x01000061'; const POWER_KEYCODE = '0x0100010b'; const ROTATE_KEYCODE = 'gm-rotation'; @@ -20,12 +20,10 @@ module.exports = class ButtonsEvents { * * @param {Object} instance Associated instance. * @param {Object} i18n Translations keys for the UI. - * @param {Object} translateHomeKey Translate HOME key press for the instance. */ - constructor(instance, i18n, translateHomeKey) { + constructor(instance, i18n) { // Reference instance this.instance = instance; - this.translateHomeKey = translateHomeKey; // Register plugin this.instance.buttonsEvents = this; @@ -51,7 +49,7 @@ module.exports = class ButtonsEvents { i18n.BUTTONS_RECENT_APPS || 'Recent applications', true, ); - this.renderToolbarButton(HOME_KEYCODE, 'gm-home', i18n.BUTTONS_HOME || 'Home', true); + this.renderToolbarButton(HOMEPAGE_KEYCODE, 'gm-home', i18n.BUTTONS_HOME || 'Home', true); this.renderToolbarButton(BACK_KEYCODE, 'gm-back', i18n.BUTTONS_BACK || 'Back', true); } @@ -103,8 +101,12 @@ module.exports = class ButtonsEvents { return; } - if (id === HOME_KEYCODE && this.translateHomeKey) { - // home is meta + enter + if (id === HOMEPAGE_KEYCODE) { + /** + * Translate homepage into meta + enter + * Note we could send the homepage keycode directly, see https://source.android.com/docs/core/interaction/input/keyboard-devices#hid-keyboard-and-keypad-page-0x07 + * but geny's webrtcd doesn't know how to map it yet. + */ this.keyPressEvent(parseInt(META_KEYCODE), ''); this.keyPressEvent(parseInt(ENTER_KEYCODE), ''); } else if (id.substring(0, 2) === '0x') { @@ -126,8 +128,8 @@ module.exports = class ButtonsEvents { return; } - if (id === HOME_KEYCODE && this.translateHomeKey) { - // "home" is "meta + enter" on PaaS, "move_home" on SaaS + if (id === HOMEPAGE_KEYCODE) { + // Translate homepage into meta + enter this.keyReleaseEvent(parseInt(ENTER_KEYCODE), ''); this.keyReleaseEvent(parseInt(META_KEYCODE), ''); } else if (id === ROTATE_KEYCODE) { diff --git a/tests/unit/buttonsevent.test.js b/tests/unit/buttonsevent.test.js index fff5c2b3..4ce568ca 100644 --- a/tests/unit/buttonsevent.test.js +++ b/tests/unit/buttonsevent.test.js @@ -174,34 +174,9 @@ describe('ButtonsEvents Plugin', () => { }); }); - test('home - default', () => { + test('home', () => { const button = document.getElementsByClassName('gm-home')[0]; - button.dispatchEvent(new Event('mousedown')); - expect(sendEventSpy).toHaveBeenCalledTimes(1); - expect(instance.outgoingMessages[0]).toEqual({ - type: 'KEYBOARD_PRESS', - keycode: parseInt('0x01000010'), - keychar: '0\n', - }); - - button.dispatchEvent(new Event('mouseup')); - expect(sendEventSpy).toHaveBeenCalledTimes(2); - expect(instance.outgoingMessages[1]).toEqual({ - type: 'KEYBOARD_RELEASE', - keycode: parseInt('0x01000010'), - keychar: '0\n', - }); - }); - - test('home - translated', () => { - instance = new Instance({ - navbar: true, - }); - new ButtonsEvents(instance, {}, true); - const button = document.getElementsByClassName('gm-home')[0]; - sendEventSpy = jest.spyOn(instance, 'sendEvent'); - button.dispatchEvent(new Event('mousedown')); expect(sendEventSpy).toHaveBeenCalledTimes(2); expect(instance.outgoingMessages[0]).toEqual({