Skip to content

Commit

Permalink
Merge pull request #80 from Genymobile/dev/PLAYER-19-keybinding
Browse files Browse the repository at this point in the history
[PLAYER-19] pre-keybinding refacto keyboard enable/disable and overlay
  • Loading branch information
jparez authored Jun 14, 2024
2 parents ea1781d + 5d50cd5 commit 106466b
Show file tree
Hide file tree
Showing 24 changed files with 157 additions and 259 deletions.
24 changes: 17 additions & 7 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"extends": ["eslint:recommended"],
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"plugins": ["prettier"],
"env": {
"browser": true,
"es6": true,
Expand All @@ -10,16 +11,18 @@
"ecmaVersion": 2020
},
"rules": {
// Possible errors
"no-console": "error",
"no-extra-parens": [
"prettier/prettier": [
"error",
"all",
{
"insertPragma": true,
"requirePragma": true,
"nestedBinaryExpressions": false,
"enforceForArrowConditionals": false
}
],
"comma-spacing": ["error", {"before": false, "after": true}],
"no-console": "warn",
"no-extra-parens": "off",
"no-loss-of-precision": "error",
"no-promise-executor-return": "error",
"no-template-curly-in-string": "error",
Expand Down Expand Up @@ -71,7 +74,7 @@
"multiline-comment-style": ["error", "starred-block"],
"new-cap": ["error", {"properties": false}],
"new-parens": "error",
"newline-per-chained-call": "error",
"newline-per-chained-call": "off",
"no-multi-assign": "error",
"no-multiple-empty-lines": ["error", {"max": 1}],
"no-trailing-spaces": "error",
Expand All @@ -80,7 +83,14 @@
"quotes": ["error", "single", {"avoidEscape": true}],
"semi": ["error", "always"],
"semi-style": ["error", "last"],
"space-before-function-paren": ["error", "never"],
"space-before-function-paren": [
"error",
{
"anonymous": "always",
"named": "never",
"asyncArrow": "never"
}
],
"space-in-parens": ["error", "never"],
"spaced-comment": ["error", "always"],
// ECMAScript 6
Expand Down
4 changes: 2 additions & 2 deletions gulp/graspify-squery.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const options = {
module.exports = transformTools.makeStringTransform('graspify', options, (content, opts, done) => {
try {
// Normalize plain replacements
opts.opts = opts.opts ? Array.isArray(opts.opts) ? opts.opts : [opts.opts] : [];
opts.config = opts.config ? Array.isArray(opts.config) ? opts.config : [opts.config] : [];
opts.opts = opts.opts ? (Array.isArray(opts.opts) ? opts.opts : [opts.opts]) : [];
opts.config = opts.config ? (Array.isArray(opts.config) ? opts.config : [opts.config]) : [];

// Merge opts & config for the full list of replacements an loop over
[].concat(opts.opts, opts.config).forEach((args) => {
Expand Down
2 changes: 1 addition & 1 deletion src/DeviceRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ module.exports = class DeviceRenderer {
!event.target.classList.contains('gm-icon-button') &&
!event.target.classList.contains('gm-dont-close')
) {
this.emit('close-overlays');
this.store.dispatch({type: 'OVERLAY_OPEN', payload: {toOpen: false}});
}
};
this.addListener(document, 'click', this.clickHandlerCloseOverlay);
Expand Down
21 changes: 2 additions & 19 deletions src/plugins/BasebandRIL.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,27 +224,9 @@ module.exports = class BasebandRIL extends OverlayPlugin {
this.widget.appendChild(this.form);

// Render into document
this.overlays.push(this.widget);
this.instance.root.appendChild(this.widget);
}

/**
* Display or hide the widget.
*/
toggleWidget() {
// Notify other callers
if (this.widget.classList.contains('gm-hidden')) {
this.instance.emit('close-overlays');
this.instance.emit('keyboard-disable');
} else {
this.instance.emit('keyboard-enable');
}

// Toggle display
this.widget.classList.toggle('gm-hidden');
this.toolbarBtnImage.classList.toggle('gm-active');
}

/**
* MSIN verification according to MCC/MNC length:
* - MCC/MNC is 5 digits => MSIN should be 10 digits
Expand Down Expand Up @@ -307,6 +289,7 @@ module.exports = class BasebandRIL extends OverlayPlugin {
}
}

this.toggleWidget();
// close the widget
this.instance.store.dispatch({type: 'OVERLAY_OPEN', payload: {overlayID: this.overlayID, toOpen: false}});
}
};
15 changes: 0 additions & 15 deletions src/plugins/Battery.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ module.exports = class Battery extends OverlayPlugin {
this.widget.appendChild(close);
this.widget.appendChild(this.container);

// Render into document
this.overlays.push(this.widget);
this.instance.root.appendChild(this.widget);
}

Expand Down Expand Up @@ -190,19 +188,6 @@ module.exports = class Battery extends OverlayPlugin {
/**
* Display or hide the widget.
*/
toggleWidget() {
// Notify other callers
if (this.widget.classList.contains('gm-hidden')) {
this.instance.emit('close-overlays');
this.instance.emit('keyboard-disable');
} else {
this.instance.emit('keyboard-enable');
}

// Toggle display
this.widget.classList.toggle('gm-hidden');
this.toolbarBtnImage.classList.toggle('gm-active');
}

/**
* Toggle Instance charging status between 'charging' and 'discharging';
Expand Down
14 changes: 2 additions & 12 deletions src/plugins/Clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,27 +107,17 @@ module.exports = class Clipboard extends OverlayPlugin {
};

// Render into document
this.overlays.push(this.widget);
this.instance.root.appendChild(this.widget);
}

/**
* Display or hide the widget.
*/
toggleWidget() {
// Notify other callers
if (this.widget.classList.contains('gm-hidden')) {
this.instance.emit('close-overlays');
this.instance.emit('keyboard-disable');
super.toggleWidget();
if (this.instance.store.getters.isWidgetOpened(this.overlayID)) {
this.clipboardInput.value = this.clipboard;
} else {
this.instance.emit('keyboard-enable');
this.widget.onclose();
}

// Toggle display
this.widget.classList.toggle('gm-hidden');
this.toolbarBtnImage.classList.toggle('gm-active');
}

/**
Expand Down
17 changes: 5 additions & 12 deletions src/plugins/FileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,16 @@ module.exports = class FileUpload extends OverlayPlugin {
this.widget.appendChild(this.container);

// Render into document
this.overlays.push(this.widget);
this.instance.root.appendChild(this.widget);
}

/**
* Display or hide the widget.
*/
toggleWidget() {
// Notify other callers
if (this.widget.classList.contains('gm-hidden')) {
this.instance.emit('close-overlays');
this.instance.emit('keyboard-disable');
super.toggleWidget();

if (this.instance.store.getters.isWidgetOpened(this.overlayID)) {
this.displayStep(this.currentStep);
// Force refresh upload screen content. Otherwise, installing status may not appear.
if (this.currentStep === 'uploadScreen') {
Expand All @@ -189,12 +187,7 @@ module.exports = class FileUpload extends OverlayPlugin {
if (this.currentStep === 'successScreen' || this.currentStep === 'errorScreen') {
this.currentStep = 'homeScreen';
}
this.instance.emit('keyboard-enable');
}

// Toggle display
this.widget.classList.toggle('gm-hidden');
this.toolbarBtnImage.classList.toggle('gm-active');
}

/**
Expand Down Expand Up @@ -309,7 +302,7 @@ module.exports = class FileUpload extends OverlayPlugin {
case 'success':
this.displayStep('successScreen');
// On flashing success, force display success screen
if (this.flashing && this.widget.classList.contains('gm-hidden')) {
if (this.flashing && !this.instance.store.getters.isWidgetOpened(this.overlayID)) {
this.toggleWidget();
}
this.flashing = false;
Expand All @@ -320,7 +313,7 @@ module.exports = class FileUpload extends OverlayPlugin {
case 'install_error':
this.displayStep('errorScreen');
// On flashing error, force display errorscreen
if (this.flashing && this.widget.classList.contains('gm-hidden')) {
if (this.flashing && !this.instance.store.getters.isWidgetOpened(this.overlayID)) {
this.toggleWidget();
}
this.flashing = false;
Expand Down
33 changes: 3 additions & 30 deletions src/plugins/FingerPrint.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ module.exports = class FingerPrint extends OverlayPlugin {
this.toolbarBtnImage = document.createElement('div');
this.toolbarBtnImage.className = 'gm-icon-button gm-fingerprint-button';
this.toolbarBtnImage.title = this.i18n.FINGERPRINT_TITLE || 'Biometrics';
this.toolbarBtn.onclick = () => this.toggleWidget();
this.toolbarBtn.onclick = this.toggleWidget.bind(this);
this.toolbarBtn.appendChild(this.toolbarBtnImage);
toolbar.appendChild(this.toolbarBtn);
}
Expand Down Expand Up @@ -284,45 +284,18 @@ module.exports = class FingerPrint extends OverlayPlugin {
// Add close button
const close = document.createElement('div');
close.className = 'gm-close-btn';
close.onclick = () => this.closeWidget();
close.onclick = this.toggleWidget.bind(this);

this.widget.appendChild(close);
this.widget.appendChild(this.container);

// Render into document
this.overlays.push(this.widget);
this.instance.root.appendChild(this.widget);

// post setup
this.disableBody();
}

/**
* Display or hide the widget.
*/
toggleWidget() {
// Notify other callers
if (this.widget.classList.contains('gm-hidden')) {
this.instance.emit('close-overlays');
this.instance.emit('keyboard-disable');
} else {
this.instance.emit('keyboard-enable');
}

// Toggle display
this.widget.classList.toggle('gm-hidden');
this.toolbarBtnImage.classList.toggle('gm-active');
}

/**
* Close the widget.
*/
closeWidget() {
this.instance.emit('keyboard-enable');
this.widget.classList.add('gm-hidden');
this.toolbarBtnImage.classList.remove('gm-active');
}

/**
* Create a fingerprint button and attached it to buttonDivs pass in parameter.
* @param {String} button Button name.
Expand Down Expand Up @@ -379,7 +352,7 @@ module.exports = class FingerPrint extends OverlayPlugin {
Array.from(document.querySelectorAll('.gm-fingerprint-dialog-button')).forEach((btn) => {
btn.classList.remove('gm-loader');
});
this.closeWidget();
this.toggleWidget();
break;
case FINGERPRINT_MESSAGES.toReceive.CURRENT_STATUS_SCANNING:
this.state.isScanning = true;
Expand Down
25 changes: 7 additions & 18 deletions src/plugins/GPS.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ module.exports = class GPS extends OverlayPlugin {
this.mapWidget.appendChild(cancel);

// Render into document
this.overlays.push(this.mapWidget);
this.instance.root.appendChild(this.mapWidget);
}

Expand Down Expand Up @@ -206,7 +205,7 @@ module.exports = class GPS extends OverlayPlugin {
*/
renderGPSForm() {
// Create elements
this.formWidget = document.createElement('div');
this.widget = document.createElement('div');
this.form = document.createElement('form');
const formWrap = document.createElement('div');

Expand Down Expand Up @@ -282,39 +281,29 @@ module.exports = class GPS extends OverlayPlugin {
this.form.appendChild(button);

// Setup
this.formWidget.className = 'gm-overlay gm-gps-controls gm-hidden';
this.widget.className = 'gm-overlay gm-gps-controls gm-hidden';

// Add close button
const close = document.createElement('div');
close.className = 'gm-close-btn';
close.onclick = this.toggleForm.bind(this);

this.formWidget.appendChild(close);
this.formWidget.appendChild(this.form);
this.widget.appendChild(close);
this.widget.appendChild(this.form);

// Render into document
this.overlays.push(this.formWidget);
this.instance.root.appendChild(this.formWidget);
this.instance.root.appendChild(this.widget);
}

/**
* Display or hide the controls view.
*/
toggleForm() {
// Notify other callers
if (this.formWidget.classList.contains('gm-hidden')) {
this.instance.emit('close-overlays');
this.instance.emit('keyboard-disable');
} else {
this.instance.emit('keyboard-enable');
}

this.toggleWidget();
this.checkForGeolocation();

// Toggle display
this.formWidget.classList.toggle('gm-hidden');
// TODO refacto this with 2 different overlay (gps and map)
this.mapWidget.classList.add('gm-hidden');
this.toolbarBtnImage.classList.toggle('gm-active');
}

/**
Expand Down
18 changes: 0 additions & 18 deletions src/plugins/Gamepad.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ module.exports = class Gamepad extends OverlayPlugin {
this.widget.appendChild(this.container);

// Render into document
this.overlays.push(this.widget);
this.instance.root.appendChild(this.widget);
}

Expand Down Expand Up @@ -150,23 +149,6 @@ module.exports = class Gamepad extends OverlayPlugin {
this.instance.sendEvent(json);
}

/**
* Display or hide the widget.
*/
toggleWidget() {
// Notify other callers
if (this.widget.classList.contains('gm-hidden')) {
this.instance.emit('close-overlays');
this.instance.emit('keyboard-disable');
} else {
this.instance.emit('keyboard-enable');
}

// Toggle display
this.widget.classList.toggle('gm-hidden');
this.toolbarBtnImage.classList.toggle('gm-active');
}

handleConfirmation(message) {
log.debug('Gamepad plugin confirmation');
const values = message.split(' ');
Expand Down
Loading

0 comments on commit 106466b

Please sign in to comment.