extensionManagementIpc.ts 4.5 KB
Newer Older
J
Joao Moreno 已提交
1 2 3 4 5 6 7 8 9
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

'use strict';

import { TPromise } from 'vs/base/common/winjs.base';
import { IChannel, eventToCall, eventFromCall } from 'vs/base/parts/ipc/common/ipc';
10
import { IExtensionManagementService, ILocalExtension, InstallExtensionEvent, DidInstallExtensionEvent, IGalleryExtension, LocalExtensionType, DidUninstallExtensionEvent, IExtensionIdentifier, IGalleryMetadata } from './extensionManagement';
11
import Event, { buffer } from 'vs/base/common/event';
J
Joao Moreno 已提交
12

J
Joao Moreno 已提交
13
export interface IExtensionManagementChannel extends IChannel {
J
Joao Moreno 已提交
14 15 16 17
	call(command: 'event:onInstallExtension'): TPromise<void>;
	call(command: 'event:onDidInstallExtension'): TPromise<void>;
	call(command: 'event:onUninstallExtension'): TPromise<void>;
	call(command: 'event:onDidUninstallExtension'): TPromise<void>;
18 19
	call(command: 'install', path: string): TPromise<void>;
	call(command: 'installFromGallery', extension: IGalleryExtension): TPromise<void>;
20
	call(command: 'uninstall', args: [ILocalExtension, boolean]): TPromise<void>;
J
Joao Moreno 已提交
21
	call(command: 'getInstalled'): TPromise<ILocalExtension[]>;
D
Dirk Baeumer 已提交
22
	call(command: string, arg?: any): TPromise<any>;
J
Joao Moreno 已提交
23 24
}

J
Joao Moreno 已提交
25
export class ExtensionManagementChannel implements IExtensionManagementChannel {
J
Joao Moreno 已提交
26

27 28
	onInstallExtension: Event<InstallExtensionEvent>;
	onDidInstallExtension: Event<DidInstallExtensionEvent>;
S
Sandeep Somavarapu 已提交
29
	onUninstallExtension: Event<IExtensionIdentifier>;
S
Sandeep Somavarapu 已提交
30
	onDidUninstallExtension: Event<DidUninstallExtensionEvent>;
31 32 33 34 35 36 37

	constructor(private service: IExtensionManagementService) {
		this.onInstallExtension = buffer(service.onInstallExtension, true);
		this.onDidInstallExtension = buffer(service.onDidInstallExtension, true);
		this.onUninstallExtension = buffer(service.onUninstallExtension, true);
		this.onDidUninstallExtension = buffer(service.onDidUninstallExtension, true);
	}
J
Joao Moreno 已提交
38

D
Dirk Baeumer 已提交
39
	call(command: string, arg?: any): TPromise<any> {
J
Joao Moreno 已提交
40
		switch (command) {
41 42 43 44
			case 'event:onInstallExtension': return eventToCall(this.onInstallExtension);
			case 'event:onDidInstallExtension': return eventToCall(this.onDidInstallExtension);
			case 'event:onUninstallExtension': return eventToCall(this.onUninstallExtension);
			case 'event:onDidUninstallExtension': return eventToCall(this.onDidUninstallExtension);
J
Joao Moreno 已提交
45
			case 'install': return this.service.install(arg);
S
Sandeep Somavarapu 已提交
46
			case 'installFromGallery': return this.service.installFromGallery(arg[0]);
47
			case 'uninstall': return this.service.uninstall(arg[0], arg[1]);
J
Joao Moreno 已提交
48
			case 'getInstalled': return this.service.getInstalled(arg);
49
			case 'updateMetadata': return this.service.updateMetadata(arg[0], arg[1]);
J
Joao Moreno 已提交
50
		}
51
		return undefined;
J
Joao Moreno 已提交
52 53 54
	}
}

J
Joao Moreno 已提交
55
export class ExtensionManagementChannelClient implements IExtensionManagementService {
J
Joao Moreno 已提交
56

57
	_serviceBrand: any;
J
Joao Moreno 已提交
58

J
Joao Moreno 已提交
59
	constructor(private channel: IExtensionManagementChannel) { }
J
Joao Moreno 已提交
60

J
Joao Moreno 已提交
61 62
	private _onInstallExtension = eventFromCall<InstallExtensionEvent>(this.channel, 'event:onInstallExtension');
	get onInstallExtension(): Event<InstallExtensionEvent> { return this._onInstallExtension; }
J
Joao Moreno 已提交
63

J
Joao Moreno 已提交
64 65
	private _onDidInstallExtension = eventFromCall<DidInstallExtensionEvent>(this.channel, 'event:onDidInstallExtension');
	get onDidInstallExtension(): Event<DidInstallExtensionEvent> { return this._onDidInstallExtension; }
J
Joao Moreno 已提交
66

S
Sandeep Somavarapu 已提交
67 68
	private _onUninstallExtension = eventFromCall<IExtensionIdentifier>(this.channel, 'event:onUninstallExtension');
	get onUninstallExtension(): Event<IExtensionIdentifier> { return this._onUninstallExtension; }
J
Joao Moreno 已提交
69

S
Sandeep Somavarapu 已提交
70 71
	private _onDidUninstallExtension = eventFromCall<DidUninstallExtensionEvent>(this.channel, 'event:onDidUninstallExtension');
	get onDidUninstallExtension(): Event<DidUninstallExtensionEvent> { return this._onDidUninstallExtension; }
J
Joao Moreno 已提交
72

73 74 75 76
	install(zipPath: string): TPromise<void> {
		return this.channel.call('install', zipPath);
	}

S
Sandeep Somavarapu 已提交
77 78
	installFromGallery(extension: IGalleryExtension): TPromise<void> {
		return this.channel.call('installFromGallery', [extension]);
J
Joao Moreno 已提交
79 80
	}

81 82
	uninstall(extension: ILocalExtension, force = false): TPromise<void> {
		return this.channel.call('uninstall', [extension, force]);
J
Joao Moreno 已提交
83 84
	}

J
Joao Moreno 已提交
85 86
	getInstalled(type: LocalExtensionType = null): TPromise<ILocalExtension[]> {
		return this.channel.call('getInstalled', type);
J
Joao Moreno 已提交
87
	}
88 89 90 91

	updateMetadata(local: ILocalExtension, metadata: IGalleryMetadata): TPromise<ILocalExtension> {
		return this.channel.call('updateMetadata', [local, metadata]);
	}
J
Joao Moreno 已提交
92
}