Skip to content

Commit

Permalink
Merge pull request #18 from joshden/master (powershell & registry)
Browse files Browse the repository at this point in the history
  • Loading branch information
omril1 committed Sep 12, 2023
2 parents 010964c + b34b4f1 commit 0fc0deb
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion index.js
Expand Up @@ -26,6 +26,8 @@ function extractChromeVersionNumer(chromeVersionString) {
return chromeVersionString.replace(/\D*(([0-9]+\.?)+)\s?.*/, '$1');
}

const chromeVersionRegex = /^(\d+\.){3}\d+$/g;

async function getChromeVersionWin(includeChromium) {

let chromePath;
Expand All @@ -35,18 +37,40 @@ async function getChromeVersionWin(includeChromium) {
return null;
}

const powershell = await execAndAttemptExtractingChromeVersion(`powershell -command "&{(Get-Item '${chromePath}').VersionInfo.ProductVersion}"`);
if (powershell !== null) {
return powershell;
}

const registry = await execAndAttemptExtractingChromeVersion('reg query "HKEY_CURRENT_USER\\Software\\Google\\Chrome\\BLBeacon" /v version');
if (registry !== null) {
return registry;
}

const versionPath = path.dirname(chromePath);

const contents = await readdir(versionPath);

const versions = contents.filter(a => /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/g.test(a));
const versions = contents.filter(a => chromeVersionRegex.test(a));

// returning oldest in case there is an updated version and chrome still hasn't relaunched
const oldest = versions.sort((a, b) => a > b)[0];

return oldest;
}

async function execAndAttemptExtractingChromeVersion(command) {
try {
const { stdout } = await exec(command);
const version = extractChromeVersionNumer(stdout).trim();
if (chromeVersionRegex.test(version)) {
return version;
}
} catch (err) { ''; }

return null;
}

function getChromeVersionFromOsa(includeChromium) {

try {
Expand Down

0 comments on commit 0fc0deb

Please sign in to comment.