Skip to content
This repository was archived by the owner on Jan 6, 2023. It is now read-only.

Automatically determine browser executable path #135

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions lib/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ var Utils = require('./utils');
var events = require('./events');
var ports = require('./ports');
var log = require('./logging').logger;
var os = require('os');
var _ = require('underscore');
var hasbin = require('hasbin');
var util = require('util');

var Serve = module.exports;

Expand All @@ -30,6 +34,20 @@ var DEFAULT_LIVE_RELOAD_PORT = 35729;
var IONIC_LAB_URL = '/ionic-lab';
var IONIC_ANGULAR_URL = '/angular.min.js';

var DEFAULT_PLATFORM_BROWSER_PATHS = {
darwin: {
chrome: '/Applications/Google Chrome.app',
safari: '/Applications/Safari.app',
firefox: '/Applications/Firefox.app'
},
linux: {
chrome: [
'google-chrome',
'chrome'
]
}
};

Serve.listenForServerCommands = function listenForServerCommands(options) {
var readline = require('readline');

Expand Down Expand Up @@ -236,8 +254,24 @@ Serve.openBrowser = function openBrowser(options) {
openUrl.push('?ionicplatform=', options.platform);
}

var browserPath;
if (!hasbin.sync(options.browser)) {
var platformBrowsers = DEFAULT_PLATFORM_BROWSER_PATHS[os.platform()];
if (platformBrowsers) {
var defaultBrowserPath = platformBrowsers[options.browser];
if (util.isString(defaultBrowserPath)) {
browserPath = defaultBrowserPath;
} else if (util.isArray(defaultBrowserPath)) {
browserPath = _.find(defaultBrowserPath, function(path) {
return fs.existsSync(path) || hasbin.sync(path);
});
}
}
}

try {
open(openUrl.join(''), options.browser);
var browser = browserPath || options.browser;
open(openUrl.join(''), browser);
} catch (ex) {
log.error('Error opening the browser - ', ex);
}
Expand Down Expand Up @@ -872,7 +906,7 @@ Serve.getAddress = function(options) {
return q.promise;

} else if (addresses.length > 1) {

if (!options.isPlatformServe) {
addresses.push({
address: 'localhost'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"finalhandler": "0.2.0",
"form-data": "0.1.4",
"glob-watcher": "3.0.0",
"hasbin": "^1.2.3",
"open": "0.0.5",
"optimist": "0.6.0",
"os-name": "^2.0.1",
Expand Down