提交 7ad40c09 编写于 作者: J Joao Moreno

ipc: git askpass service

上级 1e0204a2
......@@ -20,6 +20,7 @@ import {Instance as UpdateManager} from 'vs/workbench/electron-main/update-manag
import {Server, serve, connect} from 'vs/base/parts/ipc/node/ipc.net';
import {getUserEnvironment} from 'vs/base/node/env';
import {TPromise} from 'vs/base/common/winjs.base';
import {AskpassChannel} from 'vs/workbench/parts/git/common/gitIpc';
import {GitAskpassService} from 'vs/workbench/parts/git/electron-main/askpassService';
import {spawnSharedProcess} from 'vs/workbench/electron-main/sharedProcess';
import {Mutex} from 'windows-mutex';
......@@ -119,7 +120,10 @@ function main(ipcServer: Server, userEnv: env.IProcessEnvironment): void {
// Register IPC services
ipcServer.registerService('LaunchService', new LaunchService());
ipcServer.registerService('GitAskpassService', new GitAskpassService());
const askpassService = new GitAskpassService();
const askpassChannel = new AskpassChannel(askpassService);
ipcServer.registerChannel('askpass', askpassChannel);
// Used by sub processes to communicate back to the main instance
process.env['VSCODE_PID'] = '' + process.pid;
......
......@@ -243,10 +243,9 @@ export interface IGitCredentialScope {
path: string;
}
export interface IGitCredentials {
export interface ICredentials {
username: string;
password: string;
store: boolean;
}
export interface IGitServiceError extends Error {
......@@ -316,6 +315,10 @@ export interface IGitService extends EventEmitter.IEventEmitter {
onOutput(): WinJS.Promise;
}
export interface IAskpassService {
askpass(id: string, host: string, command: string): WinJS.TPromise<ICredentials>;
}
// Utils
export function isValidBranchName(value: string): boolean {
......
......@@ -7,7 +7,7 @@
import { TPromise } from 'vs/base/common/winjs.base';
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
import { IRawGitService, RawServiceState, IRawStatus, IPushOptions } from './git';
import { IRawGitService, RawServiceState, IRawStatus, IPushOptions, IAskpassService, ICredentials } from './git';
export interface IGitChannel extends IChannel {
call(command: 'getVersion'): TPromise<string>;
......@@ -157,4 +157,29 @@ export class GitChannelClient implements IRawGitService {
onOutput(): TPromise<void> {
return this.channel.call('onOutput');
}
}
export interface IAskpassChannel extends IChannel {
call(command: 'askpass', id: string, host: string, gitCommand: string): TPromise<ICredentials>;
call(command: string, ...args: any[]): TPromise<any>;
}
export class AskpassChannel implements IAskpassChannel {
constructor(private service: IAskpassService) { }
call(command: string, ...args: any[]): TPromise<any> {
switch (command) {
case 'askpass': return this.service.askpass(args[0], args[1], args[2]);
}
}
}
export class AskpassChannelClient implements IAskpassService {
constructor(private channel: IAskpassChannel) { }
askpass(id: string, host: string, command: string): TPromise<ICredentials> {
return this.channel.call('askpass', id, host, command);
}
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ import * as nls from 'vs/nls';
import { ipcMain as ipc, BrowserWindow} from 'electron';
import platform = require('vs/base/common/platform');
import { TPromise } from 'vs/base/common/winjs.base';
import { IAskpassService } from 'vs/workbench/parts/git/common/git';
export interface ICredentials {
username: string;
......@@ -23,7 +24,7 @@ interface IContext {
window: Electron.BrowserWindow;
}
export class GitAskpassService {
export class GitAskpassService implements IAskpassService {
private askpassCache: { [id: string]: IContext } = Object.create(null);
......
......@@ -6,20 +6,9 @@
'use strict';
import { connect } from 'vs/base/parts/ipc/node/ipc.net';
import { TPromise } from 'vs/base/common/winjs.base';
import { IAskpassChannel, AskpassChannelClient } from 'vs/workbench/parts/git/common/gitIpc';
import * as fs from 'fs';
export interface ICredentials {
username: string;
password: string;
}
export class GitAskpassServiceStub {
public askpass(id: string, host: string, command: string): TPromise<ICredentials> {
throw new Error('not implemented');
}
}
function fatal(err: any): void {
console.error(err);
process.exit(1);
......@@ -49,7 +38,8 @@ function main(argv: string[]): void {
connect(process.env['VSCODE_IPC_HOOK'])
.then(client => {
const service = client.getChannel<GitAskpassServiceStub>('GitAskpassService', GitAskpassServiceStub);
const channel = client.getChannel<IAskpassChannel>('askpass');
const service = new AskpassChannelClient(channel);
return service.askpass(id, host, process.env['MONACO_GIT_COMMAND']).then(result => {
if (result) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册