Skip to content

Commit ce3e22e

Browse files
committed
Refactor Docker gateway IP retrieval to use a dedicated shell command execution function
1 parent 71795d5 commit ce3e22e

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

src/services/browser/browserDiscovery.ts

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -55,32 +55,25 @@ export async function tryConnect(ipAddress: string): Promise<{ endpoint: string;
5555
}
5656

5757
/**
58-
* Get Docker gateway IP
58+
* Execute a shell command and return stdout and stderr
59+
*/
60+
export async function executeShellCommand(command: string): Promise<{ stdout: string; stderr: string }> {
61+
return new Promise<{ stdout: string; stderr: string }>((resolve) => {
62+
const cp = require("child_process")
63+
cp.exec(command, (err: any, stdout: string, stderr: string) => {
64+
resolve({ stdout, stderr })
65+
})
66+
})
67+
}
68+
69+
/**
70+
* Get Docker gateway IP without UI feedback
5971
*/
6072
export async function getDockerGatewayIP(): Promise<string | null> {
6173
try {
62-
// Try to get the default gateway from the route table
6374
if (process.platform === "linux") {
6475
try {
65-
const { stdout } = await vscode.window.withProgress(
66-
{
67-
location: vscode.ProgressLocation.Notification,
68-
title: "Checking Docker gateway IP",
69-
cancellable: false,
70-
},
71-
async () => {
72-
const result = await new Promise<{ stdout: string; stderr: string }>((resolve) => {
73-
const cp = require("child_process")
74-
cp.exec(
75-
"ip route | grep default | awk '{print $3}'",
76-
(err: any, stdout: string, stderr: string) => {
77-
resolve({ stdout, stderr })
78-
},
79-
)
80-
})
81-
return result
82-
},
83-
)
76+
const { stdout } = await executeShellCommand("ip route | grep default | awk '{print $3}'")
8477
return stdout.trim()
8578
} catch (error) {
8679
console.log("Could not determine Docker gateway IP:", error)
@@ -159,7 +152,7 @@ export async function discoverChromeInstances(): Promise<string | null> {
159152
ipAddresses.push("localhost")
160153
ipAddresses.push("127.0.0.1")
161154

162-
// Try to get Docker gateway IP
155+
// Try to get Docker gateway IP (headless mode)
163156
const gatewayIP = await getDockerGatewayIP()
164157
if (gatewayIP) {
165158
console.log("Found Docker gateway IP:", gatewayIP)

0 commit comments

Comments
 (0)