|
1 | 1 | import { app, nativeImage } from 'electron' |
| 2 | +// Ensure PATH matches the user's shell when launched from Finder (macOS) |
| 3 | +// so Homebrew/NPM global binaries like `gh` and `codex` are found. |
| 4 | +try { |
| 5 | + // Lazy import to avoid bundler complaints if not present on other platforms |
| 6 | + // We also defensively prepend common Homebrew locations. |
| 7 | + // eslint-disable-next-line @typescript-eslint/no-var-requires |
| 8 | + const fixPath = require('fix-path'); |
| 9 | + if (typeof fixPath === 'function') fixPath(); |
| 10 | +} catch { |
| 11 | + // no-op if fix-path isn't available at runtime |
| 12 | +} |
| 13 | + |
| 14 | +if (process.platform === 'darwin') { |
| 15 | + const extras = ['/opt/homebrew/bin', '/usr/local/bin', '/opt/homebrew/sbin', '/usr/local/sbin']; |
| 16 | + const cur = process.env.PATH || ''; |
| 17 | + const parts = cur.split(':').filter(Boolean); |
| 18 | + for (const p of extras) { |
| 19 | + if (!parts.includes(p)) parts.unshift(p); |
| 20 | + } |
| 21 | + process.env.PATH = parts.join(':'); |
| 22 | + |
| 23 | + // As a last resort, ask the user's login shell for PATH and merge it in. |
| 24 | + try { |
| 25 | + const { execSync } = require('child_process'); |
| 26 | + const shell = process.env.SHELL || '/bin/zsh'; |
| 27 | + const loginPath = execSync(`${shell} -ilc 'echo -n $PATH'`, { encoding: 'utf8' }); |
| 28 | + if (loginPath) { |
| 29 | + const merged = new Set((loginPath + ':' + process.env.PATH).split(':').filter(Boolean)); |
| 30 | + process.env.PATH = Array.from(merged).join(':'); |
| 31 | + } |
| 32 | + } catch {} |
| 33 | +} |
2 | 34 | import { join } from 'path' |
3 | 35 | import { existsSync, readFileSync } from 'fs' |
4 | 36 | import { createMainWindow } from './app/window' |
|
0 commit comments