dialogIpc.ts 1.6 KB
Newer Older
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.
 *--------------------------------------------------------------------------------------------*/

6
import { IChannel, IServerChannel } from 'vs/base/parts/ipc/common/ipc';
7
import { IDialogService, IConfirmation, IConfirmationResult, IShowResult } from 'vs/platform/dialogs/common/dialogs';
8
import Severity from 'vs/base/common/severity';
J
Joao Moreno 已提交
9
import { Event } from 'vs/base/common/event';
10

J
Joao Moreno 已提交
11
export class DialogChannel implements IServerChannel {
12

13
	constructor(@IDialogService private readonly dialogService: IDialogService) { }
J
Joao Moreno 已提交
14

15
	listen<T>(_: unknown, event: string): Event<T> {
J
Joao Moreno 已提交
16
		throw new Error(`Event not found: ${event}`);
17 18
	}

19
	call(_: unknown, command: string, args?: any[]): Promise<any> {
20
		switch (command) {
21 22
			case 'show': return this.dialogService.show(args![0], args![1], args![2]);
			case 'confirm': return this.dialogService.confirm(args![0]);
23
		}
B
Benjamin Pasero 已提交
24
		return Promise.reject(new Error('invalid command'));
25 26 27 28 29
	}
}

export class DialogChannelClient implements IDialogService {

30
	_serviceBrand: undefined;
31

J
Joao Moreno 已提交
32
	constructor(private channel: IChannel) { }
33

34
	show(severity: Severity, message: string, options: string[]): Promise<IShowResult> {
B
Benjamin Pasero 已提交
35
		return this.channel.call('show', [severity, message, options]);
36 37
	}

J
Johannes Rieken 已提交
38
	confirm(confirmation: IConfirmation): Promise<IConfirmationResult> {
B
Benjamin Pasero 已提交
39
		return this.channel.call('confirm', [confirmation]);
40
	}
41
}