From 79fb2f5b63f444baf729f0de7a78dd88c981ec9a Mon Sep 17 00:00:00 2001 From: Mitchell Hentges Date: Mon, 29 Feb 2016 17:03:18 +0100 Subject: [PATCH] Firefox can use `util` --- lib/darwin/firefox.js | 35 ---------------------------- lib/darwin/index.js | 2 +- lib/detect.js | 53 ++++++++++++++----------------------------- 3 files changed, 18 insertions(+), 72 deletions(-) delete mode 100644 lib/darwin/firefox.js diff --git a/lib/darwin/firefox.js b/lib/darwin/firefox.js deleted file mode 100644 index 50f9f1e..0000000 --- a/lib/darwin/firefox.js +++ /dev/null @@ -1,35 +0,0 @@ -var path = require('path'), - util = require('./util'); - -//Fetch all known version of Firefox on the host machine -exports.all = function (callback) { - var installed = [], - pending = 0, - check = function () { - if (!pending) { - callback(null, installed); - } - }; - - util.find('org.mozilla.firefox', function (err, p) { - if (p) { - var items = p.split('\n'); - pending = items.length; - items.forEach(function (loc) { - util.parse(util.getInfoPath(loc), function (err, data) { - if (!err) { - installed.push({ - version: data['CFBundleShortVersionString'], - path: path.join(loc, 'Contents/MacOS/firefox-bin') - }); - } - - pending--; - check(); - }); - }); - } else { - callback('not installed'); - } - }); -}; diff --git a/lib/darwin/index.js b/lib/darwin/index.js index c89bd3d..3c024c2 100644 --- a/lib/darwin/index.js +++ b/lib/darwin/index.js @@ -8,7 +8,7 @@ function browser(id, versionKey) { } exports.safari = browser('com.apple.Safari', 'CFBundleShortVersionString'); -exports.firefox = require( './firefox' ); +exports.firefox = browser('org.mozilla.firefox', 'CFBundleShortVersionString'); exports.chrome = exports[ 'google-chrome' ] = browser('com.google.Chrome', 'KSVersion'); exports.chromium = browser('org.chromium.Chromium', 'CFBundleShortVersionString'); exports.canary = exports[ 'chrome-canary' ] = exports[ 'google-chrome-canary' ] = browser('com.google.Chrome.canary', 'KSVersion'); diff --git a/lib/detect.js b/lib/detect.js index 6fdf258..23c168c 100644 --- a/lib/detect.js +++ b/lib/detect.js @@ -92,29 +92,19 @@ function detectWindows( callback ) { */ function checkDarwin( name, callback ) { if ( darwin[ name ] ) { - if ( darwin[ name ].all ) { - darwin[ name ].all( function( err, available ) { - if ( err ) { - callback( 'failed to get version for ' + name ); - } else { - callback( err, available ); - } - } ); - } else { - darwin[ name ].version( function( err, version ) { - if ( version ) { - darwin[ name ].path( function( err, p ) { - if ( err ) { - return callback( 'failed to get path for ' + name ); - } - - callback( null, version, p ); - } ); - } else { - callback( 'failed to get version for ' + name ); - } - } ); - } + darwin[ name ].version( function( err, version ) { + if ( version ) { + darwin[ name ].path( function( err, p ) { + if ( err ) { + return callback( 'failed to get path for ' + name ); + } + + callback( null, version, p ); + } ); + } else { + callback( 'failed to get version for ' + name ); + } + } ); } else { checkOthers( name, callback ); } @@ -190,19 +180,10 @@ module.exports = function detect( callback ) { check( name, function( err, v, p ) { if ( err === null ) { - if ( Array.isArray( v ) ) { - v.forEach( function( item ) { - available.push( extend( {}, br, { - command: item.path, - version: item.version - } ) ); - } ); - } else { - available.push( extend( {}, br, { - command: p || name, - version: v - } ) ); - } + available.push( extend( {}, br, { + command: p || name, + version: v + } ) ); } next();