Browse Source

Refactor Docker gateway IP retrieval to use a dedicated shell command execution function

Afshawn Lotfi 10 months ago
parent
commit
ce3e22ecfe
1 changed files with 15 additions and 22 deletions
  1. 15 22
      src/services/browser/browserDiscovery.ts

+ 15 - 22
src/services/browser/browserDiscovery.ts

@@ -55,32 +55,25 @@ export async function tryConnect(ipAddress: string): Promise<{ endpoint: string;
 }
 }
 
 
 /**
 /**
- * Get Docker gateway IP
+ * Execute a shell command and return stdout and stderr
+ */
+export async function executeShellCommand(command: string): Promise<{ stdout: string; stderr: string }> {
+	return new Promise<{ stdout: string; stderr: string }>((resolve) => {
+		const cp = require("child_process")
+		cp.exec(command, (err: any, stdout: string, stderr: string) => {
+			resolve({ stdout, stderr })
+		})
+	})
+}
+
+/**
+ * Get Docker gateway IP without UI feedback
  */
  */
 export async function getDockerGatewayIP(): Promise<string | null> {
 export async function getDockerGatewayIP(): Promise<string | null> {
 	try {
 	try {
-		// Try to get the default gateway from the route table
 		if (process.platform === "linux") {
 		if (process.platform === "linux") {
 			try {
 			try {
-				const { stdout } = await vscode.window.withProgress(
-					{
-						location: vscode.ProgressLocation.Notification,
-						title: "Checking Docker gateway IP",
-						cancellable: false,
-					},
-					async () => {
-						const result = await new Promise<{ stdout: string; stderr: string }>((resolve) => {
-							const cp = require("child_process")
-							cp.exec(
-								"ip route | grep default | awk '{print $3}'",
-								(err: any, stdout: string, stderr: string) => {
-									resolve({ stdout, stderr })
-								},
-							)
-						})
-						return result
-					},
-				)
+				const { stdout } = await executeShellCommand("ip route | grep default | awk '{print $3}'")
 				return stdout.trim()
 				return stdout.trim()
 			} catch (error) {
 			} catch (error) {
 				console.log("Could not determine Docker gateway IP:", error)
 				console.log("Could not determine Docker gateway IP:", error)
@@ -159,7 +152,7 @@ export async function discoverChromeInstances(): Promise<string | null> {
 	ipAddresses.push("localhost")
 	ipAddresses.push("localhost")
 	ipAddresses.push("127.0.0.1")
 	ipAddresses.push("127.0.0.1")
 
 
-	// Try to get Docker gateway IP
+	// Try to get Docker gateway IP (headless mode)
 	const gatewayIP = await getDockerGatewayIP()
 	const gatewayIP = await getDockerGatewayIP()
 	if (gatewayIP) {
 	if (gatewayIP) {
 		console.log("Found Docker gateway IP:", gatewayIP)
 		console.log("Found Docker gateway IP:", gatewayIP)