1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
import { IProfileAwareExtensionManagementService } from 'vs/workbench/services/extensionManagement/common/extensionManagement';
import { ExtensionManagementChannelClient } from 'vs/platform/extensionManagement/common/extensionManagementIpc';
import { URI } from 'vs/base/common/uri';
import { IGalleryExtension, ILocalExtension, InstallOptions, InstallVSIXOptions, UninstallOptions } from 'vs/platform/extensionManagement/common/extensionManagement';
import { ExtensionIdentifier, ExtensionType } from 'vs/platform/extensions/common/extensions';
import { Emitter, Event } from 'vs/base/common/event';
import { IUriIdentityService } from 'vs/platform/uriIdentity/common/uriIdentity';
import { delta } from 'vs/base/common/arrays';
import { compare } from 'vs/base/common/strings';
import { DisposableStore } from 'vs/base/common/lifecycle';
export class NativeProfileAwareExtensionManagementService extends ExtensionManagementChannelClient implements IProfileAwareExtensionManagementService {
private readonly disposables = this._register(new DisposableStore());
override get onInstallExtension() { return Event.filter(super.onInstallExtension, e => this.filterEvent(e), this.disposables); }
override get onDidInstallExtensions() {
return Event.filter(
Event.map(super.onDidInstallExtensions, results => results.filter(e => this.filterEvent(e)), this.disposables),
results => results.length > 0, this.disposables);
}
override get onUninstallExtension() { return Event.filter(super.onUninstallExtension, e => this.filterEvent(e), this.disposables); }
override get onDidUninstallExtension() { return Event.filter(super.onDidUninstallExtension, e => this.filterEvent(e), this.disposables); }
private readonly _onDidChangeProfileExtensions = this._register(new Emitter<{ readonly added: ILocalExtension[]; readonly removed: ILocalExtension[] }>());
readonly onDidChangeProfileExtensions = this._onDidChangeProfileExtensions.event;
constructor(channel: IChannel, public extensionsProfileResource: URI | undefined,
@IUriIdentityService private readonly uriIdentityService: IUriIdentityService,
) {
super(channel);
}
private filterEvent({ profileLocation, applicationScoped }: { profileLocation?: URI; applicationScoped?: boolean }): boolean {
return applicationScoped || this.uriIdentityService.extUri.isEqual(this.extensionsProfileResource, profileLocation);
}
override install(vsix: URI, options?: InstallVSIXOptions): Promise<ILocalExtension> {
return super.install(vsix, { ...options, profileLocation: this.extensionsProfileResource });
}
override installFromGallery(extension: IGalleryExtension, installOptions?: InstallOptions): Promise<ILocalExtension> {
return super.installFromGallery(extension, { ...installOptions, profileLocation: this.extensionsProfileResource });
}
override uninstall(extension: ILocalExtension, options?: UninstallOptions): Promise<void> {
return super.uninstall(extension, { ...options, profileLocation: this.extensionsProfileResource });
}
override getInstalled(type: ExtensionType | null = null): Promise<ILocalExtension[]> {
return super.getInstalled(type, this.extensionsProfileResource);
}
async switchExtensionsProfile(extensionsProfileResource: URI | undefined): Promise<void> {
if (this.uriIdentityService.extUri.isEqual(extensionsProfileResource, this.extensionsProfileResource)) {
return;
}
const oldExtensions = await this.getInstalled(ExtensionType.User);
this.extensionsProfileResource = extensionsProfileResource;
const newExtensions = await this.getInstalled(ExtensionType.User);
const { added, removed } = delta(oldExtensions, newExtensions, (a, b) => compare(`${ExtensionIdentifier.toKey(a.identifier.id)}@${a.manifest.version}`, `${ExtensionIdentifier.toKey(b.identifier.id)}@${b.manifest.version}`));
if (added.length || removed.length) {
this._onDidChangeProfileExtensions.fire({ added, removed });
}
}
}
|