@@ -41,6 +41,7 @@ import { validateExtensionManifest } from 'vs/platform/extensions/common/extensi
41
41
import Severity from 'vs/base/common/severity' ;
42
42
import { IStringDictionary } from 'vs/base/common/collections' ;
43
43
import { IUserDataProfileService } from 'vs/workbench/services/userDataProfile/common/userDataProfile' ;
44
+ import { IUserDataProfile , IUserDataProfilesService } from 'vs/platform/userDataProfile/common/userDataProfile' ;
44
45
45
46
type GalleryExtensionInfo = { readonly id : string ; preRelease ?: boolean ; migrateStorageFrom ?: string } ;
46
47
type ExtensionInfo = { readonly id : string ; preRelease : boolean } ;
@@ -98,6 +99,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
98
99
@IStorageService private readonly storageService : IStorageService ,
99
100
@IProductService private readonly productService : IProductService ,
100
101
@IUserDataProfileService private readonly userDataProfileService : IUserDataProfileService ,
102
+ @IUserDataProfilesService private readonly userDataProfilesService : IUserDataProfilesService ,
101
103
@ILifecycleService lifecycleService : ILifecycleService ,
102
104
) {
103
105
super ( ) ;
@@ -435,24 +437,26 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
435
437
return null ;
436
438
}
437
439
438
- async addExtensionFromGallery ( galleryExtension : IGalleryExtension , metadata ?: Metadata ) : Promise < IExtension > {
440
+ async addExtensionFromGallery ( galleryExtension : IGalleryExtension , metadata ?: Metadata ) : Promise < IScannedExtension > {
439
441
const webExtension = await this . toWebExtensionFromGallery ( galleryExtension , metadata ) ;
440
442
return this . addWebExtension ( webExtension ) ;
441
443
}
442
444
443
- async addExtension ( location : URI , metadata ?: Metadata ) : Promise < IExtension > {
445
+ async addExtension ( location : URI , metadata ?: Metadata ) : Promise < IScannedExtension > {
444
446
const webExtension = await this . toWebExtension ( location , undefined , undefined , undefined , undefined , undefined , metadata ) ;
445
447
return this . addWebExtension ( webExtension ) ;
446
448
}
447
449
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 ) ) ) ;
450
453
}
451
454
452
455
private async addWebExtension ( webExtension : IWebExtension ) : Promise < IScannedExtension > {
453
456
const isSystem = ! ! ( await this . scanSystemExtensions ( ) ) . find ( e => areSameExtensions ( e . identifier , webExtension . identifier ) ) ;
454
457
const isBuiltin = ! ! webExtension . metadata ?. isBuiltin ;
455
458
const extension = await this . toScannedExtension ( webExtension , isBuiltin ) ;
459
+ const profile = webExtension . metadata ?. isApplicationScoped ? this . userDataProfilesService . defaultProfile : this . userDataProfileService . currentProfile ;
456
460
457
461
if ( isSystem ) {
458
462
await this . writeSystemExtensionsCache ( systemExtensions => {
@@ -473,21 +477,21 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
473
477
return customBuiltinExtensions ;
474
478
} ) ;
475
479
476
- const installedExtensions = await this . readInstalledExtensions ( ) ;
480
+ const installedExtensions = await this . readInstalledExtensions ( profile ) ;
477
481
// Also add to installed extensions if it is installed to update its version
478
482
if ( installedExtensions . some ( e => areSameExtensions ( e . identifier , webExtension . identifier ) ) ) {
479
- await this . addToInstalledExtensions ( webExtension ) ;
483
+ await this . addToInstalledExtensions ( webExtension , profile ) ;
480
484
}
481
485
return extension ;
482
486
}
483
487
484
488
// Add to installed extensions
485
- await this . addToInstalledExtensions ( webExtension ) ;
489
+ await this . addToInstalledExtensions ( webExtension , profile ) ;
486
490
return extension ;
487
491
}
488
492
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 => {
491
495
// Remove the existing extension to avoid duplicates
492
496
installedExtensions = installedExtensions . filter ( e => ! areSameExtensions ( e . identifier , webExtension . identifier ) ) ;
493
497
installedExtensions . push ( webExtension ) ;
@@ -496,7 +500,17 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
496
500
}
497
501
498
502
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
+
500
514
installedExtensions . sort ( ( a , b ) => a . identifier . id < b . identifier . id ? - 1 : a . identifier . id > b . identifier . id ? 1 : semver . rcompare ( a . version , b . version ) ) ;
501
515
const result = new Map < string , IScannedExtension > ( ) ;
502
516
for ( const webExtension of installedExtensions ) {
@@ -670,17 +684,12 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
670
684
return manifest ;
671
685
}
672
686
673
- private async readInstalledExtensions ( ) : Promise < IWebExtension [ ] > {
674
- await this . migratePackageNLSUris ( ) ;
675
- return this . withWebExtensions ( this . userDataProfileService . currentProfile . extensionsResource ) ;
676
- }
677
-
678
687
// TODO: @TylerLeonhardt /@Sandy 081: Delete after 6 months
679
688
private _migratePackageNLSUrisPromise : Promise < void > | undefined ;
680
689
private migratePackageNLSUris ( ) : Promise < void > {
681
690
if ( ! this . _migratePackageNLSUrisPromise ) {
682
691
this . _migratePackageNLSUrisPromise = ( async ( ) => {
683
- const webExtensions = await this . withWebExtensions ( this . userDataProfileService . currentProfile . extensionsResource ) ;
692
+ const webExtensions = await this . withWebExtensions ( this . userDataProfilesService . defaultProfile . extensionsResource ) ;
684
693
if ( webExtensions . some ( e => ! e . packageNLSUris && e . packageNLSUri ) ) {
685
694
const migratedExtensions = await Promise . all ( webExtensions . map ( async e => {
686
695
if ( ! e . packageNLSUris && e . packageNLSUri ) {
@@ -691,15 +700,22 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
691
700
}
692
701
return e ;
693
702
} ) ) ;
694
- await this . withWebExtensions ( this . userDataProfileService . currentProfile . extensionsResource , ( ) => migratedExtensions ) ;
703
+ await this . withWebExtensions ( this . userDataProfilesService . defaultProfile . extensionsResource , ( ) => migratedExtensions ) ;
695
704
}
696
705
} ) ( ) ;
697
706
}
698
707
return this . _migratePackageNLSUrisPromise ;
699
708
}
700
709
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 ) ;
703
719
}
704
720
705
721
private readCustomBuiltinExtensionsCache ( ) : Promise < IWebExtension [ ] > {
0 commit comments