Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

constant.js 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.touchAction = exports.validateParameters = exports.formatArgs = void 0;
  4. const TOUCH_ACTIONS = ['press', 'longPress', 'tap', 'moveTo', 'wait', 'release'];
  5. const POS_ACTIONS = TOUCH_ACTIONS.slice(0, 4);
  6. const ACCEPTED_OPTIONS = ['x', 'y', 'element'];
  7. exports.formatArgs = function (scope, actions) {
  8. return actions.map((action) => {
  9. if (Array.isArray(action)) {
  10. return exports.formatArgs(scope, action);
  11. }
  12. if (typeof action === 'string') {
  13. action = { action };
  14. }
  15. const formattedAction = {
  16. action: action.action,
  17. options: {}
  18. };
  19. const actionElement = action.element && typeof action.element.elementId === 'string'
  20. ? action.element.elementId
  21. : scope.elementId;
  22. if (POS_ACTIONS.includes(action.action) && formattedAction.options && actionElement) {
  23. formattedAction.options.element = actionElement;
  24. }
  25. if (formattedAction.options && typeof action.x === 'number' && isFinite(action.x))
  26. formattedAction.options.x = action.x;
  27. if (formattedAction.options && typeof action.y === 'number' && isFinite(action.y))
  28. formattedAction.options.y = action.y;
  29. if (formattedAction.options && action.ms)
  30. formattedAction.options.ms = action.ms;
  31. if (formattedAction.options && Object.keys(formattedAction.options).length === 0) {
  32. delete formattedAction.options;
  33. }
  34. return formattedAction;
  35. });
  36. };
  37. exports.validateParameters = (params) => {
  38. const options = Object.keys(params.options || {});
  39. if (params.action === 'release' && options.length !== 0) {
  40. throw new Error('action "release" doesn\'t accept any options ' +
  41. `("${options.join('", "')}" found)`);
  42. }
  43. if (params.action === 'wait' &&
  44. (options.includes('x') || options.includes('y'))) {
  45. throw new Error('action "wait" doesn\'t accept x or y options');
  46. }
  47. if (POS_ACTIONS.includes(params.action)) {
  48. for (const option in params.options) {
  49. if (!ACCEPTED_OPTIONS.includes(option)) {
  50. throw new Error(`action "${params.action}" doesn't accept "${option}" as option`);
  51. }
  52. }
  53. if (options.length === 0) {
  54. throw new Error(`Touch actions like "${params.action}" need at least some kind of ` +
  55. 'position information like "element", "x" or "y" options, you\'ve none given.');
  56. }
  57. }
  58. };
  59. exports.touchAction = function (actions) {
  60. if (!this.multiTouchPerform || !this.touchPerform) {
  61. throw new Error('touchAction can be used with Appium only.');
  62. }
  63. if (!Array.isArray(actions)) {
  64. actions = [actions];
  65. }
  66. const formattedAction = exports.formatArgs(this, actions);
  67. const protocolCommand = Array.isArray(actions[0])
  68. ? this.multiTouchPerform.bind(this)
  69. : this.touchPerform.bind(this);
  70. formattedAction.forEach((params) => exports.validateParameters(params));
  71. return protocolCommand(formattedAction);
  72. };