Skip to content

Commit

Permalink
Move registry value matcher regex to a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
jkcdarunday committed Apr 29, 2024
1 parent 372b2be commit 22cd6c3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/system-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { spawnSync } from 'child_process'
const { config } = Pear

const BIN = path.join(config.pearDir, 'bin')
const WIN_REGVAL_MATCHER = /REG_SZ\s+([^\r\n]+)\r?\n/

const isWin = process.platform === 'win32'

customElements.define('pear-welcome', class extends HTMLElement {
Expand Down Expand Up @@ -181,7 +183,7 @@ customElements.define('system-status', class extends HTMLElement {
if (hasPear) process.env.PATH = `${BIN}:${process.env.PATH}`
} else {
const currentPath = spawnSync('reg', ['query', 'HKCU\\Environment', '/v', 'Path'], { stdio: 'pipe' })
.stdout.toString()?.match(/REG_SZ\s+([^\r\n]+)\r?\n/)?.[1]
.stdout.toString()?.match(WIN_REGVAL_MATCHER)?.[1]

if (!process.env.PATH?.includes(BIN) && currentPath?.includes(BIN)) {
process.env.PATH = `${BIN}${path.delimiter}${process.env.PATH}`
Expand Down Expand Up @@ -213,7 +215,7 @@ customElements.define('system-status', class extends HTMLElement {
throw new Error('Failed to query user PATH.')
}

const originalPath = pathQuery.stdout.toString()?.match(/REG_SZ\s+([^\r\n]+)\r?\n/)?.[1]
const originalPath = pathQuery.stdout.toString()?.match(WIN_REGVAL_MATCHER)?.[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 22cd6c3

Please sign in to comment.