Skip to content

Commit

Permalink
feat: support for finding firefox web browser on windows added (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
SetTrend authored Jun 20, 2023
1 parent 7fe97ea commit 2228297
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
40 changes: 26 additions & 14 deletions src/helpers/browsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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'
);
},

Expand Down
22 changes: 22 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -96,6 +117,7 @@ module.exports = {
run: run,
log: log,
fileExists: fileExists,
windowsExeExists: windowsExeExists,
readFile: readFile,
requireJson: requireJson,
versionRegex: versionRegex,
Expand Down

0 comments on commit 2228297

Please sign in to comment.