Skip to content

Commit 06e33d2

Browse files
edvardchenjdneo
authored andcommitted
1 parent 7ca9b8a commit 06e33d2

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/leetCodeManager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as vscode from "vscode";
77
import { leetCodeChannel } from "./leetCodeChannel";
88
import { leetCodeExecutor } from "./leetCodeExecutor";
99
import { UserStatus } from "./shared";
10+
import { createEnvOption } from "./utils/cpUtils";
1011
import { DialogType, promptForOpenOutputChannel } from "./utils/uiUtils";
1112
import * as wsl from "./utils/wslUtils";
1213

@@ -42,7 +43,10 @@ class LeetCodeManager extends EventEmitter {
4243

4344
const childProc: cp.ChildProcess = wsl.useWsl()
4445
? cp.spawn("wsl", ["node", leetCodeBinaryPath, "user", "-l"], { shell: true })
45-
: cp.spawn("node", [leetCodeBinaryPath, "user", "-l"], { shell: true });
46+
: cp.spawn("node", [leetCodeBinaryPath, "user", "-l"], {
47+
shell: true,
48+
env: createEnvOption(),
49+
});
4650

4751
childProc.stdout.on("data", (data: string | Buffer) => {
4852
data = data.toString();

src/utils/cpUtils.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export async function executeCommand(command: string, args: string[], options: c
99
return new Promise((resolve: (res: string) => void, reject: (e: Error) => void): void => {
1010
let result: string = "";
1111

12-
const childProc: cp.ChildProcess = cp.spawn(command, args, options);
12+
const childProc: cp.ChildProcess = cp.spawn(command, args, { ...options, env: createEnvOption() });
1313

1414
childProc.stdout.on("data", (data: string | Buffer) => {
1515
data = data.toString();
@@ -45,3 +45,18 @@ export async function executeCommandWithProgress(message: string, command: strin
4545
});
4646
return result;
4747
}
48+
49+
// clone process.env and add http proxy
50+
export function createEnvOption(): {} {
51+
const proxy: string | undefined = getHttpAgent();
52+
if (proxy) {
53+
const env: any = Object.create(process.env);
54+
env.http_proxy = proxy;
55+
return env;
56+
}
57+
return process.env;
58+
}
59+
60+
function getHttpAgent(): string | undefined {
61+
return vscode.workspace.getConfiguration("http").get<string>("proxy");
62+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy