为了更好的为您提供服务, 云效 邀请您使用持续交付相关功能。云效结合ECS、EDAS等服务为您提供完备的发布、部署、测试全研发流程,大大提升您的研发效率. 了解更多>

提交 5780b1db3db7590c0b3532a9c7ae8422f6be3d39

作者 sdfsung
1 个父辈 458a1de3

Add exit foreground app module

  1 +module.exports = (() => {
  2 + const uiUtils = require('../utils/ui');
  3 +
  4 + const exitApp = function exitForegroundApplicationUsingReturnKey() {
  5 + showResult(returnUntilExitingApp());
  6 + };
  7 +
  8 + const showResult = function showExitForegroundApplicationResult(result) {
  9 + const state = result.success ? 'has exited' : 'cannot exit';
  10 + const message = getAppName(result.package) + ' ' + state;
  11 + toast(message);
  12 + };
  13 +
  14 + const returnUntilExitingApp = function keepReturningUntilExitingForegroundApplication() {
  15 + const TIME_REQUIRED_FOR_RETURN = 100;
  16 + const MAXIMUM_RETURN_IN_SAME_UI = 10;
  17 + let prevPackage = uiUtils.getCurrentPackage();
  18 + let result = { package: prevPackage, success: false };
  19 + let sameui = getSameUiInfo();
  20 +
  21 + while (true) {
  22 + back();
  23 + sleep(TIME_REQUIRED_FOR_RETURN);
  24 +
  25 + if (uiUtils.getCurrentPackage() !== prevPackage) {
  26 + result.success = true;
  27 + break;
  28 + }
  29 +
  30 + if (sameui.number + 1 >= MAXIMUM_RETURN_IN_SAME_UI) break;
  31 +
  32 + sameui.updateNum();
  33 + }
  34 +
  35 + return result;
  36 + };
  37 +
  38 + const getSameUiInfo = function getInfoAboutNumberOfTimesOfTheSameUi() {
  39 + return {
  40 + number: 1,
  41 + prevText: null,
  42 + updateNum: function() {
  43 + let curText = uiUtils.getAllTextualContent().toString();
  44 + this.number = curText !== this.prevText ? 1 : this.number + 1;
  45 + this.prevText = curText;
  46 + },
  47 + };
  48 + };
  49 +
  50 + return {
  51 + exitApp: exitApp,
  52 + returnUntilExitingApp: returnUntilExitingApp,
  53 + };
  54 +})();
... ...
  1 +require('./exit-app-action').exitApp();
... ...