Skip to content

Commit 9ad5c86

Browse files
committed
Be more flexible in Electron launch paths for .app bundles
Previously, we needed the exact executable path, or the app path. Now we also accept the app base name (/Applications/Slack) even if the real path is .app, because that extension is hidden on Mac. This is useful because we're going to have to move to manually entering app paths on Mac, since in recent Electron versions the file picker no longer works for selecting inside .app bundles.
1 parent e107327 commit 9ad5c86

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/interceptors/electron.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Interceptor } from '.';
1111
import { HtkConfig } from '../config';
1212
import { delay } from '../util/promise';
1313
import { isErrorLike } from '../util/error';
14-
import { readFile } from '../util/fs';
14+
import { canAccess, readFile } from '../util/fs';
1515
import { windowsClose } from '../util/process-management';
1616
import { getTerminalEnvVars, OVERRIDES_DIR } from './terminal/terminal-env-overrides';
1717
import { reportError, addBreadcrumb } from '../error-tracking';
@@ -22,6 +22,13 @@ const isAppBundle = (path: string) => {
2222
path.endsWith(".app");
2323
};
2424

25+
// Returns true if this path is wrong, but path.app is a real app bundle.
26+
const shouldBeAppBundle = async (path: string) => {
27+
if (process.platform !== 'darwin') return false;
28+
if (await canAccess(path)) return false;
29+
return canAccess(path + '.app');
30+
}
31+
2532
export class ElectronInterceptor implements Interceptor {
2633
readonly id = 'electron';
2734
readonly version = '1.0.1';
@@ -49,9 +56,14 @@ export class ElectronInterceptor implements Interceptor {
4956
const debugPort = await getPort({ port: proxyPort });
5057
const { pathToApplication } = options;
5158

59+
// We're very flexible with paths for app bundles, because on Mac in reality most people
60+
// never see the executable itself, except when developing their own Electron apps.
5261
const cmd = isAppBundle(pathToApplication)
53-
? await findExecutableInApp(pathToApplication)
54-
: pathToApplication;
62+
? await findExecutableInApp(pathToApplication)
63+
: await shouldBeAppBundle(pathToApplication)
64+
? await findExecutableInApp(pathToApplication + '.app')
65+
// Non-darwin, or darwin with a full path to the binary:
66+
: pathToApplication;
5567

5668
const appProcess = spawn(cmd, [`--inspect-brk=${debugPort}`], {
5769
stdio: 'inherit',

0 commit comments

Comments
 (0)