You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by TimBarham <gi...@git.apache.org> on 2015/10/21 00:03:10 UTC

[GitHub] cordova-lib pull request: On Windows, verify browsers installed be...

GitHub user TimBarham opened a pull request:

    https://github.com/apache/cordova-lib/pull/327

    On Windows, verify browsers installed before launching.

    Do this to avoid dialog that pops up on Windows if browser is not installed, and provide more meaningful error messages.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/MSOpenTech/cordova-lib serve-verify-browser

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/cordova-lib/pull/327.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #327
    
----
commit 8f330f173edd19c1d50fa5db00368192c609bb59
Author: Tim Barham <ti...@microsoft.com>
Date:   2015-10-17T02:17:03Z

    On Windows, verify browsers installed before launching.
    
    Do this to avoid dialog that pops up if browser is not installed.

----


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-lib pull request: On Windows, verify browsers installed be...

Posted by TimBarham <gi...@git.apache.org>.
Github user TimBarham commented on the pull request:

    https://github.com/apache/cordova-lib/pull/327#issuecomment-149737583
  
    Thanks for taking a look, @vladimir-kotikov.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-lib pull request: On Windows, verify browsers installed be...

Posted by vladimir-kotikov <gi...@git.apache.org>.
Github user vladimir-kotikov commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/327#discussion_r42561198
  
    --- Diff: cordova-serve/src/browser.js ---
    @@ -17,9 +17,15 @@
      under the License.
      */
     
    -var exec = require('./exec'),
    +var child_process = require('child_process'),
    +    exec = require('./exec'),
    +    fs = require('fs'),
    +    path = require('path'),
         Q = require('q');
     
    +var NOT_INSALLED = 'The browser target is not installed: %target%';
    --- End diff --
    
    typo: `NOT_INSTALLED`


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-lib pull request: On Windows, verify browsers installed be...

Posted by vladimir-kotikov <gi...@git.apache.org>.
Github user vladimir-kotikov commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/327#discussion_r42564428
  
    --- Diff: cordova-serve/src/browser.js ---
    @@ -95,16 +105,93 @@ function getBrowser(target, dataDir) {
                 'firefox': 'firefox',
                 'opera': 'opera'
             },
    -        'linux' : {
    -            'chrome': 'google-chrome' + chromeArgs ,
    +        'linux': {
    +            'chrome': 'google-chrome' + chromeArgs,
                 'chromium': 'chromium-browser' + chromeArgs,
                 'firefox': 'firefox',
                 'opera': 'opera'
             }
         };
    -    target = target.toLowerCase();
         if (target in browsers[process.platform]) {
    -        return Q(browsers[process.platform][target]);
    +        var browser = browsers[process.platform][target];
    +        if (process.platform === 'win32') {
    +            // Windows displays a dialog if the browser is not installed. We'd prefer to avoid that.
    +            return checkBrowserExistsWindows(browser, target).then(function () {
    +                return browser;
    +            });
    +        } else {
    +            return Q(browser);
    +        }
         }
    -    return Q.reject('Browser target not supported: ' + target);
    +    return Q.reject(NOT_SUPPORTED.replace('%target%', target));
    +}
    +
    +function checkBrowserExistsWindows(browser, target) {
    +    var promise = target === 'edge' ? edgeSupported() : browserInstalled(browser);
    +    return promise.catch(function (error) {
    +        return Q.reject((error && error.toString() || NOT_INSTALLED).replace('%target%', target));
    +    });
    +}
    +
    +function edgeSupported() {
    +    var d = Q.defer();
    +
    +    child_process.exec('ver', function (err, stdout, stderr) {
    --- End diff --
    
    Is there any chance to reuse `./exec` module here. Looks like it contains almost the same logic.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-lib pull request: On Windows, verify browsers installed be...

Posted by vladimir-kotikov <gi...@git.apache.org>.
Github user vladimir-kotikov commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/327#discussion_r42564896
  
    --- Diff: cordova-serve/src/browser.js ---
    @@ -95,16 +105,93 @@ function getBrowser(target, dataDir) {
                 'firefox': 'firefox',
                 'opera': 'opera'
             },
    -        'linux' : {
    -            'chrome': 'google-chrome' + chromeArgs ,
    +        'linux': {
    +            'chrome': 'google-chrome' + chromeArgs,
                 'chromium': 'chromium-browser' + chromeArgs,
                 'firefox': 'firefox',
                 'opera': 'opera'
             }
         };
    -    target = target.toLowerCase();
         if (target in browsers[process.platform]) {
    -        return Q(browsers[process.platform][target]);
    +        var browser = browsers[process.platform][target];
    +        if (process.platform === 'win32') {
    +            // Windows displays a dialog if the browser is not installed. We'd prefer to avoid that.
    +            return checkBrowserExistsWindows(browser, target).then(function () {
    +                return browser;
    +            });
    +        } else {
    +            return Q(browser);
    +        }
         }
    -    return Q.reject('Browser target not supported: ' + target);
    +    return Q.reject(NOT_SUPPORTED.replace('%target%', target));
    +}
    +
    +function checkBrowserExistsWindows(browser, target) {
    +    var promise = target === 'edge' ? edgeSupported() : browserInstalled(browser);
    +    return promise.catch(function (error) {
    +        return Q.reject((error && error.toString() || NOT_INSTALLED).replace('%target%', target));
    +    });
    +}
    +
    +function edgeSupported() {
    +    var d = Q.defer();
    +
    +    child_process.exec('ver', function (err, stdout, stderr) {
    --- End diff --
    
    BTW, `os.version()` gives me exactly the same version as `ver`, it might better to use it


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-lib pull request: On Windows, verify browsers installed be...

Posted by vladimir-kotikov <gi...@git.apache.org>.
Github user vladimir-kotikov commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/327#discussion_r42561832
  
    --- Diff: cordova-serve/src/browser.js ---
    @@ -72,7 +79,10 @@ module.exports = function (opts) {
                 args.push(url);
             }
             var command = args.join(' ');
    -        return exec(command);
    +        return exec(command).catch(function (error) {
    +            // Assume any error means that the browser is not installed and display that as a more friendly error.
    +            throw new Error(NOT_INSALLED.replace('%target%', target));
    --- End diff --
    
    typo again


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-lib pull request: On Windows, verify browsers installed be...

Posted by vladimir-kotikov <gi...@git.apache.org>.
Github user vladimir-kotikov commented on the pull request:

    https://github.com/apache/cordova-lib/pull/327#issuecomment-149728218
  
    Looks good.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-lib pull request: On Windows, verify browsers installed be...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/cordova-lib/pull/327


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-lib pull request: On Windows, verify browsers installed be...

Posted by TimBarham <gi...@git.apache.org>.
Github user TimBarham commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/327#discussion_r42565322
  
    --- Diff: cordova-serve/src/browser.js ---
    @@ -95,16 +105,93 @@ function getBrowser(target, dataDir) {
                 'firefox': 'firefox',
                 'opera': 'opera'
             },
    -        'linux' : {
    -            'chrome': 'google-chrome' + chromeArgs ,
    +        'linux': {
    +            'chrome': 'google-chrome' + chromeArgs,
                 'chromium': 'chromium-browser' + chromeArgs,
                 'firefox': 'firefox',
                 'opera': 'opera'
             }
         };
    -    target = target.toLowerCase();
         if (target in browsers[process.platform]) {
    -        return Q(browsers[process.platform][target]);
    +        var browser = browsers[process.platform][target];
    +        if (process.platform === 'win32') {
    +            // Windows displays a dialog if the browser is not installed. We'd prefer to avoid that.
    +            return checkBrowserExistsWindows(browser, target).then(function () {
    +                return browser;
    +            });
    +        } else {
    +            return Q(browser);
    +        }
         }
    -    return Q.reject('Browser target not supported: ' + target);
    +    return Q.reject(NOT_SUPPORTED.replace('%target%', target));
    +}
    +
    +function checkBrowserExistsWindows(browser, target) {
    +    var promise = target === 'edge' ? edgeSupported() : browserInstalled(browser);
    +    return promise.catch(function (error) {
    +        return Q.reject((error && error.toString() || NOT_INSTALLED).replace('%target%', target));
    +    });
    +}
    +
    +function edgeSupported() {
    +    var d = Q.defer();
    +
    +    child_process.exec('ver', function (err, stdout, stderr) {
    --- End diff --
    
    I originally used the exec module and the logic actuallly ended up simpler this way. 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-lib pull request: On Windows, verify browsers installed be...

Posted by TimBarham <gi...@git.apache.org>.
Github user TimBarham commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/327#discussion_r42565419
  
    --- Diff: cordova-serve/src/browser.js ---
    @@ -95,16 +105,93 @@ function getBrowser(target, dataDir) {
                 'firefox': 'firefox',
                 'opera': 'opera'
             },
    -        'linux' : {
    -            'chrome': 'google-chrome' + chromeArgs ,
    +        'linux': {
    +            'chrome': 'google-chrome' + chromeArgs,
                 'chromium': 'chromium-browser' + chromeArgs,
                 'firefox': 'firefox',
                 'opera': 'opera'
             }
         };
    -    target = target.toLowerCase();
         if (target in browsers[process.platform]) {
    -        return Q(browsers[process.platform][target]);
    +        var browser = browsers[process.platform][target];
    +        if (process.platform === 'win32') {
    +            // Windows displays a dialog if the browser is not installed. We'd prefer to avoid that.
    +            return checkBrowserExistsWindows(browser, target).then(function () {
    +                return browser;
    +            });
    +        } else {
    +            return Q(browser);
    +        }
         }
    -    return Q.reject('Browser target not supported: ' + target);
    +    return Q.reject(NOT_SUPPORTED.replace('%target%', target));
    +}
    +
    +function checkBrowserExistsWindows(browser, target) {
    +    var promise = target === 'edge' ? edgeSupported() : browserInstalled(browser);
    +    return promise.catch(function (error) {
    +        return Q.reject((error && error.toString() || NOT_INSTALLED).replace('%target%', target));
    +    });
    +}
    +
    +function edgeSupported() {
    +    var d = Q.defer();
    +
    +    child_process.exec('ver', function (err, stdout, stderr) {
    --- End diff --
    
    os.release() doesn't recognize Win10 in fairly common versions of node. 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] cordova-lib pull request: On Windows, verify browsers installed be...

Posted by TimBarham <gi...@git.apache.org>.
Github user TimBarham commented on a diff in the pull request:

    https://github.com/apache/cordova-lib/pull/327#discussion_r42562761
  
    --- Diff: cordova-serve/src/browser.js ---
    @@ -17,9 +17,15 @@
      under the License.
      */
     
    -var exec = require('./exec'),
    +var child_process = require('child_process'),
    +    exec = require('./exec'),
    +    fs = require('fs'),
    +    path = require('path'),
         Q = require('q');
     
    +var NOT_INSALLED = 'The browser target is not installed: %target%';
    --- End diff --
    
    Thanks. Oops. Fixed :smile: 


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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