use request service everywhere
This commit is contained in:
parent
200e222740
commit
92c7bed93c
|
@ -8,10 +8,9 @@
|
|||
import { EventEmitter } from 'events';
|
||||
import { isString } from 'vs/base/common/types';
|
||||
import { Promise } from 'vs/base/common/winjs.base';
|
||||
import { request, asJson } from 'vs/base/node/request';
|
||||
import { getProxyAgent } from 'vs/base/node/proxy';
|
||||
import { ISettingsService } from 'vs/code/electron-main/settings';
|
||||
import { IEnvironmentService } from 'vs/code/electron-main/env';
|
||||
import { asJson } from 'vs/base/node/request';
|
||||
import { IEnvService } from 'vs/code/electron-main/env';
|
||||
import { IRequestService } from 'vs/platform/request/common/request';
|
||||
|
||||
export interface IUpdate {
|
||||
url: string;
|
||||
|
@ -26,8 +25,8 @@ export class LinuxAutoUpdaterImpl extends EventEmitter {
|
|||
private currentRequest: Promise;
|
||||
|
||||
constructor(
|
||||
@IEnvironmentService private envService: IEnvironmentService,
|
||||
@ISettingsService private settingsService: ISettingsService
|
||||
@IEnvService private envService: IEnvService,
|
||||
@IRequestService private requestService: IRequestService
|
||||
) {
|
||||
super();
|
||||
|
||||
|
@ -50,12 +49,8 @@ export class LinuxAutoUpdaterImpl extends EventEmitter {
|
|||
|
||||
this.emit('checking-for-update');
|
||||
|
||||
const proxyUrl = this.settingsService.getValue<string>('http.proxy');
|
||||
const strictSSL = this.settingsService.getValue('http.proxyStrictSSL', true);
|
||||
const agent = getProxyAgent(this.url, { proxyUrl, strictSSL });
|
||||
|
||||
this.currentRequest = request({ url: this.url, agent })
|
||||
.then(context => asJson<IUpdate>(context))
|
||||
this.currentRequest = this.requestService.request({ url: this.url })
|
||||
.then<IUpdate>(asJson)
|
||||
.then(update => {
|
||||
if (!update || !update.url || !update.version) {
|
||||
this.emit('update-not-available');
|
||||
|
|
|
@ -14,11 +14,10 @@ import { spawn } from 'child_process';
|
|||
import { mkdirp } from 'vs/base/node/extfs';
|
||||
import { isString } from 'vs/base/common/types';
|
||||
import { Promise, TPromise } from 'vs/base/common/winjs.base';
|
||||
import { request, download, asJson } from 'vs/base/node/request';
|
||||
import { getProxyAgent } from 'vs/base/node/proxy';
|
||||
import { ISettingsService } from 'vs/code/electron-main/settings';
|
||||
import { download, asJson } from 'vs/base/node/request';
|
||||
import { ILifecycleService } from 'vs/code/electron-main/lifecycle';
|
||||
import { IEnvironmentService } from 'vs/code/electron-main/env';
|
||||
import { IEnvService } from 'vs/code/electron-main/env';
|
||||
import { IRequestService } from 'vs/platform/request/common/request';
|
||||
|
||||
export interface IUpdate {
|
||||
url: string;
|
||||
|
@ -35,8 +34,8 @@ export class Win32AutoUpdaterImpl extends EventEmitter {
|
|||
|
||||
constructor(
|
||||
@ILifecycleService private lifecycleService: ILifecycleService,
|
||||
@IEnvironmentService private envService: IEnvironmentService,
|
||||
@ISettingsService private settingsService: ISettingsService
|
||||
@IEnvService private envService: IEnvService,
|
||||
@IRequestService private requestService: IRequestService
|
||||
) {
|
||||
super();
|
||||
|
||||
|
@ -64,12 +63,8 @@ export class Win32AutoUpdaterImpl extends EventEmitter {
|
|||
|
||||
this.emit('checking-for-update');
|
||||
|
||||
const proxyUrl = this.settingsService.getValue<string>('http.proxy');
|
||||
const strictSSL = this.settingsService.getValue('http.proxyStrictSSL', true);
|
||||
const agent = getProxyAgent(this.url, { proxyUrl, strictSSL });
|
||||
|
||||
this.currentRequest = request({ url: this.url, agent })
|
||||
.then(context => asJson<IUpdate>(context))
|
||||
this.currentRequest = this.requestService.request({ url: this.url })
|
||||
.then<IUpdate>(asJson)
|
||||
.then(update => {
|
||||
if (!update || !update.url || !update.version) {
|
||||
this.emit('update-not-available');
|
||||
|
@ -88,9 +83,8 @@ export class Win32AutoUpdaterImpl extends EventEmitter {
|
|||
const url = update.url;
|
||||
const hash = update.hash;
|
||||
const downloadPath = `${updatePackagePath}.tmp`;
|
||||
const agent = getProxyAgent(url, { proxyUrl, strictSSL });
|
||||
|
||||
return request({ url, agent, strictSSL })
|
||||
return this.requestService.request({ url })
|
||||
.then(context => download(downloadPath, context))
|
||||
.then(hash ? () => checksum(downloadPath, update.hash) : () => null)
|
||||
.then(() => pfs.rename(downloadPath, updatePackagePath))
|
||||
|
|
|
@ -48,9 +48,9 @@ export interface ICommandLineArguments {
|
|||
waitForWindowClose?: boolean;
|
||||
}
|
||||
|
||||
export const IEnvironmentService = createDecorator<IEnvironmentService>('mainEnvironmentService');
|
||||
export const IEnvService = createDecorator<IEnvService>('mainEnvironmentService');
|
||||
|
||||
export interface IEnvironmentService {
|
||||
export interface IEnvService {
|
||||
_serviceBrand: any;
|
||||
cliArgs: ICommandLineArguments;
|
||||
userExtensionsHome: string;
|
||||
|
@ -86,7 +86,7 @@ function getNumericValue(value: string, defaultValue: number, fallback: number =
|
|||
return fallback;
|
||||
}
|
||||
|
||||
export class EnvService implements IEnvironmentService {
|
||||
export class EnvService implements IEnvService {
|
||||
|
||||
_serviceBrand: any;
|
||||
|
||||
|
|
|
@ -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 { IEnvironmentService } from 'vs/code/electron-main/env';
|
||||
import { IEnvService } from 'vs/code/electron-main/env';
|
||||
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(
|
||||
@IEnvironmentService private envService: IEnvironmentService,
|
||||
@IEnvService private envService: IEnvService,
|
||||
@ILogService private logService: ILogService,
|
||||
@IStorageService private storageService: IStorageService
|
||||
) {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
'use strict';
|
||||
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IEnvironmentService } from 'vs/code/electron-main/env';
|
||||
import { IEnvService } from 'vs/code/electron-main/env';
|
||||
|
||||
export const ILogService = createDecorator<ILogService>('logService');
|
||||
|
||||
|
@ -19,7 +19,7 @@ export class MainLogService implements ILogService {
|
|||
|
||||
_serviceBrand: any;
|
||||
|
||||
constructor( @IEnvironmentService private envService: IEnvironmentService) {
|
||||
constructor( @IEnvService private envService: IEnvService) {
|
||||
}
|
||||
|
||||
log(...args: any[]): void {
|
||||
|
|
|
@ -10,7 +10,8 @@ import * as fs from 'original-fs';
|
|||
import { app, ipcMain as ipc } from 'electron';
|
||||
import { assign } from 'vs/base/common/objects';
|
||||
import * as platform from 'vs/base/common/platform';
|
||||
import { IProcessEnvironment, IEnvironmentService, EnvService } from 'vs/code/electron-main/env';
|
||||
import { parseArgs } from 'vs/code/node/argv';
|
||||
import { IProcessEnvironment, IEnvService, EnvService } from 'vs/code/electron-main/env';
|
||||
import { IWindowsService, WindowsManager } from 'vs/code/electron-main/windows';
|
||||
import { ILifecycleService, LifecycleService } from 'vs/code/electron-main/lifecycle';
|
||||
import { VSCodeMenu } from 'vs/code/electron-main/menus';
|
||||
|
@ -30,6 +31,12 @@ import { ServiceCollection } from 'vs/platform/instantiation/common/serviceColle
|
|||
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
|
||||
import { ILogService, MainLogService } from 'vs/code/electron-main/log';
|
||||
import { IStorageService, StorageService } from 'vs/code/electron-main/storage';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { NodeConfigurationService } from 'vs/platform/configuration/node/nodeConfigurationService';
|
||||
import { IRequestService } from 'vs/platform/request/common/request';
|
||||
import { RequestService } from 'vs/platform/request/node/requestService';
|
||||
import * as cp from 'child_process';
|
||||
import { generateUuid } from 'vs/base/common/uuid';
|
||||
import { URLChannel } from 'vs/platform/url/common/urlIpc';
|
||||
|
@ -58,7 +65,7 @@ function quit(accessor: ServicesAccessor, arg?: any) {
|
|||
function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: IProcessEnvironment): void {
|
||||
const instantiationService = accessor.get(IInstantiationService);
|
||||
const logService = accessor.get(ILogService);
|
||||
const envService = accessor.get(IEnvironmentService);
|
||||
const envService = accessor.get(IEnvService);
|
||||
const windowsService = accessor.get(IWindowsService);
|
||||
const lifecycleService = accessor.get(ILifecycleService);
|
||||
const updateService = accessor.get(IUpdateService);
|
||||
|
@ -199,7 +206,7 @@ function main(accessor: ServicesAccessor, mainIpcServer: Server, userEnv: IProce
|
|||
|
||||
function setupIPC(accessor: ServicesAccessor): TPromise<Server> {
|
||||
const logService = accessor.get(ILogService);
|
||||
const envService = accessor.get(IEnvironmentService);
|
||||
const envService = accessor.get(IEnvService);
|
||||
|
||||
function setup(retry: boolean): TPromise<Server> {
|
||||
return serve(envService.mainIPCHandle).then(server => {
|
||||
|
@ -266,11 +273,14 @@ function setupIPC(accessor: ServicesAccessor): TPromise<Server> {
|
|||
// TODO: isolate
|
||||
const services = new ServiceCollection();
|
||||
|
||||
services.set(IEnvironmentService, new SyncDescriptor(EnvService));
|
||||
services.set(IEnvService, new SyncDescriptor(EnvService));
|
||||
services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService, parseArgs(process.argv)));
|
||||
services.set(ILogService, new SyncDescriptor(MainLogService));
|
||||
services.set(IWindowsService, new SyncDescriptor(WindowsManager));
|
||||
services.set(ILifecycleService, new SyncDescriptor(LifecycleService));
|
||||
services.set(IStorageService, new SyncDescriptor(StorageService));
|
||||
services.set(IConfigurationService, new SyncDescriptor(NodeConfigurationService));
|
||||
services.set(IRequestService, new SyncDescriptor(RequestService));
|
||||
services.set(IUpdateService, new SyncDescriptor(UpdateManager));
|
||||
services.set(ISettingsService, new SyncDescriptor(SettingsManager));
|
||||
|
||||
|
@ -363,7 +373,7 @@ function getShellEnvironment(): TPromise<IEnv> {
|
|||
function getEnvironment(): TPromise<IEnv> {
|
||||
return getShellEnvironment().then(shellEnv => {
|
||||
return instantiationService.invokeFunction(a => {
|
||||
const envService = a.get(IEnvironmentService);
|
||||
const envService = a.get(IEnvService);
|
||||
const instanceEnv = {
|
||||
VSCODE_PID: String(process.pid),
|
||||
VSCODE_IPC_HOOK: envService.mainIPCHandle,
|
||||
|
@ -381,7 +391,7 @@ function getEnvironment(): TPromise<IEnv> {
|
|||
getEnvironment().then(env => {
|
||||
assign(process.env, env);
|
||||
|
||||
return instantiationService.invokeFunction(a => a.get(IEnvironmentService).createPaths())
|
||||
return instantiationService.invokeFunction(a => a.get(IEnvService).createPaths())
|
||||
.then(() => instantiationService.invokeFunction(setupIPC))
|
||||
.then(mainIpcServer => instantiationService.invokeFunction(main, mainIpcServer, env));
|
||||
})
|
||||
|
|
|
@ -58,7 +58,7 @@ export class VSCodeMenu {
|
|||
@IStorageService private storageService: IStorageService,
|
||||
@IUpdateService private updateService: IUpdateService,
|
||||
@IWindowsService private windowsService: IWindowsService,
|
||||
@env.IEnvironmentService private envService: env.IEnvironmentService
|
||||
@env.IEnvService private envService: env.IEnvService
|
||||
) {
|
||||
this.actionIdKeybindingRequests = [];
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { app } from 'electron';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { UserSettings, ISettings } from 'vs/base/node/userSettings';
|
||||
import { IEnvironmentService } from 'vs/code/electron-main/env';
|
||||
import { IEnvService } from 'vs/code/electron-main/env';
|
||||
import Event from 'vs/base/common/event';
|
||||
|
||||
export const ISettingsService = createDecorator<ISettingsService>('settingsService');
|
||||
|
@ -25,7 +25,7 @@ export class SettingsManager extends UserSettings implements ISettingsService {
|
|||
|
||||
_serviceBrand: any;
|
||||
|
||||
constructor(@IEnvironmentService envService: IEnvironmentService) {
|
||||
constructor(@IEnvService envService: IEnvService) {
|
||||
super(envService.appSettingsPath, envService.appKeybindingsPath);
|
||||
|
||||
app.on('will-quit', () => {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import * as path from 'path';
|
||||
import * as fs from 'original-fs';
|
||||
import { EventEmitter } from 'events';
|
||||
import { IEnvironmentService } from 'vs/code/electron-main/env';
|
||||
import { IEnvService } from 'vs/code/electron-main/env';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
||||
const EventTypes = {
|
||||
|
@ -33,7 +33,7 @@ export class StorageService implements IStorageService {
|
|||
private database: any = null;
|
||||
private eventEmitter = new EventEmitter();
|
||||
|
||||
constructor(@IEnvironmentService private envService: IEnvironmentService) {
|
||||
constructor(@IEnvService private envService: IEnvService) {
|
||||
this.dbPath = path.join(envService.appHome, 'storage.json');
|
||||
}
|
||||
|
||||
|
|
|
@ -10,12 +10,13 @@ import * as path from 'path';
|
|||
import * as electron from 'electron';
|
||||
import * as platform from 'vs/base/common/platform';
|
||||
import { EventEmitter } from 'events';
|
||||
import { IEnvironmentService, getPlatformIdentifier } from 'vs/code/electron-main/env';
|
||||
import { IEnvService, getPlatformIdentifier } from 'vs/code/electron-main/env';
|
||||
import { ISettingsService } from 'vs/code/electron-main/settings';
|
||||
import { Win32AutoUpdaterImpl } from 'vs/code/electron-main/auto-updater.win32';
|
||||
import { LinuxAutoUpdaterImpl } from 'vs/code/electron-main/auto-updater.linux';
|
||||
import { ILifecycleService } from 'vs/code/electron-main/lifecycle';
|
||||
import { createDecorator, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IRequestService } from 'vs/platform/request/common/request';
|
||||
|
||||
export enum State {
|
||||
Uninitialized,
|
||||
|
@ -71,8 +72,9 @@ export class UpdateManager extends EventEmitter implements IUpdateService {
|
|||
constructor(
|
||||
@IInstantiationService instantiationService: IInstantiationService,
|
||||
@ILifecycleService private lifecycleService: ILifecycleService,
|
||||
@IEnvironmentService private envService: IEnvironmentService,
|
||||
@ISettingsService private settingsService: ISettingsService
|
||||
@IEnvService private envService: IEnvService,
|
||||
@ISettingsService private settingsService: ISettingsService,
|
||||
@IRequestService requestService: IRequestService
|
||||
) {
|
||||
super();
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ 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, IEnvironmentService, IProcessEnvironment } from 'vs/code/electron-main/env';
|
||||
import { ICommandLineArguments, IEnvService, IProcessEnvironment } from 'vs/code/electron-main/env';
|
||||
import { ILogService } from 'vs/code/electron-main/log';
|
||||
|
||||
export interface IWindowState {
|
||||
|
@ -159,7 +159,7 @@ export class VSCodeWindow {
|
|||
constructor(
|
||||
config: IWindowCreationOptions,
|
||||
@ILogService private logService: ILogService,
|
||||
@IEnvironmentService private envService: IEnvironmentService,
|
||||
@IEnvService private envService: IEnvService,
|
||||
@IStorageService private storageService: IStorageService
|
||||
) {
|
||||
this.options = config;
|
||||
|
|
|
@ -17,7 +17,7 @@ import { EventEmitter } from 'events';
|
|||
import { IStorageService } from 'vs/code/electron-main/storage';
|
||||
import { IPath, VSCodeWindow, ReadyState, IWindowConfiguration, IWindowState as ISingleWindowState, defaultWindowState } from 'vs/code/electron-main/window';
|
||||
import { ipcMain as ipc, app, screen, crashReporter, BrowserWindow, dialog } from 'electron';
|
||||
import { ICommandLineArguments, IProcessEnvironment, IEnvironmentService, IParsedPath, parseLineAndColumnAware } from 'vs/code/electron-main/env';
|
||||
import { ICommandLineArguments, IProcessEnvironment, IEnvService, IParsedPath, parseLineAndColumnAware } from 'vs/code/electron-main/env';
|
||||
import { ILifecycleService } from 'vs/code/electron-main/lifecycle';
|
||||
import { ISettingsService } from 'vs/code/electron-main/settings';
|
||||
import { IUpdateService, IUpdate } from 'vs/code/electron-main/update-manager';
|
||||
|
@ -130,7 +130,7 @@ export class WindowsManager implements IWindowsService {
|
|||
@IInstantiationService private instantiationService: IInstantiationService,
|
||||
@ILogService private logService: ILogService,
|
||||
@IStorageService private storageService: IStorageService,
|
||||
@IEnvironmentService private envService: IEnvironmentService,
|
||||
@IEnvService private envService: IEnvService,
|
||||
@ILifecycleService private lifecycleService: ILifecycleService,
|
||||
@IUpdateService private updateService: IUpdateService,
|
||||
@ISettingsService private settingsService: ISettingsService
|
||||
|
|
Loading…
Reference in a new issue