From 9ad5c86cc294e505cd47cf1f153f3e3f006d97e3 Mon Sep 17 00:00:00 2001 From: Tim Perry Date: Wed, 17 Aug 2022 16:05:25 +0200 Subject: [PATCH] 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. --- src/interceptors/electron.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/interceptors/electron.ts b/src/interceptors/electron.ts index b758fabe..692f5a56 100644 --- a/src/interceptors/electron.ts +++ b/src/interceptors/electron.ts @@ -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'; @@ -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'; @@ -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',