Skip to content

Commit 836231f

Browse files
committed
adopt profiles in web extensions scanning
1 parent 89f0630 commit 836231f

File tree

4 files changed

+41
-25
lines changed

4 files changed

+41
-25
lines changed

src/vs/workbench/services/extensionManagement/browser/webExtensionsScannerService.ts

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import { validateExtensionManifest } from 'vs/platform/extensions/common/extensi
4141
import Severity from 'vs/base/common/severity';
4242
import { IStringDictionary } from 'vs/base/common/collections';
4343
import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile';
44+
import { IUserDataProfile, IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile';
4445

4546
type GalleryExtensionInfo = { readonly id: string; preRelease?: boolean; migrateStorageFrom?: string };
4647
type ExtensionInfo = { readonly id: string; preRelease: boolean };
@@ -98,6 +99,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
9899
@IStorageService private readonly storageService: IStorageService,
99100
@IProductService private readonly productService: IProductService,
100101
@IUserDataProfileService private readonly userDataProfileService: IUserDataProfileService,
102+
@IUserDataProfilesService private readonly userDataProfilesService: IUserDataProfilesService,
101103
@ILifecycleService lifecycleService: ILifecycleService,
102104
) {
103105
super();
@@ -435,24 +437,26 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
435437
return null;
436438
}
437439

438-
async addExtensionFromGallery(galleryExtension: IGalleryExtension, metadata?: Metadata): Promise<IExtension> {
440+
async addExtensionFromGallery(galleryExtension: IGalleryExtension, metadata?: Metadata): Promise<IScannedExtension> {
439441
const webExtension = await this.toWebExtensionFromGallery(galleryExtension, metadata);
440442
return this.addWebExtension(webExtension);
441443
}
442444

443-
async addExtension(location: URI, metadata?: Metadata): Promise<IExtension> {
445+
async addExtension(location: URI, metadata?: Metadata): Promise<IScannedExtension> {
444446
const webExtension = await this.toWebExtension(location, undefined, undefined, undefined, undefined, undefined, metadata);
445447
return this.addWebExtension(webExtension);
446448
}
447449

448-
async removeExtension(identifier: IExtensionIdentifier, version?: string): Promise<void> {
449-
await this.writeInstalledExtensions(installedExtensions => installedExtensions.filter(extension => !(areSameExtensions(extension.identifier, identifier) && (version ? extension.version === version : true))));
450+
async removeExtension(extension: IScannedExtension): Promise<void> {
451+
const profile = extension.metadata?.isApplicationScoped ? this.userDataProfilesService.defaultProfile : this.userDataProfileService.currentProfile;
452+
await this.writeInstalledExtensions(profile, installedExtensions => installedExtensions.filter(installedExtension => !areSameExtensions(installedExtension.identifier, extension.identifier)));
450453
}
451454

452455
private async addWebExtension(webExtension: IWebExtension): Promise<IScannedExtension> {
453456
const isSystem = !!(await this.scanSystemExtensions()).find(e => areSameExtensions(e.identifier, webExtension.identifier));
454457
const isBuiltin = !!webExtension.metadata?.isBuiltin;
455458
const extension = await this.toScannedExtension(webExtension, isBuiltin);
459+
const profile = webExtension.metadata?.isApplicationScoped ? this.userDataProfilesService.defaultProfile : this.userDataProfileService.currentProfile;
456460

457461
if (isSystem) {
458462
await this.writeSystemExtensionsCache(systemExtensions => {
@@ -473,21 +477,21 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
473477
return customBuiltinExtensions;
474478
});
475479

476-
const installedExtensions = await this.readInstalledExtensions();
480+
const installedExtensions = await this.readInstalledExtensions(profile);
477481
// Also add to installed extensions if it is installed to update its version
478482
if (installedExtensions.some(e => areSameExtensions(e.identifier, webExtension.identifier))) {
479-
await this.addToInstalledExtensions(webExtension);
483+
await this.addToInstalledExtensions(webExtension, profile);
480484
}
481485
return extension;
482486
}
483487

484488
// Add to installed extensions
485-
await this.addToInstalledExtensions(webExtension);
489+
await this.addToInstalledExtensions(webExtension, profile);
486490
return extension;
487491
}
488492

489-
private async addToInstalledExtensions(webExtension: IWebExtension): Promise<void> {
490-
await this.writeInstalledExtensions(installedExtensions => {
493+
private async addToInstalledExtensions(webExtension: IWebExtension, profile: IUserDataProfile): Promise<void> {
494+
await this.writeInstalledExtensions(profile, installedExtensions => {
491495
// Remove the existing extension to avoid duplicates
492496
installedExtensions = installedExtensions.filter(e => !areSameExtensions(e.identifier, webExtension.identifier));
493497
installedExtensions.push(webExtension);
@@ -496,7 +500,17 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
496500
}
497501

498502
private async scanInstalledExtensions(scanOptions?: ScanOptions): Promise<IScannedExtension[]> {
499-
const installedExtensions = await this.readInstalledExtensions();
503+
let installedExtensions = await this.readInstalledExtensions(this.userDataProfileService.currentProfile);
504+
505+
// If current profile is not a default profile, then add the application extensions to the list
506+
if (!this.userDataProfileService.currentProfile.isDefault) {
507+
// Remove application extensions from the non default profile
508+
installedExtensions = installedExtensions.filter(i => !i.metadata?.isApplicationScoped);
509+
// Add application extensions from the default profile to the list
510+
const defaultProfileExtensions = await this.readInstalledExtensions(this.userDataProfilesService.defaultProfile);
511+
installedExtensions.push(...defaultProfileExtensions.filter(i => i.metadata?.isApplicationScoped));
512+
}
513+
500514
installedExtensions.sort((a, b) => a.identifier.id < b.identifier.id ? -1 : a.identifier.id > b.identifier.id ? 1 : semver.rcompare(a.version, b.version));
501515
const result = new Map<string, IScannedExtension>();
502516
for (const webExtension of installedExtensions) {
@@ -670,17 +684,12 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
670684
return manifest;
671685
}
672686

673-
private async readInstalledExtensions(): Promise<IWebExtension[]> {
674-
await this.migratePackageNLSUris();
675-
return this.withWebExtensions(this.userDataProfileService.currentProfile.extensionsResource);
676-
}
677-
678687
// TODO: @TylerLeonhardt/@Sandy081: Delete after 6 months
679688
private _migratePackageNLSUrisPromise: Promise<void> | undefined;
680689
private migratePackageNLSUris(): Promise<void> {
681690
if (!this._migratePackageNLSUrisPromise) {
682691
this._migratePackageNLSUrisPromise = (async () => {
683-
const webExtensions = await this.withWebExtensions(this.userDataProfileService.currentProfile.extensionsResource);
692+
const webExtensions = await this.withWebExtensions(this.userDataProfilesService.defaultProfile.extensionsResource);
684693
if (webExtensions.some(e => !e.packageNLSUris && e.packageNLSUri)) {
685694
const migratedExtensions = await Promise.all(webExtensions.map(async e => {
686695
if (!e.packageNLSUris && e.packageNLSUri) {
@@ -691,15 +700,22 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
691700
}
692701
return e;
693702
}));
694-
await this.withWebExtensions(this.userDataProfileService.currentProfile.extensionsResource, () => migratedExtensions);
703+
await this.withWebExtensions(this.userDataProfilesService.defaultProfile.extensionsResource, () => migratedExtensions);
695704
}
696705
})();
697706
}
698707
return this._migratePackageNLSUrisPromise;
699708
}
700709

701-
private writeInstalledExtensions(updateFn: (extensions: IWebExtension[]) => IWebExtension[]): Promise<IWebExtension[]> {
702-
return this.withWebExtensions(this.userDataProfileService.currentProfile.extensionsResource, updateFn);
710+
private async readInstalledExtensions(profile: IUserDataProfile): Promise<IWebExtension[]> {
711+
if (profile.isDefault) {
712+
await this.migratePackageNLSUris();
713+
}
714+
return this.withWebExtensions(profile.extensionsResource);
715+
}
716+
717+
private writeInstalledExtensions(profile: IUserDataProfile, updateFn: (extensions: IWebExtension[]) => IWebExtension[]): Promise<IWebExtension[]> {
718+
return this.withWebExtensions(profile.extensionsResource, updateFn);
703719
}
704720

705721
private readCustomBuiltinExtensionsCache(): Promise<IWebExtension[]> {

src/vs/workbench/services/extensionManagement/common/extensionManagement.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import { Event } from 'vs/base/common/event';
77
import { createDecorator, refineServiceDecorator } from 'vs/platform/instantiation/common/instantiation';
88
import { IExtension, ExtensionType, IExtensionManifest } from 'vs/platform/extensions/common/extensions';
9-
import { IExtensionManagementService, IGalleryExtension, IExtensionIdentifier, ILocalExtension, InstallOptions, InstallExtensionEvent, DidUninstallExtensionEvent, InstallExtensionResult, Metadata, InstallVSIXOptions, UninstallExtensionEvent } from 'vs/platform/extensionManagement/common/extensionManagement';
9+
import { IExtensionManagementService, IGalleryExtension, ILocalExtension, InstallOptions, InstallExtensionEvent, DidUninstallExtensionEvent, InstallExtensionResult, Metadata, InstallVSIXOptions, UninstallExtensionEvent } from 'vs/platform/extensionManagement/common/extensionManagement';
1010
import { URI } from 'vs/base/common/uri';
1111
import { FileAccess } from 'vs/base/common/network';
1212

@@ -162,9 +162,9 @@ export interface IWebExtensionsScannerService {
162162
scanExtensionsUnderDevelopment(): Promise<IExtension[]>;
163163
scanExistingExtension(extensionLocation: URI, extensionType: ExtensionType): Promise<IScannedExtension | null>;
164164

165-
addExtension(location: URI, metadata?: Metadata): Promise<IExtension>;
166-
addExtensionFromGallery(galleryExtension: IGalleryExtension, metadata?: Metadata): Promise<IExtension>;
167-
removeExtension(identifier: IExtensionIdentifier, version?: string): Promise<void>;
165+
addExtension(location: URI, metadata?: Metadata): Promise<IScannedExtension>;
166+
addExtensionFromGallery(galleryExtension: IGalleryExtension, metadata?: Metadata): Promise<IScannedExtension>;
167+
removeExtension(extension: IScannedExtension, version?: string): Promise<void>;
168168

169169
scanMetadata(extensionLocation: URI): Promise<Metadata | undefined>;
170170
scanExtensionManifest(extensionLocation: URI): Promise<IExtensionManifest | null>;

src/vs/workbench/services/extensionManagement/common/webExtensionManagementService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,6 @@ class UninstallExtensionTask extends AbstractExtensionTask<void> implements IUni
196196
}
197197

198198
protected doRun(token: CancellationToken): Promise<void> {
199-
return this.webExtensionsScannerService.removeExtension(this.extension.identifier);
199+
return this.webExtensionsScannerService.removeExtension(this.extension);
200200
}
201201
}

src/vs/workbench/test/browser/workbenchTestServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,7 @@ export class TestWebExtensionsScannerService implements IWebExtensionsScannerSer
20142014
addExtensionFromGallery(galleryExtension: IGalleryExtension, metadata?: Partial<IGalleryMetadata & { isApplicationScoped: boolean; isMachineScoped: boolean; isBuiltin: boolean; isSystem: boolean; updated: boolean; preRelease: boolean; installedTimestamp: number }> | undefined): Promise<IExtension> {
20152015
throw new Error('Method not implemented.');
20162016
}
2017-
removeExtension(identifier: IExtensionIdentifier, version?: string | undefined): Promise<void> {
2017+
removeExtension(): Promise<void> {
20182018
throw new Error('Method not implemented.');
20192019
}
20202020
scanMetadata(extensionLocation: URI): Promise<Partial<IGalleryMetadata & { isApplicationScoped: boolean; isMachineScoped: boolean; isBuiltin: boolean; isSystem: boolean; updated: boolean; preRelease: boolean; installedTimestamp: number }> | undefined> {

0 commit comments

Comments
 (0)