Skip to content

Commit

Permalink
Be more flexible in Electron launch paths for .app bundles
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pimterry committed Aug 17, 2022
1 parent e107327 commit 9ad5c86
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/interceptors/electron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Interceptor } from '.';
import { HtkConfig } from '../config';
import { delay } from '../util/promise';
import { isErrorLike } from '../util/error';
import { readFile } from '../util/fs';
import { canAccess, readFile } from '../util/fs';
import { windowsClose } from '../util/process-management';
import { getTerminalEnvVars, OVERRIDES_DIR } from './terminal/terminal-env-overrides';
import { reportError, addBreadcrumb } from '../error-tracking';
Expand All @@ -22,6 +22,13 @@ const isAppBundle = (path: string) => {
path.endsWith(".app");
};

// Returns true if this path is wrong, but path.app is a real app bundle.
const shouldBeAppBundle = async (path: string) => {
if (process.platform !== 'darwin') return false;
if (await canAccess(path)) return false;
return canAccess(path + '.app');
}

export class ElectronInterceptor implements Interceptor {
readonly id = 'electron';
readonly version = '1.0.1';
Expand Down Expand Up @@ -49,9 +56,14 @@ export class ElectronInterceptor implements Interceptor {
const debugPort = await getPort({ port: proxyPort });
const { pathToApplication } = options;

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

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

0 comments on commit 9ad5c86

Please sign in to comment.