Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/services/extensionManagement/electron-browser/nativeExtensionManagementService.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 { IChannel } from '../../../../base/parts/ipc/common/ipc.js';
7
import { DidChangeProfileEvent, IProfileAwareExtensionManagementService } from '../common/extensionManagement.js';
8
import { URI } from '../../../../base/common/uri.js';
9
import { IAllowedExtensionsService, ILocalExtension, InstallOptions } from '../../../../platform/extensionManagement/common/extensionManagement.js';
10
import { IUriIdentityService } from '../../../../platform/uriIdentity/common/uriIdentity.js';
11
import { IUserDataProfileService } from '../../userDataProfile/common/userDataProfile.js';
12
import { joinPath } from '../../../../base/common/resources.js';
13
import { Schemas } from '../../../../base/common/network.js';
14
import { ILogService } from '../../../../platform/log/common/log.js';
15
import { IDownloadService } from '../../../../platform/download/common/download.js';
16
import { IFileService } from '../../../../platform/files/common/files.js';
17
import { generateUuid } from '../../../../base/common/uuid.js';
18
import { ProfileAwareExtensionManagementChannelClient } from '../common/extensionManagementChannelClient.js';
19
import { ExtensionIdentifier, ExtensionType, isResolverExtension } from '../../../../platform/extensions/common/extensions.js';
20
import { INativeWorkbenchEnvironmentService } from '../../environment/electron-browser/environmentService.js';
21
import { IProductService } from '../../../../platform/product/common/productService.js';
22
23
export class NativeExtensionManagementService extends ProfileAwareExtensionManagementChannelClient implements IProfileAwareExtensionManagementService {
24
25
constructor(
26
channel: IChannel,
27
@IProductService productService: IProductService,
28
@IAllowedExtensionsService allowedExtensionsService: IAllowedExtensionsService,
29
@IUserDataProfileService userDataProfileService: IUserDataProfileService,
30
@IUriIdentityService uriIdentityService: IUriIdentityService,
31
@IFileService private readonly fileService: IFileService,
32
@IDownloadService private readonly downloadService: IDownloadService,
33
@INativeWorkbenchEnvironmentService private readonly nativeEnvironmentService: INativeWorkbenchEnvironmentService,
34
@ILogService private readonly logService: ILogService,
35
) {
36
super(channel, productService, allowedExtensionsService, userDataProfileService, uriIdentityService);
37
}
38
39
protected filterEvent(profileLocation: URI, isApplicationScoped: boolean): boolean {
40
return isApplicationScoped || this.uriIdentityService.extUri.isEqual(this.userDataProfileService.currentProfile.extensionsResource, profileLocation);
41
}
42
43
override async install(vsix: URI, options?: InstallOptions): Promise<ILocalExtension> {
44
const { location, cleanup } = await this.downloadVsix(vsix);
45
try {
46
return await super.install(location, options);
47
} finally {
48
await cleanup();
49
}
50
}
51
52
private async downloadVsix(vsix: URI): Promise<{ location: URI; cleanup: () => Promise<void> }> {
53
if (vsix.scheme === Schemas.file) {
54
return { location: vsix, async cleanup() { } };
55
}
56
this.logService.trace('Downloading extension from', vsix.toString());
57
const location = joinPath(this.nativeEnvironmentService.extensionsDownloadLocation, generateUuid());
58
await this.downloadService.download(vsix, location);
59
this.logService.info('Downloaded extension to', location.toString());
60
const cleanup = async () => {
61
try {
62
await this.fileService.del(location);
63
} catch (error) {
64
this.logService.error(error);
65
}
66
};
67
return { location, cleanup };
68
}
69
70
protected override async switchExtensionsProfile(previousProfileLocation: URI, currentProfileLocation: URI, preserveExtensions?: ExtensionIdentifier[]): Promise<DidChangeProfileEvent> {
71
if (this.nativeEnvironmentService.remoteAuthority) {
72
const previousInstalledExtensions = await this.getInstalled(ExtensionType.User, previousProfileLocation);
73
const resolverExtension = previousInstalledExtensions.find(e => isResolverExtension(e.manifest, this.nativeEnvironmentService.remoteAuthority));
74
if (resolverExtension) {
75
if (!preserveExtensions) {
76
preserveExtensions = [];
77
}
78
preserveExtensions.push(new ExtensionIdentifier(resolverExtension.identifier.id));
79
}
80
}
81
return super.switchExtensionsProfile(previousProfileLocation, currentProfileLocation, preserveExtensions);
82
}
83
}
84
85