Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Pass http proxy as env to command (fix #136, #117)#147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jdneo merged 4 commits intoLeetCode-OpenSource:masterfromedvardchen:fix-proxy-issue
Feb 24, 2019
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletionsrc/leetCodeManager.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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";

Expand DownExpand Up@@ -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();
Expand Down
17 changes: 16 additions & 1 deletionsrc/utils/cpUtils.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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();
Expand DownExpand Up@@ -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<string>("proxy");
}

[8]ページ先頭

©2009-2025 Movatter.jp