Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checks for invalid reg output #16

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading