Skip to content

Commit

Permalink
Add checks for invalid reg output (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkcdarunday authored Oct 17, 2024
1 parent fec2a77 commit 1ca3f09
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/system-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,15 @@ customElements.define('system-status', class extends HTMLElement {

const pathQuery = spawnSync('reg', ['query', 'HKCU\\Environment', '/v', 'Path'])
if (pathQuery.status !== 0 && !pathQuery.stderr.toString().includes('unable to find')) {
throw new Error('Failed to query user PATH.')
throw new Error('Failed to query user PATH')
}

const originalPath = pathQuery.stdout.toString()?.match(WIN_REGVAL_MATCHER)?.[1]
const pathMatches = pathQuery.stdout.toString()?.match(WIN_REGVAL_MATCHER)
if (!Array.isArray(pathMatches) || pathMatches.length !== 2) {
throw new Error('Failed to extract user PATH')
}

const originalPath = pathMatches[1]
if (!originalPath || !originalPath.includes(BIN)) {
const newPath = originalPath ? `${BIN};${originalPath}` : BIN
spawnSync('reg', ['add', 'HKCU\\Environment', '/v', 'Path', '/t', 'REG_SZ', '/d', newPath, '/f'])
Expand Down

0 comments on commit 1ca3f09

Please sign in to comment.