diff --git a/src/leetCodeManager.ts b/src/leetCodeManager.ts index 0456d2d1..1db3f5e2 100644 --- a/src/leetCodeManager.ts +++ b/src/leetCodeManager.ts @@ -7,6 +7,7 @@ import * as vscode from "vscode"; import { leetCodeChannel } from "./leetCodeChannel"; import { leetCodeExecutor } from "./leetCodeExecutor"; import { UserStatus } from "./shared"; +import { createEnvOption } from "./utils/cpUtils"; import { DialogType, promptForOpenOutputChannel } from "./utils/uiUtils"; import * as wsl from "./utils/wslUtils"; @@ -42,7 +43,10 @@ class LeetCodeManager extends EventEmitter { const childProc: cp.ChildProcess = wsl.useWsl() ? cp.spawn("wsl", ["node", leetCodeBinaryPath, "user", "-l"], { shell: true }) - : cp.spawn("node", [leetCodeBinaryPath, "user", "-l"], { shell: true }); + : cp.spawn("node", [leetCodeBinaryPath, "user", "-l"], { + shell: true, + env: createEnvOption(), + }); childProc.stdout.on("data", (data: string | Buffer) => { data = data.toString(); diff --git a/src/utils/cpUtils.ts b/src/utils/cpUtils.ts index eeb7c007..6e265e48 100644 --- a/src/utils/cpUtils.ts +++ b/src/utils/cpUtils.ts @@ -9,7 +9,7 @@ export async function executeCommand(command: string, args: string[], options: c return new Promise((resolve: (res: string) => void, reject: (e: Error) => void): void => { let result: string = ""; - const childProc: cp.ChildProcess = cp.spawn(command, args, options); + const childProc: cp.ChildProcess = cp.spawn(command, args, { ...options, env: createEnvOption() }); childProc.stdout.on("data", (data: string | Buffer) => { data = data.toString(); @@ -45,3 +45,18 @@ export async function executeCommandWithProgress(message: string, command: strin }); return result; } + +// clone process.env and add http proxy +export function createEnvOption(): {} { + const proxy: string | undefined = getHttpAgent(); + if (proxy) { + const env: any = Object.create(process.env); + env.http_proxy = proxy; + return env; + } + return process.env; +} + +function getHttpAgent(): string | undefined { + return vscode.workspace.getConfiguration("http").get("proxy"); +}