Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/download/common/downloadIpc.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import { Event } from '../../../base/common/event.js';
7
import { URI } from '../../../base/common/uri.js';
8
import { IURITransformer } from '../../../base/common/uriIpc.js';
9
import { IChannel, IServerChannel } from '../../../base/parts/ipc/common/ipc.js';
10
import { IDownloadService } from './download.js';
11
12
export class DownloadServiceChannel implements IServerChannel {
13
14
constructor(private readonly service: IDownloadService) { }
15
16
listen(_: unknown, event: string, arg?: any): Event<any> {
17
throw new Error('Invalid listen');
18
}
19
20
call(context: any, command: string, args?: any): Promise<any> {
21
switch (command) {
22
case 'download': return this.service.download(URI.revive(args[0]), URI.revive(args[1]));
23
}
24
throw new Error('Invalid call');
25
}
26
}
27
28
export class DownloadServiceChannelClient implements IDownloadService {
29
30
declare readonly _serviceBrand: undefined;
31
32
constructor(private channel: IChannel, private getUriTransformer: () => IURITransformer | null) { }
33
34
async download(from: URI, to: URI): Promise<void> {
35
const uriTransformer = this.getUriTransformer();
36
if (uriTransformer) {
37
from = uriTransformer.transformOutgoingURI(from);
38
to = uriTransformer.transformOutgoingURI(to);
39
}
40
await this.channel.call('download', [from, to]);
41
}
42
}
43
44