|
| 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 { IChannel } from 'vs/base/parts/ipc/common/ipc'; |
| 7 | +import { Event } from 'vs/base/common/event'; |
| 8 | +import { ILocalExtension, IGalleryExtension, InstallOptions, InstallVSIXOptions, UninstallOptions } from 'vs/platform/extensionManagement/common/extensionManagement'; |
| 9 | +import { URI } from 'vs/base/common/uri'; |
| 10 | +import { ExtensionType } from 'vs/platform/extensions/common/extensions'; |
| 11 | +import { IProfileAwareExtensionManagementService } from 'vs/workbench/services/extensionManagement/common/extensionManagement'; |
| 12 | +import { ExtensionManagementChannelClient } from 'vs/platform/extensionManagement/common/extensionManagementIpc'; |
| 13 | +import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity'; |
| 14 | +import { IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile'; |
| 15 | + |
| 16 | +export class RemoteExtensionManagementService extends ExtensionManagementChannelClient implements IProfileAwareExtensionManagementService { |
| 17 | + |
| 18 | + readonly onDidChangeProfile = Event.None; |
| 19 | + get onProfileAwareInstallExtension() { return super.onInstallExtension; } |
| 20 | + get onProfileAwareDidInstallExtensions() { return super.onDidInstallExtensions; } |
| 21 | + get onProfileAwareUninstallExtension() { return super.onUninstallExtension; } |
| 22 | + get onProfileAwareDidUninstallExtension() { return super.onDidUninstallExtension; } |
| 23 | + |
| 24 | + constructor( |
| 25 | + channel: IChannel, |
| 26 | + @IUserDataProfilesService private readonly userDataProfileService: IUserDataProfilesService, |
| 27 | + @IUriIdentityService private readonly uriIdentityService: IUriIdentityService, |
| 28 | + ) { |
| 29 | + super(channel); |
| 30 | + } |
| 31 | + |
| 32 | + override getInstalled(type: ExtensionType | null = null, profileLocation?: URI): Promise<ILocalExtension[]> { |
| 33 | + this.validateProfileLocation({ profileLocation }); |
| 34 | + return super.getInstalled(type); |
| 35 | + } |
| 36 | + |
| 37 | + override uninstall(extension: ILocalExtension, options?: UninstallOptions): Promise<void> { |
| 38 | + options = this.validateProfileLocation(options); |
| 39 | + return super.uninstall(extension, options); |
| 40 | + } |
| 41 | + |
| 42 | + override async install(vsix: URI, options?: InstallVSIXOptions): Promise<ILocalExtension> { |
| 43 | + options = this.validateProfileLocation(options); |
| 44 | + return super.install(vsix, options); |
| 45 | + } |
| 46 | + |
| 47 | + override async installFromGallery(extension: IGalleryExtension, options?: InstallOptions): Promise<ILocalExtension> { |
| 48 | + options = this.validateProfileLocation(options); |
| 49 | + return super.installFromGallery(extension, options); |
| 50 | + } |
| 51 | + |
| 52 | + private validateProfileLocation<T extends { profileLocation?: URI }>(options?: T): T | undefined { |
| 53 | + if (options?.profileLocation) { |
| 54 | + if (!this.uriIdentityService.extUri.isEqual(options?.profileLocation, this.userDataProfileService.defaultProfile.extensionsResource)) { |
| 55 | + throw new Error('This operataion is not supported in remote scenario'); |
| 56 | + } |
| 57 | + options = { ...options, profileLocation: undefined }; |
| 58 | + } |
| 59 | + return options; |
| 60 | + } |
| 61 | + |
| 62 | +} |
0 commit comments