From 2f1be7abca85c679499750e9e6e06aebcd06898a Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 1 Jun 2026 15:32:47 +0000 Subject: [PATCH] Add --path option and detect new install layouts --- README.md | 4 ++++ index.js | 42 +++++++++++++++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c415d15..c5c9767 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,9 @@ node . start # Restore original (if needed) node . restore + +# Specify a custom install path (e.g. Program Files) +node . patch --path "C:\Program Files\HTTP Toolkit" ``` ## How it works @@ -38,6 +41,7 @@ node . restore - Creates a backup at `app.asar.bak` before patching - You can set a custom proxy with the `PROXY` environment variable +- Use `--path` to point at a non-default install location; auto-detection also covers `Program Files` and the newer `Programs\httptoolkit\HTTP Toolkit` layout on Windows - Works offline after first run (caches UI files locally) ## License diff --git a/index.js b/index.js index db09ac2..8c6de3d 100644 --- a/index.js +++ b/index.js @@ -14,6 +14,10 @@ const argv = await yargs(process.argv.slice(2)) .command('patch', 'Patch HTTP Toolkit using the specified script') .command('restore', 'Restore HTTP Toolkit files to their original state') .command('start', 'Start HTTP Toolkit') + .option('path', { + type: 'string', + describe: 'Path to the HTTP Toolkit installation (the install dir or its resources folder)' + }) .demandCommand(1, 'You need at least one command before moving on') .alias('h', 'help') .parse() @@ -26,17 +30,37 @@ const pm = userAgent ? userAgent.split('/')[0] : 'npm' const installCmd = pm === 'npm' ? 'install' : 'add' // Try to find where HTTP Toolkit is installed -const appPath = - isWin ? path.join(process.env.LOCALAPPDATA ?? '', 'Programs', 'httptoolkit', 'resources') - : isMac ? '/Applications/HTTP Toolkit.app/Contents/Resources' - : fs.existsSync('/opt/HTTP Toolkit/resources') ? '/opt/HTTP Toolkit/resources' - : '/opt/httptoolkit/resources' +const getAppPath = () => { + if (argv.path) { + return /resources$/i.test(argv.path) ? argv.path : path.join(argv.path, isMac ? 'Contents/Resources' : 'resources') + } + const localAppData = process.env.LOCALAPPDATA ?? '' + const candidates = isWin + ? [ + path.join(localAppData, 'Programs', 'httptoolkit', 'HTTP Toolkit', 'resources'), // current default + path.join(localAppData, 'Programs', 'httptoolkit', 'resources'), // older default + path.join(process.env.PROGRAMFILES ?? '', 'HTTP Toolkit', 'resources'), + path.join(process.env['PROGRAMFILES(X86)'] ?? '', 'HTTP Toolkit', 'resources') + ] + : isMac + ? ['/Applications/HTTP Toolkit.app/Contents/Resources'] + : [ + '/opt/HTTP Toolkit/resources', + '/opt/httptoolkit/resources', + '/usr/lib/httptoolkit' + ] + for (const p of candidates) { + if (p && fs.existsSync(path.join(p, 'app.asar'))) return p + } + return candidates[0] +} + +const appPath = getAppPath() const exePath = - isWin ? path.join(process.env.LOCALAPPDATA ?? '', 'Programs', 'httptoolkit', 'HTTP Toolkit.exe') - : isMac ? '/Applications/HTTP Toolkit.app/Contents/MacOS/HTTP Toolkit' - : fs.existsSync('/opt/HTTP Toolkit/httptoolkit') ? '/opt/HTTP Toolkit/httptoolkit' - : '/opt/httptoolkit/httptoolkit' + isWin ? path.join(path.dirname(appPath), 'HTTP Toolkit.exe') + : isMac ? path.join(path.dirname(appPath), 'MacOS', 'HTTP Toolkit') + : path.join(path.dirname(appPath), 'httptoolkit') const isSudo = !isWin && (process.getuid || (() => process.env.SUDO_UID ? 0 : null))() === 0