@@ -35,23 +35,17 @@ const APP_BUNDLE_INFO_PLIST = 'Contents/Info.plist';
3535const LSAPPINFO_ASN = / A S N : / ;
3636
3737/**
38- * The bundle path of the one running copy of `bundleId` that LaunchServices lists, which `open`
39- * must name instead of the bundle id, after waiting out the registration race (#3406). Undefined
40- * leaves the open to `open -b`.
41- *
42- * `open -b` opens the copy LaunchServices resolves the bundle id to, which is not always the one
43- * running: when several copies of the bundle are registered, such as successive dev builds at
44- * different paths, it can launch a stale build with no arguments next to the running one. Naming
45- * the running copy's own path attaches to it.
38+ * The bundle path of the one running copy of `bundleId` that LaunchServices lists, or undefined to
39+ * leave the open to `open -b`. `open -b` opens the copy LaunchServices resolves the bundle id to,
40+ * which can be a stale build registered at another path rather than the running copy.
4641 *
4742 * A copy started directly — by a supervisor or a dev script — is only listed by LaunchServices
48- * about half a second after it spawns. While it is unlisted, `open` sees no instance and launches
49- * a second one with no arguments, which the session then drives instead of the copy the caller
50- * owns. So the copy is only named once LaunchServices lists it. An open with no running copy pays
51- * one `lsappinfo find` and one process-table read (plus a bundle-identifier read only when
52- * app-shaped candidates exist) to learn that; an open of a running copy pays the bundle-identifier
53- * read as well; only a copy that runs while unlisted is waited for. Every read shares one budget,
54- * and the wait itself stays well inside it:
43+ * about half a second after it spawns (#3406). While it is unlisted, `open` sees no instance and
44+ * launches a second one with no arguments, which the session then drives instead of the copy the
45+ * caller owns. An open with no running copy pays one `lsappinfo find` and one process-table read
46+ * (plus a bundle-identifier read only when app-shaped candidates exist) to learn that; an open of a
47+ * running copy pays the bundle-identifier read as well; only a copy that runs while unlisted is
48+ * waited for. Every read shares one budget, and the wait itself stays well inside it:
5549 *
5650 * - `LAUNCH_SERVICES_PROBE_BUDGET_MS` bounds every read below, each read also taking its own
5751 * smaller cap so a single hung tool cannot consume the budget alone;
@@ -78,7 +72,6 @@ export async function resolveListedRunningBundle(
7872 ) {
7973 return undefined ;
8074 }
81- // Copies at several paths leave the choice to LaunchServices, as `open -b` always did.
8275 return running . size === 1 ? [ ...running . keys ( ) ] [ 0 ] : undefined ;
8376 } catch ( error ) {
8477 // The probe is an extra read on someone else's app launch, so a host that cannot answer it at
@@ -96,7 +89,6 @@ export async function resolveListedRunningBundle(
9689 }
9790}
9891
99- /** Whether LaunchServices came to list one of `pids` before the wait's bounds ran out. */
10092async function waitForListing (
10193 runCommand : AppleToolCommandExecutor ,
10294 bundleId : string ,
@@ -154,10 +146,6 @@ async function readsLaunchServicesInstance(
154146 return LSAPPINFO_ASN . test ( result . stdout ) ;
155147}
156148
157- /**
158- * The processes running `bundleId`, by the app bundle path each one runs from. Identifiers compare
159- * without regard to case, as LaunchServices compares them.
160- */
161149async function findRunningInstances (
162150 runCommand : AppleToolCommandExecutor ,
163151 bundleId : string ,
@@ -198,6 +186,7 @@ async function findRunningInstances(
198186 return new Map (
199187 bundlePaths
200188 . filter (
189+ // LaunchServices compares bundle identifiers without regard to case.
201190 ( bundlePath ) =>
202191 bundleIds . get ( path . join ( bundlePath , APP_BUNDLE_INFO_PLIST ) ) ?. trim ( ) . toLowerCase ( ) ===
203192 bundleId . toLowerCase ( ) ,
@@ -213,6 +202,7 @@ async function findRunningInstances(
213202 * XPC services, app extensions, and driver bundles, whose identifiers match no app anyone opens.
214203 */
215204function macAppBundlePath ( command : string ) : string | undefined {
205+ if ( ! path . isAbsolute ( command ) ) return undefined ;
216206 const marker = command . indexOf ( APP_EXECUTABLE_MARKER ) ;
217207 if ( marker <= 0 ) return undefined ;
218208 const bundlePath = command . slice ( 0 , marker ) ;
0 commit comments