44 *--------------------------------------------------------------------------------------------*/
55
66import { ChildProcess , spawn , SpawnOptions , StdioOptions } from 'child_process' ;
7- import { chmodSync , existsSync , readFileSync , statSync , truncateSync , unlinkSync , promises } from 'fs' ;
7+ import { chmodSync , existsSync , readFileSync , statSync , truncateSync , unlinkSync } from 'fs' ;
88import { homedir , tmpdir } from 'os' ;
99import type { ProfilingSession , Target } from 'v8-inspect-profiler' ;
1010import { Event } from '../../base/common/event.js' ;
@@ -20,6 +20,7 @@ import { addArg, parseCLIProcessArgv } from '../../platform/environment/node/arg
2020import { getStdinFilePath , hasStdinWithoutTty , readFromStdin , stdinDataListener } from '../../platform/environment/node/stdin.js' ;
2121import { createWaitMarkerFileSync } from '../../platform/environment/node/wait.js' ;
2222import product from '../../platform/product/common/product.js' ;
23+ import { resolveSiblingWindowsExePath } from '../../platform/native/node/siblingApp.js' ;
2324import { CancellationTokenSource } from '../../base/common/cancellation.js' ;
2425import { isUNC , randomPath } from '../../base/common/extpath.js' ;
2526import { Utils } from '../../platform/profiling/common/profiling.js' ;
@@ -487,15 +488,11 @@ export async function main(argv: string[]): Promise<void> {
487488
488489 // Figure out the app to launch: with --agents we try to launch the embedded app on Windows
489490 let execToLaunch = process . execPath ;
490- if ( isWindows && args . agents && product . win32SiblingExeBasename ) {
491- const siblingExe = join ( dirname ( process . execPath ) , `${ product . win32SiblingExeBasename } .exe` ) ;
492- try {
493- if ( statSync ( siblingExe ) . isFile ( ) ) {
494- execToLaunch = siblingExe ;
495- argv = argv . filter ( arg => arg !== '--agents' ) ;
496- }
497- } catch ( error ) {
498- /* may not exist on disk */
491+ if ( isWindows && args . agents ) {
492+ const siblingExe = resolveSiblingWindowsExePath ( product ) ;
493+ if ( siblingExe ) {
494+ execToLaunch = siblingExe ;
495+ argv = argv . filter ( arg => arg !== '--agents' ) ;
499496 }
500497 }
501498
@@ -516,24 +513,12 @@ export async function main(argv: string[]): Promise<void> {
516513 const spawnArgs = [ '-n' , '-g' ] ;
517514
518515 // Figure out the app to launch: with --agents we try to launch the embedded app
519- let appToLaunch = process . execPath ;
520- if ( args . agents ) {
521- // process.execPath is e.g. /Applications/Code.app/Contents/MacOS/Electron
522- // Embedded app is at /Applications/Code.app/Contents/Applications/<EmbeddedApp>.app
523- const contentsPath = dirname ( dirname ( process . execPath ) ) ;
524- const applicationsPath = join ( contentsPath , 'Applications' ) ;
525- try {
526- const files = await promises . readdir ( applicationsPath ) ;
527- const embeddedApp = files . find ( file => file . endsWith ( '.app' ) ) ;
528- if ( embeddedApp ) {
529- appToLaunch = join ( applicationsPath , embeddedApp ) ;
530- argv = argv . filter ( arg => arg !== '--agents' ) ;
531- }
532- } catch ( error ) {
533- /* may not exist on disk */
534- }
516+ if ( args . agents && product . darwinSiblingBundleIdentifier ) {
517+ spawnArgs . push ( '-b' , product . darwinSiblingBundleIdentifier ) ;
518+ argv = argv . filter ( arg => arg !== '--agents' ) ;
519+ } else {
520+ spawnArgs . push ( '-a' , process . execPath ) ; // -a opens the given application.
535521 }
536- spawnArgs . push ( '-a' , appToLaunch ) ; // -a opens the given application.
537522
538523 if ( args . verbose || args . status ) {
539524 spawnArgs . push ( '--wait-apps' ) ; // `open --wait-apps`: blocks until the launched app is closed (even if they were already running)
0 commit comments