diff options
author | Sandeep Somavarapu <sasomava@microsoft.com> | 2022-07-07 19:49:41 +0300 |
---|---|---|
committer | Sandeep Somavarapu <sasomava@microsoft.com> | 2022-07-07 19:49:41 +0300 |
commit | 7f8fdb3b32eaa3cd769b80b0937900636b45e448 (patch) | |
tree | 46480c996103fb4d45628b9e9ce0c219b3b3b820 /src/vs/platform/extensionManagement/node/extensionManagementService.ts | |
parent | 6037448e13801c02e9949c46d62a5c378e222b27 (diff) |
adopt extension installation in profiles in web
Diffstat (limited to 'src/vs/platform/extensionManagement/node/extensionManagementService.ts')
-rw-r--r-- | src/vs/platform/extensionManagement/node/extensionManagementService.ts | 92 |
1 files changed, 86 insertions, 6 deletions
diff --git a/src/vs/platform/extensionManagement/node/extensionManagementService.ts b/src/vs/platform/extensionManagement/node/extensionManagementService.ts index 56ea181d99e..5171a2fa2e4 100644 --- a/src/vs/platform/extensionManagement/node/extensionManagementService.ts +++ b/src/vs/platform/extensionManagement/node/extensionManagementService.ts @@ -65,21 +65,23 @@ export class ExtensionManagementService extends AbstractExtensionManagementServi private readonly manifestCache: ExtensionsManifestCache; private readonly extensionsDownloader: ExtensionsDownloader; + private readonly installGalleryExtensionsTasks = new Map<string, InstallGalleryExtensionTask>(); + constructor( @IExtensionGalleryService galleryService: IExtensionGalleryService, @ITelemetryService telemetryService: ITelemetryService, @ILogService logService: ILogService, @INativeEnvironmentService private readonly environmentService: INativeEnvironmentService, @IExtensionsScannerService private readonly extensionsScannerService: IExtensionsScannerService, - @IExtensionsProfileScannerService extensionsProfileScannerService: IExtensionsProfileScannerService, + @IExtensionsProfileScannerService private readonly extensionsProfileScannerService: IExtensionsProfileScannerService, @IDownloadService private downloadService: IDownloadService, @IInstantiationService instantiationService: IInstantiationService, @IFileService private readonly fileService: IFileService, @IProductService productService: IProductService, @IUriIdentityService uriIdentityService: IUriIdentityService, - @IUserDataProfilesService userDataProfilesService: IUserDataProfilesService, + @IUserDataProfilesService private readonly userDataProfilesService: IUserDataProfilesService, ) { - super(userDataProfilesService, uriIdentityService, galleryService, extensionsProfileScannerService, telemetryService, logService, productService); + super(galleryService, telemetryService, logService, productService); const extensionLifecycle = this._register(instantiationService.createInstance(ExtensionsLifecycle)); this.extensionsScanner = this._register(instantiationService.createInstance(ExtensionsScanner, extension => extensionLifecycle.postUninstall(extension))); this.manifestCache = this._register(new ExtensionsManifestCache(environmentService, this)); @@ -176,11 +178,28 @@ export class ExtensionManagementService extends AbstractExtensionManagementServi return downloadedLocation; } - protected createDefaultInstallExtensionTask(manifest: IExtensionManifest, extension: URI | IGalleryExtension, options: ServerInstallOptions & ServerInstallVSIXOptions): IInstallExtensionTask { - return URI.isUri(extension) ? new InstallVSIXTask(manifest, extension, options, this.galleryService, this.extensionsScanner, this.logService) : new InstallGalleryExtensionTask(manifest, extension, options, this.extensionsDownloader, this.extensionsScanner, this.logService); + protected createInstallExtensionTask(manifest: IExtensionManifest, extension: URI | IGalleryExtension, options: ServerInstallOptions & ServerInstallVSIXOptions): IInstallExtensionTask { + let installExtensionTask: IInstallExtensionTask | undefined; + if (URI.isUri(extension)) { + installExtensionTask = new InstallVSIXTask(manifest, extension, options, this.galleryService, this.extensionsScanner, this.logService); + } else { + const key = ExtensionKey.create(extension).toString(); + installExtensionTask = this.installGalleryExtensionsTasks.get(key); + if (!installExtensionTask) { + this.installGalleryExtensionsTasks.set(key, installExtensionTask = new InstallGalleryExtensionTask(manifest, extension, options, this.extensionsDownloader, this.extensionsScanner, this.logService)); + installExtensionTask.waitUntilTaskIsFinished().then(() => this.installGalleryExtensionsTasks.delete(key)); + } + } + if (options.profileLocation && this.userDataProfilesService.defaultProfile.extensionsResource) { + return new InstallExtensionInProfileTask(installExtensionTask, options.profileLocation, this.userDataProfilesService.defaultProfile.extensionsResource, this.extensionsProfileScannerService); + } + return installExtensionTask; } - protected createDefaultUninstallExtensionTask(extension: ILocalExtension, options: ServerUninstallOptions): IUninstallExtensionTask { + protected createUninstallExtensionTask(extension: ILocalExtension, options: ServerUninstallOptions): IUninstallExtensionTask { + if (options.profileLocation && this.userDataProfilesService.defaultProfile.extensionsResource) { + return new UninstallExtensionFromProfileTask(extension, options.profileLocation, this.userDataProfilesService, this.extensionsProfileScannerService); + } return new UninstallExtensionTask(extension, options, this.extensionsScanner); } @@ -706,6 +725,44 @@ class InstallVSIXTask extends InstallExtensionTask { } } +class InstallExtensionInProfileTask implements IInstallExtensionTask { + + readonly identifier = this.task.identifier; + readonly source = this.task.source; + readonly operation = this.task.operation; + + private readonly promise: Promise<{ local: ILocalExtension; metadata: Metadata }>; + + constructor( + private readonly task: IInstallExtensionTask, + readonly profileLocation: URI, + private readonly defaultProfileLocation: URI, + private readonly extensionsProfileScannerService: IExtensionsProfileScannerService, + ) { + this.promise = this.waitAndAddExtensionToProfile(); + } + + private async waitAndAddExtensionToProfile(): Promise<{ local: ILocalExtension; metadata: Metadata }> { + const result = await this.task.waitUntilTaskIsFinished(); + const profileLocation = result.local.isApplicationScoped ? this.defaultProfileLocation : this.profileLocation; + await this.extensionsProfileScannerService.addExtensionsToProfile([[result.local, result.metadata]], profileLocation); + return result; + } + + async run(): Promise<{ local: ILocalExtension; metadata: Metadata }> { + await this.task.run(); + return this.promise; + } + + waitUntilTaskIsFinished(): Promise<{ local: ILocalExtension; metadata: Metadata }> { + return this.promise; + } + + cancel(): void { + return this.task.cancel(); + } +} + class UninstallExtensionTask extends AbstractExtensionTask<void> implements IUninstallExtensionTask { constructor( @@ -745,3 +802,26 @@ class UninstallExtensionTask extends AbstractExtensionTask<void> implements IUni } } + +class UninstallExtensionFromProfileTask extends AbstractExtensionTask<void> implements IUninstallExtensionTask { + + constructor( + readonly extension: ILocalExtension, + private readonly profileLocation: URI, + private readonly userDataProfilesService: IUserDataProfilesService, + private readonly extensionsProfileScannerService: IExtensionsProfileScannerService, + ) { + super(); + } + + protected async doRun(token: CancellationToken): Promise<void> { + const promises: Promise<any>[] = []; + promises.push(this.extensionsProfileScannerService.removeExtensionFromProfile(this.extension.identifier, this.profileLocation)); + if (this.extension.isApplicationScoped && this.userDataProfilesService.defaultProfile.extensionsResource) { + promises.push(this.extensionsProfileScannerService.removeExtensionFromProfile(this.extension.identifier, this.userDataProfilesService.defaultProfile.extensionsResource)); + } + await Promise.all(promises); + } + +} + |