extensionManagementServerService.ts 3.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 { localize } from 'vs/nls';
A
Alex Dima 已提交
7
import { Schemas } from 'vs/base/common/network';
8
import { IExtensionManagementServer, IExtensionManagementServerService } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
9
import { ExtensionManagementChannelClient } from 'vs/platform/extensionManagement/common/extensionManagementIpc';
10 11
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
12
import { ISharedProcessService } from 'vs/platform/ipc/electron-browser/sharedProcessService';
13
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
14
import { NativeRemoteExtensionManagementService } from 'vs/workbench/services/extensionManagement/electron-sandbox/remoteExtensionManagementService';
15
import { ILabelService } from 'vs/platform/label/common/label';
16
import { IExtension } from 'vs/platform/extensions/common/extensions';
17
import { IExtensionGalleryService } from 'vs/platform/extensionManagement/common/extensionManagement';
18
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
19 20 21

export class ExtensionManagementServerService implements IExtensionManagementServerService {

22
	declare readonly _serviceBrand: undefined;
23

24
	private readonly _localExtensionManagementServer: IExtensionManagementServer;
25
	public get localExtensionManagementServer(): IExtensionManagementServer { return this._localExtensionManagementServer; }
S
Rename  
Sandeep Somavarapu 已提交
26
	readonly remoteExtensionManagementServer: IExtensionManagementServer | null = null;
27
	readonly webExtensionManagementServer: IExtensionManagementServer | null = null;
28 29

	constructor(
30
		@ISharedProcessService sharedProcessService: ISharedProcessService,
31
		@IRemoteAgentService remoteAgentService: IRemoteAgentService,
32
		@ILabelService labelService: ILabelService,
33
		@IExtensionGalleryService galleryService: IExtensionGalleryService,
34
		@IInstantiationService instantiationService: IInstantiationService,
35
	) {
36
		const localExtensionManagementService = new ExtensionManagementChannelClient(sharedProcessService.getChannel('extensions'));
37

38
		this._localExtensionManagementServer = { extensionManagementService: localExtensionManagementService, id: 'local', label: localize('local', "Local") };
S
tweaks  
Sandeep Somavarapu 已提交
39 40
		const remoteAgentConnection = remoteAgentService.getConnection();
		if (remoteAgentConnection) {
41
			const extensionManagementService = instantiationService.createInstance(NativeRemoteExtensionManagementService, remoteAgentConnection.getChannel<IChannel>('extensions'), this.localExtensionManagementServer);
42
			this.remoteExtensionManagementServer = {
43
				id: 'remote',
44
				extensionManagementService,
45
				get label() { return labelService.getHostLabel(Schemas.vscodeRemote, remoteAgentConnection!.remoteAuthority) || localize('remote', "Remote"); }
46
			};
S
tweaks  
Sandeep Somavarapu 已提交
47
		}
48 49
	}

50 51
	getExtensionManagementServer(extension: IExtension): IExtensionManagementServer {
		if (extension.location.scheme === Schemas.file) {
S
tweaks  
Sandeep Somavarapu 已提交
52 53
			return this.localExtensionManagementServer;
		}
54
		if (this.remoteExtensionManagementServer && extension.location.scheme === Schemas.vscodeRemote) {
S
Rename  
Sandeep Somavarapu 已提交
55
			return this.remoteExtensionManagementServer;
S
tweaks  
Sandeep Somavarapu 已提交
56
		}
57
		throw new Error(`Invalid Extension ${extension.location}`);
58
	}
59 60
}

61
registerSingleton(IExtensionManagementServerService, ExtensionManagementServerService);