introduce and use IEnvironmentService to the renderer (for #6095)
This commit is contained in:
parent
01a25e9455
commit
d54054ee3f
5 changed files with 41 additions and 10 deletions
|
@ -12,10 +12,17 @@ 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>;
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
@ -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; }
|
||||
|
||||
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,7 +187,8 @@ 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);
|
||||
}
|
||||
|
@ -193,7 +196,7 @@ export class OpenGlobalKeybindingsAction extends BaseTwoEditorsAction {
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
|
|
@ -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';
|
||||
|
@ -89,6 +90,7 @@ export interface ICoreServices {
|
|||
contextService: IWorkspaceContextService;
|
||||
eventService: IEventService;
|
||||
configurationService: IConfigurationService;
|
||||
environmentService: IEnvironmentService;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue