11import * as http from 'http' ;
22import * as path from 'path' ;
3+ import { execFile } from 'child_process' ;
4+ import { promisify } from 'util' ;
35
46import { getDeferred } from '@httptoolkit/util' ;
57
68import { getSocketPath } from './ui-operation-bridge' ;
79
10+ const execFileAsync = promisify ( execFile ) ;
11+ let darwinTempDirPromise : Promise < string | undefined > | undefined ;
12+
13+ function getDarwinTempDir ( ) : Promise < string | undefined > {
14+ if ( ! darwinTempDirPromise ) {
15+ darwinTempDirPromise = execFileAsync (
16+ '/usr/bin/getconf' ,
17+ [ 'DARWIN_USER_TEMP_DIR' ] ,
18+ { encoding : 'utf8' , timeout : 1000 }
19+ )
20+ . then ( ( { stdout } ) => stdout . trim ( ) || undefined )
21+ . catch ( ( ) => undefined ) ;
22+ }
23+
24+ return darwinTempDirPromise ;
25+ }
26+
827export async function apiRequest (
928 method : 'GET' | 'POST' ,
1029 urlPath : string ,
@@ -22,6 +41,15 @@ export async function apiRequest(
2241 `${ process . getuid ( ) } ` ,
2342 'httptoolkit-ctl.sock'
2443 ) ) ;
44+ } else if ( process . platform === 'darwin' ) {
45+ const darwinTempDir = await getDarwinTempDir ( ) ;
46+ const darwinSocketPath = darwinTempDir
47+ ? path . join ( darwinTempDir , 'httptoolkit-ctl.sock' )
48+ : undefined ;
49+
50+ if ( darwinSocketPath && ! socketPaths . includes ( darwinSocketPath ) ) {
51+ socketPaths . push ( darwinSocketPath ) ;
52+ }
2553 }
2654
2755 for ( let i = 0 ; i < socketPaths . length ; i ++ ) {
0 commit comments