diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..de99ed8 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text eol=lf \ No newline at end of file diff --git a/src/helpers/browsers.js b/src/helpers/browsers.js index 953ff27..a4642d5 100644 --- a/src/helpers/browsers.js +++ b/src/helpers/browsers.js @@ -3,6 +3,28 @@ const os = require('os'); const utils = require('../utils'); const path = require('path'); +function getFirefoxVersion(darvinId, winProgPath) { + let firefoxVersion; + let appPath; + if (utils.isLinux) { + firefoxVersion = utils.run('firefox --version').then(v => v.replace(/^.* ([^ ]*)/g, '$1')); + } else if (utils.isMacOS && typeof darvinId === 'string' && darvinId) { + firefoxVersion = utils.getDarwinApplicationVersion(darvinId); + } else if (utils.isWindows && typeof winProgPath === 'string' && winProgPath) { + firefoxVersion = utils.windowsExeExists(winProgPath).then(filePath => { + appPath = filePath; + return filePath + ? utils + .run(`powershell ". '${filePath}' -v | Write-Output"`) + .then(out => utils.findVersion(out)) + : utils.NA; + }); + } else { + firefoxVersion = Promise.resolve(utils.NA); + } + return firefoxVersion.then(v => utils.determineFound('Firefox', v, appPath || utils.NA)); +} + module.exports = { getBraveBrowserInfo: () => { utils.log('trace', 'getBraveBrowser'); @@ -106,24 +128,14 @@ module.exports = { getFirefoxInfo: () => { utils.log('trace', 'getFirefoxInfo'); - let firefoxVersion; - if (utils.isLinux) { - firefoxVersion = utils.run('firefox --version').then(v => v.replace(/^.* ([^ ]*)/g, '$1')); - } else if (utils.isMacOS) { - firefoxVersion = utils.getDarwinApplicationVersion(utils.browserBundleIdentifiers.Firefox); - } else { - firefoxVersion = Promise.resolve('N/A'); - } - return firefoxVersion.then(v => utils.determineFound('Firefox', v, 'N/A')); + getFirefoxVersion(utils.browserBundleIdentifiers.Firefox, 'Mozilla Firefox/firefox.exe'); }, getFirefoxDeveloperEditionInfo: () => { utils.log('trace', 'getFirefoxDeveloperEditionInfo'); - const firefoxDeveloperEdition = utils.getDarwinApplicationVersion( - utils.browserBundleIdentifiers['Firefox Developer Edition'] - ); - return firefoxDeveloperEdition.then(v => - utils.determineFound('Firefox Developer Edition', v, 'N/A') + getFirefoxVersion( + utils.browserBundleIdentifiers['Firefox Developer Edition'], + 'Firefox Developer Edition/firefox.exe' ); }, diff --git a/src/utils.js b/src/utils.js index e7c8b33..077b3f1 100644 --- a/src/utils.js +++ b/src/utils.js @@ -38,6 +38,27 @@ const fileExists = filePath => { }); }; +const windowsExeExists = relExeFilePath => { + return new Promise(resolve => { + let absPath; + fs.access( + (absPath = path.join(process.env.ProgramFiles, `${relExeFilePath}`)), + fs.constants.R_OK, + err1 => { + if (err1) { + fs.access( + (absPath = path.join(process.env['ProgramFiles(x86)'], `${relExeFilePath}`)), + fs.constants.X_OK, + err2 => { + resolve(err2 ? null : absPath); + } + ); + } else resolve(absPath); + } + ); + }); +}; + const readFile = filePath => { return new Promise(fileResolved => { fs.readFile(filePath, 'utf8', (err, file) => (file ? fileResolved(file) : fileResolved(null))); @@ -96,6 +117,7 @@ module.exports = { run: run, log: log, fileExists: fileExists, + windowsExeExists: windowsExeExists, readFile: readFile, requireJson: requireJson, versionRegex: versionRegex,