localizationsIpc.ts 1.7 KB
Newer Older
S
Sandeep Somavarapu 已提交
1 2 3 4 5
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

J
Joao Moreno 已提交
6
import { IChannel, IServerChannel } from 'vs/base/parts/ipc/node/ipc';
J
Joao Moreno 已提交
7
import { Event } from 'vs/base/common/event';
8
import { ILocalizationsService, LanguageType } from 'vs/platform/localizations/common/localizations';
9
import { ISharedProcessService } from 'vs/platform/sharedProcess/node/sharedProcessService';
S
Sandeep Somavarapu 已提交
10

J
Joao Moreno 已提交
11
export class LocalizationsChannel implements IServerChannel {
S
Sandeep Somavarapu 已提交
12 13 14 15

	onDidLanguagesChange: Event<void>;

	constructor(private service: ILocalizationsService) {
J
Joao Moreno 已提交
16
		this.onDidLanguagesChange = Event.buffer(service.onDidLanguagesChange, true);
S
Sandeep Somavarapu 已提交
17 18
	}

J
Joao Moreno 已提交
19
	listen(_, event: string): Event<any> {
J
Joao Moreno 已提交
20 21 22 23
		switch (event) {
			case 'onDidLanguagesChange': return this.onDidLanguagesChange;
		}

24
		throw new Error(`Event not found: ${event}`);
J
Joao Moreno 已提交
25 26
	}

J
Johannes Rieken 已提交
27
	call(_, command: string, arg?: any): Promise<any> {
S
Sandeep Somavarapu 已提交
28
		switch (command) {
29
			case 'getLanguageIds': return this.service.getLanguageIds(arg);
S
Sandeep Somavarapu 已提交
30
		}
31 32

		throw new Error(`Call not found: ${command}`);
S
Sandeep Somavarapu 已提交
33 34 35 36 37 38 39
	}
}

export class LocalizationsChannelClient implements ILocalizationsService {

	_serviceBrand: any;

40 41 42 43 44
	private channel: IChannel;

	constructor(@ISharedProcessService sharedProcessService: ISharedProcessService) {
		this.channel = sharedProcessService.getChannel('localizations');
	}
S
Sandeep Somavarapu 已提交
45

J
Joao Moreno 已提交
46
	get onDidLanguagesChange(): Event<void> { return this.channel.listen('onDidLanguagesChange'); }
S
Sandeep Somavarapu 已提交
47

J
Johannes Rieken 已提交
48
	getLanguageIds(type?: LanguageType): Promise<string[]> {
49
		return this.channel.call('getLanguageIds', type);
S
Sandeep Somavarapu 已提交
50 51
	}
}