提交 05334aea 编写于 作者: B Benjamin Pasero

more use of IEnvironmentService (for #10656)

上级 beeb7f20
......@@ -7,17 +7,13 @@
import * as fs from 'original-fs';
import * as path from 'path';
import * as os from 'os';
import { app } from 'electron';
import * as arrays from 'vs/base/common/arrays';
import * as strings from 'vs/base/common/strings';
import * as paths from 'vs/base/common/paths';
import * as platform from 'vs/base/common/platform';
import URI from 'vs/base/common/uri';
import * as types from 'vs/base/common/types';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { parseArgs, ParsedArgs } from 'vs/platform/environment/node/argv';
import product from 'vs/platform/product';
export interface IProcessEnvironment {
[key: string]: string;
......@@ -32,14 +28,6 @@ export const IEnvService = createDecorator<IEnvService>('mainEnvironmentService'
export interface IEnvService {
_serviceBrand: any;
cliArgs: ICommandLineArguments;
isBuilt: boolean;
userHome: string;
appRoot: string;
currentWorkingDirectory: string;
appHome: string;
appSettingsHome: string;
appSettingsPath: string;
appKeybindingsPath: string;
}
export class EnvService implements IEnvService {
......@@ -49,45 +37,14 @@ export class EnvService implements IEnvService {
private _cliArgs: ICommandLineArguments;
get cliArgs(): ICommandLineArguments { return this._cliArgs; }
private _userExtensionsHome: string;
get userExtensionsHome(): string { return this._userExtensionsHome; }
get isBuilt(): boolean { return !process.env['VSCODE_DEV']; }
private _userHome: string;
get userHome(): string { return this._userHome; }
private _appRoot: string;
get appRoot(): string { return this._appRoot; }
private _currentWorkingDirectory: string;
get currentWorkingDirectory(): string { return this._currentWorkingDirectory; }
private _appHome: string;
get appHome(): string { return this._appHome; }
private _appSettingsHome: string;
get appSettingsHome(): string { return this._appSettingsHome; }
private _appSettingsPath: string;
get appSettingsPath(): string { return this._appSettingsPath; }
private _appKeybindingsPath: string;
get appKeybindingsPath(): string { return this._appKeybindingsPath; }
constructor() {
this._appRoot = path.dirname(URI.parse(require.toUrl('')).fsPath);
this._currentWorkingDirectory = process.env['VSCODE_CWD'] || process.cwd();
this._appHome = app.getPath('userData');
this._appSettingsHome = path.join(this._appHome, 'User');
this._appSettingsPath = path.join(this._appSettingsHome, 'settings.json');
this._appKeybindingsPath = path.join(this._appSettingsHome, 'keybindings.json');
// Remove the Electron executable
const [, ...args] = process.argv;
// If dev, remove the first non-option argument: it's the app location
if (!this.isBuilt) {
const isBuilt = !process.env['VSCODE_DEV'];
if (!isBuilt) {
const index = arrays.firstIndex(args, a => !/^-/.test(a));
if (index > -1) {
......@@ -96,7 +53,8 @@ export class EnvService implements IEnvService {
}
const argv = parseArgs(args);
const paths = parsePathArguments(this._currentWorkingDirectory, argv._, argv.goto);
const cwd = process.env['VSCODE_CWD'] || process.cwd();
const paths = parsePathArguments(cwd, argv._, argv.goto);
this._cliArgs = Object.freeze({
_: [],
......@@ -118,9 +76,6 @@ export class EnvService implements IEnvService {
locale: argv.locale,
wait: argv.wait
});
this._userHome = path.join(os.homedir(), product.dataFolderName);
this._userExtensionsHome = this.cliArgs.extensionHomePath || path.join(this._userHome, 'extensions');
}
}
......
......@@ -9,7 +9,7 @@ import { EventEmitter } from 'events';
import { ipcMain as ipc, app } from 'electron';
import { TPromise, TValueCallback } from 'vs/base/common/winjs.base';
import { ReadyState, VSCodeWindow } from 'vs/code/electron-main/window';
import { IEnvService } from 'vs/code/electron-main/env';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { ILogService } from 'vs/code/electron-main/log';
import { IStorageService } from 'vs/code/electron-main/storage';
......@@ -50,7 +50,7 @@ export class LifecycleService implements ILifecycleService {
private _wasUpdated: boolean;
constructor(
@IEnvService private envService: IEnvService,
@IEnvironmentService private environmentService: IEnvironmentService,
@ILogService private logService: ILogService,
@IStorageService private storageService: IStorageService
) {
......@@ -109,7 +109,7 @@ export class LifecycleService implements ILifecycleService {
// Windows/Linux: we quit when all windows have closed
// Mac: we only quit when quit was requested
// --wait: we quit when all windows are closed
if (this.quitRequested || process.platform !== 'darwin' || this.envService.cliArgs.wait) {
if (this.quitRequested || process.platform !== 'darwin' || this.environmentService.wait) {
app.quit();
}
});
......
......@@ -6,7 +6,7 @@
'use strict';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IEnvService } from 'vs/code/electron-main/env';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
export const ILogService = createDecorator<ILogService>('logService');
......@@ -19,13 +19,11 @@ export class MainLogService implements ILogService {
_serviceBrand: any;
constructor(@IEnvService private envService: IEnvService) {
constructor(@IEnvironmentService private environmentService: IEnvironmentService) {
}
log(...args: any[]): void {
const { verbose } = this.envService.cliArgs;
if (verbose) {
if (this.environmentService.verbose) {
console.log(`\x1b[93m[main ${new Date().toLocaleTimeString()}]\x1b[0m`, ...args);
}
}
......
......@@ -102,7 +102,7 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: IProce
});
logService.log('Starting VS Code in verbose mode');
logService.log(`from: ${envService.appRoot}`);
logService.log(`from: ${environmentService.appRoot}`);
logService.log('args:', envService.cliArgs);
// Setup Windows mutex
......@@ -134,8 +134,8 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: IProce
// Spawn shared process
const initData = { args: environmentService.args };
const options = {
allowOutput: !envService.isBuilt || envService.cliArgs.verbose,
debugPort: envService.isBuilt ? null : 5871
allowOutput: !environmentService.isBuilt || environmentService.verbose,
debugPort: environmentService.isBuilt ? null : 5871
};
let sharedProcessDisposable;
......
......@@ -7,7 +7,7 @@
import * as path from 'path';
import * as fs from 'original-fs';
import { IEnvService } from 'vs/code/electron-main/env';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
export const IStorageService = createDecorator<IStorageService>('storageService');
......@@ -26,8 +26,8 @@ export class StorageService implements IStorageService {
private dbPath: string;
private database: any = null;
constructor(@IEnvService private envService: IEnvService) {
this.dbPath = path.join(envService.appHome, 'storage.json');
constructor(@IEnvironmentService private environmentService: IEnvironmentService) {
this.dbPath = path.join(environmentService.userDataPath, 'storage.json');
}
getItem<T>(key: string, defaultValue?: T): T {
......@@ -74,7 +74,7 @@ export class StorageService implements IStorageService {
try {
return JSON.parse(fs.readFileSync(this.dbPath).toString()); // invalid JSON or permission issue can happen here
} catch (error) {
if (this.envService.cliArgs.verbose) {
if (this.environmentService.verbose) {
console.error(error);
}
......@@ -86,7 +86,7 @@ export class StorageService implements IStorageService {
try {
fs.writeFileSync(this.dbPath, JSON.stringify(this.database, null, 4)); // permission issue can happen here
} catch (error) {
if (this.envService.cliArgs.verbose) {
if (this.environmentService.verbose) {
console.error(error);
}
}
......
......@@ -11,7 +11,8 @@ import * as objects from 'vs/base/common/objects';
import { IStorageService } from 'vs/code/electron-main/storage';
import { shell, screen, BrowserWindow } from 'electron';
import { TPromise, TValueCallback } from 'vs/base/common/winjs.base';
import { ICommandLineArguments, IEnvService, IProcessEnvironment } from 'vs/code/electron-main/env';
import { ICommandLineArguments, IProcessEnvironment } from 'vs/code/electron-main/env';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ILogService } from 'vs/code/electron-main/log';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { parseArgs } from 'vs/platform/environment/node/argv';
......@@ -135,7 +136,7 @@ export class VSCodeWindow {
constructor(
config: IWindowCreationOptions,
@ILogService private logService: ILogService,
@IEnvService private envService: IEnvService,
@IEnvironmentService private environmentService: IEnvironmentService,
@IConfigurationService private configurationService: IConfigurationService,
@IStorageService private storageService: IStorageService
) {
......@@ -173,7 +174,7 @@ export class VSCodeWindow {
};
if (platform.isLinux) {
options.icon = path.join(this.envService.appRoot, 'resources/linux/code.png'); // Windows and Mac are better off using the embedded icon(s)
options.icon = path.join(this.environmentService.appRoot, 'resources/linux/code.png'); // Windows and Mac are better off using the embedded icon(s)
}
// Create the browser window.
......@@ -340,7 +341,7 @@ export class VSCodeWindow {
// Prevent any kind of navigation triggered by the user!
// But do not touch this in dev version because it will prevent "Reload" from dev tools
if (this.envService.isBuilt) {
if (this.environmentService.isBuilt) {
this._win.webContents.on('will-navigate', (event: Event) => {
if (event) {
event.preventDefault();
......@@ -375,7 +376,7 @@ export class VSCodeWindow {
this._win.loadURL(this.getUrl(config));
// Make window visible if it did not open in N seconds because this indicates an error
if (!this.envService.isBuilt) {
if (!this.environmentService.isBuilt) {
this.showTimeoutHandle = setTimeout(() => {
if (this._win && !this._win.isVisible() && !this._win.isMinimized()) {
this._win.show();
......
......@@ -14,6 +14,7 @@ import * as types from 'vs/base/common/types';
import * as arrays from 'vs/base/common/arrays';
import { assign, mixin } from 'vs/base/common/objects';
import { EventEmitter } from 'events';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IStorageService } from 'vs/code/electron-main/storage';
import { IPath, VSCodeWindow, ReadyState, IWindowConfiguration, IWindowState as ISingleWindowState, defaultWindowState, IWindowSettings } from 'vs/code/electron-main/window';
import { ipcMain as ipc, app, screen, crashReporter, BrowserWindow, dialog } from 'electron';
......@@ -162,6 +163,7 @@ export class WindowsManager implements IWindowsService {
@ILogService private logService: ILogService,
@IStorageService private storageService: IStorageService,
@IEnvService private envService: IEnvService,
@IEnvironmentService private environmentService: IEnvironmentService,
@ILifecycleService private lifecycleService: ILifecycleService,
@IUpdateService private updateService: IUpdateService,
@IConfigurationService private configurationService: IConfigurationService
......@@ -843,7 +845,7 @@ export class WindowsManager implements IWindowsService {
private toConfiguration(userEnv: IProcessEnvironment, cli: ICommandLineArguments, workspacePath?: string, filesToOpen?: IPath[], filesToCreate?: IPath[], filesToDiff?: IPath[]): IWindowConfiguration {
const configuration: IWindowConfiguration = mixin({}, cli); // inherit all properties from CLI
configuration.appRoot = this.envService.appRoot;
configuration.appRoot = this.environmentService.appRoot;
configuration.execPath = process.execPath;
configuration.userEnv = userEnv;
configuration.workspacePath = workspacePath;
......
......@@ -34,6 +34,7 @@ export interface IEnvironmentService {
isBuilt: boolean;
verbose: boolean;
wait: boolean;
performance: boolean;
mainIPCHandle: string;
......
......@@ -89,6 +89,7 @@ export class EnvironmentService implements IEnvironmentService {
get isBuilt(): boolean { return !process.env['VSCODE_DEV']; }
get verbose(): boolean { return this._args.verbose; }
get wait(): boolean { return this._args.wait; }
get performance(): boolean { return this._args.performance; }
get logExtensionHostCommunication(): boolean { return this._args.logExtensionHostCommunication; }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册