Skip to content

Commit 466ae7f

Browse files
committed
Support Electron .app bundles on Mac
1 parent 4606cf9 commit 466ae7f

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

custom-typings/osx-find-executable.d.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

package-lock.json

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"bugs": "https://github.com/httptoolkit/httptoolkit-server/issues",
2828
"dependencies": {
2929
"@httptoolkit/browser-launcher": "^1.6.0",
30-
"@httptoolkit/osx-find-executable": "^1.1.2",
30+
"@httptoolkit/osx-find-executable": "^2.0.0",
3131
"@oclif/command": "^1.5.4",
3232
"@oclif/config": "^1.13.3",
3333
"@oclif/plugin-help": "^2.1.3",

src/interceptors/electron.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ import { HtkConfig } from '../config';
1313
import { delay } from '../util';
1414
import { getTerminalEnvVars } from './terminal/terminal-env-overrides';
1515
import { reportError, addBreadcrumb } from '../error-tracking';
16+
import { findExecutableInApp } from '@httptoolkit/osx-find-executable';
1617

1718
const readFile = util.promisify(fs.readFile);
1819

20+
const isAppBundle = (path: string) => {
21+
return process.platform === "darwin" &&
22+
path.endsWith(".app");
23+
};
24+
1925
export class ElectronInterceptor implements Interceptor {
2026
readonly id = 'electron';
2127
readonly version = '1.0.0';
@@ -41,8 +47,13 @@ export class ElectronInterceptor implements Interceptor {
4147
pathToApplication: string
4248
}): Promise<void | {}> {
4349
const debugPort = await getPort({ port: proxyPort });
50+
const { pathToApplication } = options;
51+
52+
const cmd = isAppBundle(pathToApplication)
53+
? await findExecutableInApp(pathToApplication)
54+
: pathToApplication;
4455

45-
spawn(options.pathToApplication, [`--inspect-brk=${debugPort}`], {
56+
spawn(cmd, [`--inspect-brk=${debugPort}`], {
4657
stdio: 'inherit',
4758
env: Object.assign({},
4859
process.env,

src/interceptors/terminal/fresh-terminal-interceptor.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { spawn, ChildProcess, SpawnOptions } from 'child_process';
55
import * as GSettings from 'node-gsettings-wrapper';
66
import * as ensureCommandExists from 'command-exists';
77

8-
import findOsxExecutableCb = require('@httptoolkit/osx-find-executable');
9-
const findOsxExecutable = util.promisify(findOsxExecutableCb);
8+
import { findExecutableById } from '@httptoolkit/osx-find-executable';
109

1110
import { Interceptor } from '..';
1211
import { HtkConfig } from '../../config';
@@ -84,7 +83,7 @@ const getOSXTerminalCommand = async (): Promise<SpawnArgs | null> => {
8483
'com.googlecode.iterm',
8584
'com.apple.Terminal'
8685
].map(
87-
(bundleId) => findOsxExecutable(bundleId).catch(() => null)
86+
(bundleId) => findExecutableById(bundleId).catch(() => null)
8887
)
8988
)).filter((executablePath) => !!executablePath);
9089

0 commit comments

Comments
 (0)