Skip to content

Commit

Permalink
Merge pull request #110 from Genymobile/dev/qbi/SYSTEM-2682/always-tr…
Browse files Browse the repository at this point in the history
…anslate-home

Always translate home widget btn into meta+enter
  • Loading branch information
qbi-geny authored Sep 30, 2024
2 parents 53d2c39 + e08cdd6 commit 0958bfe
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 47 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
1 change: 0 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/DeviceRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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],
},
];

Expand Down
2 changes: 0 additions & 2 deletions src/DeviceRendererFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const defaultOptions = {
diskIO: true,
gamepad: true,
biometrics: true,
translateHomeKey: false,
token: '',
i18n: {},
stun: {
Expand Down Expand Up @@ -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.
Expand Down
20 changes: 11 additions & 9 deletions src/plugins/ButtonsEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand All @@ -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);
}

Expand Down Expand Up @@ -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') {
Expand All @@ -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) {
Expand Down
27 changes: 1 addition & 26 deletions tests/unit/buttonsevent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 0958bfe

Please sign in to comment.