Github user dblotsky commented on a diff in the pull request:

    https://github.com/apache/cordova-android/pull/180#discussion_r32090785
  
    --- Diff: bin/templates/cordova/lib/emulator.js ---
    @@ -298,37 +306,67 @@ module.exports.resolveTarget = function(target) {
      * If no started emulators are found, error out.
      * Returns a promise.
      */
    -module.exports.install = function(target, buildResults) {
    -    return Q().then(function() {
    -        if (target && typeof target == 'object') {
    -            return target;
    +module.exports.install = function(givenTarget, buildResults) {
    +
    +    var target;
    +
    +    // resolve the target emulator
    +    return Q().then(function () {
    +        if (givenTarget && typeof givenTarget == 'object') {
    +            return givenTarget;
    +        } else {
    +            return module.exports.resolveTarget(givenTarget);
             }
    -        return module.exports.resolveTarget(target);
    -    }).then(function(resolvedTarget) {
    -        var apk_path = build.findBestApkForArchitecture(buildResults, 
resolvedTarget.arch);
    +
    +    // set the resolved target
    +    }).then(function (resolvedTarget) {
    +        target = resolvedTarget;
    +
    +    // install the app
    +    }).then(function () {
    +
    +        var apk_path    = build.findBestApkForArchitecture(buildResults, 
target.arch);
    +        var execOptions = {
    +            timeout:    INSTALL_COMMAND_TIMEOUT, // in milliseconds
    +            killSignal: EXEC_KILL_SIGNAL
    +        };
    +
             console.log('Installing app on emulator...');
             console.log('Using apk: ' + apk_path);
    -        return exec('adb -s ' + resolvedTarget.target + ' install -r -d "' 
+ apk_path + '"', os.tmpdir())
    -        .then(function(output) {
    +
    +        var retriedInstall = retry.retryPromise(
    +            NUM_INSTALL_RETRIES,
    +            exec, 'adb -s ' + target.target + ' install -r -d "' + 
apk_path + '"', os.tmpdir(), execOptions
    +        );
    +
    +        return retriedInstall.then(function (output) {
                 if (output.match(/Failure/)) {
                     return Q.reject('Failed to install apk to emulator: ' + 
output);
    +            } else {
    +                console.log('INSTALL SUCCESS');
                 }
    -            return Q();
    -        }, function(err) {
    +        }, function (err) {
                 return Q.reject('Failed to install apk to emulator: ' + err);
    -        }).then(function() {
    -            //unlock screen
    -            return exec('adb -s ' + resolvedTarget.target + ' shell input 
keyevent 82', os.tmpdir());
    -        }).then(function() {
    -            // launch the application
    -            console.log('Launching application...');
    -            var launchName = appinfo.getActivityName();
    -            var cmd = 'adb -s ' + resolvedTarget.target + ' shell am start 
-W -a android.intent.action.MAIN -n ' + launchName;
    -            return exec(cmd, os.tmpdir());
    -        }).then(function(output) {
    -            console.log('LAUNCH SUCCESS');
    -        }, function(err) {
    -            return Q.reject('Failed to launch app on emulator: ' + err);
             });
    +
    +    // unlock screen
    +    }).then(function () {
    +
    +        console.log('Unlocking screen...');
    +        return exec('adb -s ' + target.target + ' shell input keyevent 
82', os.tmpdir());
    +
    +    // launch the application
    --- End diff --
    
    Don't Repeat Yourself applies to repeated code or logic, not to comments. 
This comment improves readability because you can clearly see what every `then` 
block does by looking only at the comment above it, and it is therefore useful.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@cordova.apache.org
For additional commands, e-mail: dev-h...@cordova.apache.org

Reply via email to