Skip to content

Commit bdfe1e4

Browse files
committed
set proxy header
1 parent eb61fe2 commit bdfe1e4

4 files changed

Lines changed: 115 additions & 33 deletions

File tree

.gitignore

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/node_modules
22
/out
33
/out.min
4-
src/Telemetry/
54
vsc-extension-quickstart.md
65
*.vsix
76
.EIDE
@@ -12,11 +11,18 @@ vsc-extension-quickstart.md
1211
pack.js
1312
test.js
1413
*.js.map
15-
**/data/config.json
16-
**/data/sln.record
1714
*.cpuprofile
1815
package-lock.json
1916

17+
# private
18+
/src/Telemetry
19+
/src/Private
20+
21+
# eide vars
22+
/res/data/config.json
23+
/res/data/sln.record
24+
/res/data/data.yaml
25+
2026
# internal template projects
2127
res/template/projects
2228

src/ResManager.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ export class ResManager extends events.EventEmitter {
140140
return resManager;
141141
}
142142

143+
static instance(): ResManager {
144+
return ResManager.GetInstance();
145+
}
146+
143147
static getLocalCodePage(): string | undefined {
144148
return codePage;
145149
}
@@ -223,6 +227,29 @@ export class ResManager extends events.EventEmitter {
223227
return this.appConfig;
224228
}
225229

230+
getAppUsrData(): { [key: string]: any } | undefined {
231+
232+
const dataFile = File.fromArray([this.GetAppDataDir().path, 'data.yaml']);
233+
234+
if (dataFile.IsFile()) {
235+
try {
236+
return yaml.parse(dataFile.Read());
237+
} catch (error) {
238+
// nothing todo
239+
}
240+
}
241+
}
242+
243+
setAppUsrData(key: string, val: any): void {
244+
245+
let data = this.getAppUsrData() || {};
246+
247+
data[key] = val;
248+
249+
File.fromArray([this.GetAppDataDir().path, 'data.yaml'])
250+
.Write(yaml.stringify(data));
251+
}
252+
226253
//=====================
227254

228255
getCache(name: string): FileCacheInfo | undefined {

src/extension.ts

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,12 @@ export async function activate(context: vscode.ExtensionContext) {
259259
// load project in this workspace
260260
projectExplorer.loadWorkspace();
261261

262+
// hook
263+
postLaunchHook(context);
264+
262265
// launch done
263266
GlobalEvent.emit('extension_launch_done');
264267
GlobalEvent.emit('globalLog', newMessage('Info', 'Embedded IDE launch done'));
265-
266-
// refresh external tools now
267-
ResInstaller.instance().refreshExternalToolsIndex().catch(err => {
268-
GlobalEvent.emit('globalLog', ExceptionToMessage(err, 'Warning'));
269-
});
270268
}
271269

272270
// this method is called when your extension is deactivated
@@ -275,6 +273,32 @@ export function deactivate() {
275273
StatusBarManager.getInstance().disposeAll();
276274
}
277275

276+
function postLaunchHook(extensionCtx: vscode.ExtensionContext) {
277+
278+
const resManager = ResManager.instance();
279+
const appUsrData = resManager.getAppUsrData() || {};
280+
const isFirstLaunch = appUsrData['InstallTime'] == undefined;
281+
282+
// is first launch ?
283+
if (isFirstLaunch) {
284+
285+
// setup install time
286+
resManager.setAppUsrData('InstallTime', Date.now().toString());
287+
288+
// only enable github proxy for GMT+8:00 by default
289+
const timeZone = Math.floor((new Date().getTimezoneOffset() / 60) * -1);
290+
if (timeZone != 8) {
291+
// disable settings: 'EIDE.Repository.UseProxy'
292+
SettingManager.GetInstance().setConfigValue('Repository.UseProxy', false);
293+
}
294+
}
295+
296+
// refresh external tools now
297+
ResInstaller.instance().refreshExternalToolsIndex().catch(err => {
298+
GlobalEvent.emit('globalLog', ExceptionToMessage(err, 'Warning'));
299+
});
300+
}
301+
278302
//////////////////////////////////////////////////
279303
// internal vsc-commands funcs
280304
//////////////////////////////////////////////////
@@ -704,14 +728,16 @@ async function tryInstallBinaries(binFolder: File, binVersion: string): Promise<
704728

705729
let isEnvSetuped: boolean = false;
706730

707-
function exportEnvToSysPath() {
731+
let isExport2ExtensionCtx = false;
732+
733+
function exportEnvToSysPath(context?: vscode.ExtensionContext) {
708734

709735
const settingManager = SettingManager.GetInstance();
710736
const resManager = ResManager.GetInstance();
711737
const builderFolder = resManager.getBuilderDir();
712738

713739
// export some eide binaries path to system env path
714-
const defEnvPath: string[] = [
740+
const systemEnvPaths: string[] = [
715741
File.normalize(`${builderFolder.path}/bin`), // builder bin folder
716742
File.normalize(`${builderFolder.path}/utils`), // utils tool folder
717743
File.normalize(`${builderFolder.dir}/scripts`),
@@ -802,22 +828,20 @@ function exportEnvToSysPath() {
802828
}
803829
});
804830

831+
// append all tools to system env paths
832+
pathList
833+
.filter((env) => File.IsDir(env.path))
834+
.forEach(envInfo => {
835+
systemEnvPaths.push(envInfo.path);
836+
if (envInfo.extraPath) {
837+
envInfo.extraPath.forEach(p => systemEnvPaths.push(p));
838+
}
839+
});
840+
805841
/* append to System Path if we not */
806842
if (isEnvSetuped == false) {
807-
808-
// append all tools env paths
809-
pathList
810-
.filter((env) => File.IsDir(env.path))
811-
.forEach(envInfo => {
812-
defEnvPath.push(envInfo.path);
813-
if (envInfo.extraPath) {
814-
envInfo.extraPath.forEach(p => defEnvPath.push(p));
815-
}
816-
});
817-
818-
// apply to system env path
819-
platform.prependToSysEnv(process.env, defEnvPath);
820843
isEnvSetuped = true;
844+
platform.prependToSysEnv(process.env, systemEnvPaths);
821845
}
822846

823847
/* update env key value */
@@ -833,6 +857,24 @@ function exportEnvToSysPath() {
833857
// 你可通过使用喜欢的 shell 将 DOTNET_CLI_TELEMETRY_OPTOUT 环境变量设置为 "1" 或 "true" 来选择退出遥测。
834858
// 阅读有关 .NET CLI 工具遥测的更多信息: https://aka.ms/dotnet-cli-telemetry
835859
process.env['DOTNET_CLI_TELEMETRY_OPTOUT'] = '1'; // disable telemetry
860+
861+
//
862+
// export to vscode extension envs
863+
//
864+
if (context && !isExport2ExtensionCtx) {
865+
866+
isExport2ExtensionCtx = true;
867+
868+
context.environmentVariableCollection.persistent = false;
869+
870+
context.environmentVariableCollection.prepend('DOTNET_CLI_TELEMETRY_OPTOUT', '1');
871+
872+
for (const env of pathList) {
873+
if (File.IsDir(env.path)) {
874+
context.environmentVariableCollection.append(env.key, env.path);
875+
}
876+
}
877+
}
836878
}
837879

838880
async function checkAndInstallRuntime() {
@@ -1033,15 +1075,15 @@ async function InitComponents(context: vscode.ExtensionContext): Promise<boolean
10331075
// register telemetry hook if user enabled
10341076
try {
10351077
if (settingManager.isEnableTelemetry()) {
1036-
const TelemetryTask = require('./Telemetry/TelemetryTask');
1078+
const TelemetryTask = require('./Private/TelemetryTask');
10371079
TelemetryTask.registerTelemetryHook();
10381080
}
10391081
} catch (error) {
10401082
// ignore error
10411083
}
10421084

10431085
// set some toolpath to env
1044-
exportEnvToSysPath();
1086+
exportEnvToSysPath(context);
10451087

10461088
// init status bar
10471089
{

src/utility.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,21 +288,21 @@ export function wrapCommand(cmds: string[]): string {
288288
}).join(' ');
289289
}
290290

291-
export function md5(str: string): string {
291+
export function md5(str_or_buff: string | Buffer): string {
292292
const md5 = crypto.createHash('md5');
293-
md5.update(str);
293+
md5.update(str_or_buff);
294294
return md5.digest('hex');
295295
}
296296

297-
export function sha256(str: string): string {
297+
export function sha256(str_or_buff: string | Buffer): string {
298298
const md5 = crypto.createHash('sha256');
299-
md5.update(str);
299+
md5.update(str_or_buff);
300300
return md5.digest('hex');
301301
}
302302

303-
export function sha1(str: string): string {
303+
export function sha1(str_or_buff: string | Buffer): string {
304304
const md5 = crypto.createHash('sha1');
305-
md5.update(str);
305+
md5.update(str_or_buff);
306306
return md5.digest('hex');
307307
}
308308

@@ -372,8 +372,15 @@ export function redirectHost(url: string) {
372372
return url;
373373
}
374374

375-
export function setProxyHeader(headers: { [key: string]: string }): { [key: string]: string } {
376-
// TODO
375+
export function setProxyHeader(headers: { [key: string]: string | undefined }): { [key: string]: string | undefined } {
376+
377+
try {
378+
const proxyUtils = require('./Private/GithubProxy');
379+
proxyUtils.setProxyHeader(headers);
380+
} catch (error) {
381+
// ignore error
382+
}
383+
377384
return headers;
378385
}
379386

0 commit comments

Comments
 (0)