mirror of
https://github.com/microsoft/vscode.git
synced 2026-09-15 07:41:11 +01:00
env - tweak shell resolve experience on startup
This commit is contained in:
@@ -83,7 +83,6 @@ import { VSBuffer } from 'vs/base/common/buffer';
|
||||
import { EncryptionMainService, IEncryptionMainService } from 'vs/platform/encryption/electron-main/encryptionMainService';
|
||||
import { ActiveWindowManager } from 'vs/platform/windows/common/windowTracker';
|
||||
import { IKeyboardLayoutMainService, KeyboardLayoutMainService } from 'vs/platform/keyboardLayout/electron-main/keyboardLayoutMainService';
|
||||
import { toErrorMessage } from 'vs/base/common/errorMessage';
|
||||
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
|
||||
import { DisplayMainService, IDisplayMainService } from 'vs/platform/display/electron-main/displayMainService';
|
||||
import { isLaunchedFromCli } from 'vs/platform/environment/node/argvHelper';
|
||||
@@ -272,45 +271,45 @@ export class CodeApplication extends Disposable {
|
||||
let replied = false;
|
||||
|
||||
function acceptShellEnv(env: NodeJS.ProcessEnv): void {
|
||||
clearTimeout(shellEnvTimeoutWarningHandle);
|
||||
clearTimeout(shellEnvSlowWarningHandle);
|
||||
clearTimeout(shellEnvTimeoutErrorHandle);
|
||||
|
||||
if (!replied) {
|
||||
webContents.send('vscode:acceptShellEnv', env);
|
||||
replied = true;
|
||||
|
||||
if (!webContents.isDestroyed()) {
|
||||
webContents.send('vscode:acceptShellEnv', env);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const shellEnvTimeoutWarningHandle = setTimeout(function () {
|
||||
window?.sendWhenReady('vscode:showShellEnvTimeoutWarning'); // notify inside window if we have one
|
||||
// Handle slow shell environment resolve calls:
|
||||
// - a warning after 3s but continue to resolve
|
||||
// - an error after 10s and stop trying to resolve
|
||||
const shellEnvSlowWarningHandle = setTimeout(() => window?.sendWhenReady('vscode:showShellEnvSlowWarning'), 3000);
|
||||
const shellEnvTimeoutErrorHandle = setTimeout(function () {
|
||||
window?.sendWhenReady('vscode:showShellEnvTimeoutError');
|
||||
acceptShellEnv({});
|
||||
}, 10000);
|
||||
|
||||
try {
|
||||
|
||||
// Prefer to use the args and env from the target window
|
||||
// when resolving the shell env. It is possible that
|
||||
// a first window was opened from the UI but a second
|
||||
// from the CLI and that has implications for wether to
|
||||
// resolve the shell environment or not.
|
||||
let args: NativeParsedArgs;
|
||||
let env: NodeJS.ProcessEnv;
|
||||
if (window?.config) {
|
||||
args = window.config;
|
||||
env = { ...process.env, ...window.config.userEnv };
|
||||
} else {
|
||||
args = this.environmentService.args;
|
||||
env = process.env;
|
||||
}
|
||||
|
||||
// Resolve shell env
|
||||
const shellEnv = await resolveShellEnv(this.logService, args, env);
|
||||
acceptShellEnv(shellEnv);
|
||||
} catch (error) {
|
||||
window?.sendWhenReady('vscode:showShellEnvError', toErrorMessage(error)); // notify inside window if we have one
|
||||
acceptShellEnv({});
|
||||
|
||||
this.logService.error('Error fetching shell env', error);
|
||||
// Prefer to use the args and env from the target window
|
||||
// when resolving the shell env. It is possible that
|
||||
// a first window was opened from the UI but a second
|
||||
// from the CLI and that has implications for wether to
|
||||
// resolve the shell environment or not.
|
||||
let args: NativeParsedArgs;
|
||||
let env: NodeJS.ProcessEnv;
|
||||
if (window?.config) {
|
||||
args = window.config;
|
||||
env = { ...process.env, ...window.config.userEnv };
|
||||
} else {
|
||||
args = this.environmentService.args;
|
||||
env = process.env;
|
||||
}
|
||||
|
||||
// Resolve shell env
|
||||
const shellEnv = await resolveShellEnv(this.logService, args, env);
|
||||
acceptShellEnv(shellEnv);
|
||||
});
|
||||
|
||||
ipc.on('vscode:toggleDevTools', (event: IpcMainEvent) => event.sender.toggleDevTools());
|
||||
|
||||
@@ -685,7 +685,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
|
||||
// (for https://github.com/microsoft/vscode/issues/108571)
|
||||
const currentUserEnv = (this.currentConfig ?? this.pendingLoadConfig)?.userEnv;
|
||||
if (currentUserEnv && isLaunchedFromCli(currentUserEnv) && !isLaunchedFromCli(config.userEnv)) {
|
||||
config.userEnv = currentUserEnv;
|
||||
config.userEnv = { ...currentUserEnv, ...config.userEnv }; // still allow to override certain environment as passed in
|
||||
}
|
||||
|
||||
// If this is the first time the window is loaded, we associate the paths
|
||||
|
||||
@@ -9,6 +9,7 @@ import { isWindows } from 'vs/base/common/platform';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { NativeParsedArgs } from 'vs/platform/environment/common/argv';
|
||||
import { isLaunchedFromCli } from 'vs/platform/environment/node/argvHelper';
|
||||
import { toErrorMessage } from 'vs/base/common/errorMessage';
|
||||
|
||||
/**
|
||||
* We need to get the environment from a user's shell.
|
||||
@@ -56,7 +57,7 @@ export async function resolveShellEnv(logService: ILogService, args: NativeParse
|
||||
|
||||
let unixShellEnvPromise: Promise<typeof process.env> | undefined = undefined;
|
||||
|
||||
function doResolveUnixShellEnv(logService: ILogService): Promise<typeof process.env> {
|
||||
async function doResolveUnixShellEnv(logService: ILogService): Promise<typeof process.env> {
|
||||
const promise = new Promise<typeof process.env>((resolve, reject) => {
|
||||
const runAsNode = process.env['ELECTRON_RUN_AS_NODE'];
|
||||
logService.trace('getUnixShellEnvironment#runAsNode', runAsNode);
|
||||
@@ -125,6 +126,11 @@ function doResolveUnixShellEnv(logService: ILogService): Promise<typeof process.
|
||||
});
|
||||
});
|
||||
|
||||
// swallow errors
|
||||
return promise.catch(() => ({}));
|
||||
try {
|
||||
return await promise;
|
||||
} catch (error) {
|
||||
logService.error('getUnixShellEnvironment#error', toErrorMessage(error));
|
||||
|
||||
return {}; // ignore any errors
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user