Skip to content

Commit

Permalink
introduce and use IEnvironmentService to the renderer (for #6095)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Aug 16, 2016
1 parent 01a25e9 commit d54054e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
9 changes: 8 additions & 1 deletion src/vs/platform/environment/common/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ export interface IEnvironmentService {
_serviceBrand: any;

appRoot: string;

userHome: string;
userDataPath: string;

appSettingsHome: string;
appSettingsPath: string;
appKeybindingsPath: string;

extensionsPath: string;
extensionDevelopmentPath: string;

isBuilt: boolean;

createPaths(): TPromise<void>;
}
}
21 changes: 17 additions & 4 deletions src/vs/platform/environment/node/environmentService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
import * as paths from 'vs/base/node/paths';
import product from 'vs/platform/product';
import pkg from 'vs/platform/package';
import * as os from 'os';
import * as path from 'path';
import { mkdirp } from 'vs/base/node/pfs';
import { parseArgs } from 'vs/code/node/argv';
import {mkdirp} from 'vs/base/node/pfs';
import {parseArgs} from 'vs/code/node/argv';
import URI from 'vs/base/common/uri';
import { TPromise } from 'vs/base/common/winjs.base';
import {TPromise} from 'vs/base/common/winjs.base';

export class EnvironmentService implements IEnvironmentService {

Expand All @@ -27,6 +27,15 @@ export class EnvironmentService implements IEnvironmentService {
private _userDataPath: string;
get userDataPath(): string { return this._userDataPath; }

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; }

private _extensionsPath: string;
get extensionsPath(): string { return this._extensionsPath; }

Expand All @@ -41,6 +50,10 @@ export class EnvironmentService implements IEnvironmentService {
this._appRoot = path.dirname(URI.parse(require.toUrl('')).fsPath);
this._userDataPath = paths.getUserDataPath(process.platform, pkg.name, process.argv);

this._appSettingsHome = path.join(this.userDataPath, 'User');
this._appSettingsPath = path.join(this.appSettingsHome, 'settings.json');
this._appKeybindingsPath = path.join(this.appSettingsHome, 'keybindings.json');

this._userHome = path.join(os.homedir(), product.dataFolderName);
this._extensionsPath = argv.extensionHomePath || path.join(this._userHome, 'extensions');
this._extensionsPath = path.normalize(this._extensionsPath);
Expand Down
11 changes: 7 additions & 4 deletions src/vs/workbench/browser/actions/openSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {IMessageService, Severity, CloseAction} from 'vs/platform/message/common
import {IKeybindingService} from 'vs/platform/keybinding/common/keybinding';
import {SyncActionDescriptor} from 'vs/platform/actions/common/actions';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
import {KeyMod, KeyCode} from 'vs/base/common/keyCodes';

interface IWorkbenchSettingsConfiguration {
Expand Down Expand Up @@ -134,7 +135,8 @@ export class OpenGlobalSettingsAction extends BaseOpenSettingsAction {
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IKeybindingService keybindingService: IKeybindingService,
@IInstantiationService instantiationService: IInstantiationService,
@IStorageService private storageService: IStorageService
@IStorageService private storageService: IStorageService,
@IEnvironmentService private environmentService: IEnvironmentService
) {
super(id, label, editorService, editorGroupService, fileService, configurationService, messageService, contextService, keybindingService, instantiationService);
}
Expand Down Expand Up @@ -166,7 +168,7 @@ export class OpenGlobalSettingsAction extends BaseOpenSettingsAction {
// Open settings
let emptySettingsHeader = nls.localize('emptySettingsHeader', "Place your settings in this file to overwrite the default settings");

return this.open('// ' + emptySettingsHeader + '\n{\n}', URI.file(this.contextService.getConfiguration().env.appSettingsPath));
return this.open('// ' + emptySettingsHeader + '\n{\n}', URI.file(this.environmentService.appSettingsPath));
}
}

Expand All @@ -185,15 +187,16 @@ export class OpenGlobalKeybindingsAction extends BaseTwoEditorsAction {
@IMessageService messageService: IMessageService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IKeybindingService keybindingService: IKeybindingService,
@IInstantiationService instantiationService: IInstantiationService
@IInstantiationService instantiationService: IInstantiationService,
@IEnvironmentService private environmentService: IEnvironmentService
) {
super(id, label, editorService, editorGroupService, fileService, configurationService, messageService, contextService, keybindingService, instantiationService);
}

public run(event?: any): TPromise<void> {
let emptyContents = '// ' + nls.localize('emptyKeybindingsHeader', "Place your key bindings in this file to overwrite the defaults") + '\n[\n]';

return this.openTwoEditors(DefaultKeybindingsInput.getInstance(this.instantiationService, this.keybindingService), URI.file(this.contextService.getConfiguration().env.appKeybindingsPath), emptyContents);
return this.openTwoEditors(DefaultKeybindingsInput.getInstance(this.instantiationService, this.keybindingService), URI.file(this.environmentService.appKeybindingsPath), emptyContents);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/vs/workbench/electron-browser/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {EventService} from 'vs/platform/event/common/eventService';
import {WorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService';
import {IWorkspace, IConfiguration, IEnvironment} from 'vs/platform/workspace/common/workspace';
import {ConfigurationService} from 'vs/workbench/services/configuration/node/configurationService';
import {EnvironmentService} from 'vs/platform/environment/node/environmentService';
import path = require('path');
import fs = require('fs');
import gracefulFs = require('graceful-fs');
Expand Down Expand Up @@ -129,6 +130,7 @@ function getWorkspace(environment: IMainEnvironment): IWorkspace {

function openWorkbench(workspace: IWorkspace, configuration: IConfiguration, options: IOptions): winjs.TPromise<void> {
const eventService = new EventService();
const environmentService = new EnvironmentService();
const contextService = new WorkspaceContextService(eventService, workspace, configuration, options);
const configurationService = new ConfigurationService(contextService, eventService);

Expand All @@ -145,7 +147,8 @@ function openWorkbench(workspace: IWorkspace, configuration: IConfiguration, opt
const shell = new WorkbenchShell(document.body, workspace, {
configurationService,
eventService,
contextService
contextService,
environmentService
}, configuration, options);
shell.open();

Expand Down
5 changes: 5 additions & 0 deletions src/vs/workbench/electron-browser/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {IEventService} from 'vs/platform/event/common/event';
import {IFileService} from 'vs/platform/files/common/files';
import {ILifecycleService} from 'vs/platform/lifecycle/common/lifecycle';
import {IMarkerService} from 'vs/platform/markers/common/markers';
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
import {IMessageService, Severity} from 'vs/platform/message/common/message';
import {IRequestService} from 'vs/platform/request/common/request';
import {ISearchService} from 'vs/platform/search/common/search';
Expand Down Expand Up @@ -89,6 +90,7 @@ export interface ICoreServices {
contextService: IWorkspaceContextService;
eventService: IEventService;
configurationService: IConfigurationService;
environmentService: IEnvironmentService;
}

/**
Expand All @@ -99,6 +101,7 @@ export class WorkbenchShell {
private storageService: IStorageService;
private messageService: MessageService;
private eventService: IEventService;
private environmentService:IEnvironmentService;
private contextViewService: ContextViewService;
private windowService: IWindowService;
private threadService: MainThreadService;
Expand Down Expand Up @@ -129,6 +132,7 @@ export class WorkbenchShell {
this.contextService = services.contextService;
this.eventService = services.eventService;
this.configurationService = services.configurationService;
this.environmentService = services.environmentService;

this.toUnbind = [];
this.previousErrorTime = 0;
Expand Down Expand Up @@ -225,6 +229,7 @@ export class WorkbenchShell {
serviceCollection.set(IEventService, this.eventService);
serviceCollection.set(IWorkspaceContextService, this.contextService);
serviceCollection.set(IConfigurationService, this.configurationService);
serviceCollection.set(IEnvironmentService, this.environmentService);

const instantiationService = new InstantiationService(serviceCollection, true);

Expand Down

0 comments on commit d54054e

Please sign in to comment.