@@ -18,10 +18,10 @@ import { CancellationToken } from 'vs/base/common/cancellation';
18
18
import { IExtensionGalleryService , IExtensionInfo , IGalleryExtension , IGalleryMetadata , Metadata } from 'vs/platform/extensionManagement/common/extensionManagement' ;
19
19
import { areSameExtensions , getGalleryExtensionId , getExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil' ;
20
20
import { Disposable } from 'vs/base/common/lifecycle' ;
21
- import { localizeManifest } from 'vs/platform/extensionManagement/common/extensionNls' ;
21
+ import { ITranslations , localizeManifest } from 'vs/platform/extensionManagement/common/extensionNls' ;
22
22
import { localize } from 'vs/nls' ;
23
23
import * as semver from 'vs/base/common/semver/semver' ;
24
- import { isString } from 'vs/base/common/types' ;
24
+ import { isString , isUndefined } from 'vs/base/common/types' ;
25
25
import { getErrorMessage } from 'vs/base/common/errors' ;
26
26
import { ResourceMap } from 'vs/base/common/map' ;
27
27
import { IExtensionManifestPropertiesService } from 'vs/workbench/services/extensions/common/extensionManifestPropertiesService' ;
@@ -66,6 +66,7 @@ interface IStoredWebExtension {
66
66
readonly packageNLSUri ?: UriComponents ;
67
67
readonly packageNLSUris ?: IStringDictionary < UriComponents > ;
68
68
readonly fallbackPackageNLSUri ?: UriComponents ;
69
+ readonly defaultManifestTranslations ?: ITranslations | null ;
69
70
readonly metadata ?: Metadata ;
70
71
}
71
72
@@ -81,6 +82,7 @@ interface IWebExtension {
81
82
packageNLSUris ?: Map < string , URI > ;
82
83
bundleNLSUris ?: Map < string , URI > ;
83
84
fallbackPackageNLSUri ?: URI ;
85
+ defaultManifestTranslations ?: ITranslations | null ;
84
86
metadata ?: Metadata ;
85
87
}
86
88
@@ -329,6 +331,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
329
331
if ( ! this . _updateCustomBuiltinExtensionsCachePromise ) {
330
332
this . _updateCustomBuiltinExtensionsCachePromise = ( async ( ) => {
331
333
this . logService . info ( 'Updating additional builtin extensions cache' ) ;
334
+ const cached = await this . getCustomBuiltinExtensionsFromCache ( ) ;
332
335
const webExtensions : IWebExtension [ ] = [ ] ;
333
336
const { extensions } = await this . readCustomBuiltinExtensionsInfoFromEnv ( ) ;
334
337
if ( extensions . length ) {
@@ -339,7 +342,9 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
339
342
}
340
343
await Promise . all ( [ ...galleryExtensionsMap . values ( ) ] . map ( async gallery => {
341
344
try {
342
- webExtensions . push ( await this . toWebExtensionFromGallery ( gallery , { isPreReleaseVersion : gallery . properties . isPreReleaseVersion , preRelease : gallery . properties . isPreReleaseVersion , isBuiltin : true } ) ) ;
345
+ const webExtension = cached . find ( e => areSameExtensions ( e . identifier , gallery . identifier ) && e . version === gallery . version )
346
+ ?? await this . toWebExtensionFromGallery ( gallery , { isPreReleaseVersion : gallery . properties . isPreReleaseVersion , preRelease : gallery . properties . isPreReleaseVersion , isBuiltin : true } ) ;
347
+ webExtensions . push ( webExtension ) ;
343
348
} catch ( error ) {
344
349
this . logService . info ( `Ignoring additional builtin extension ${ gallery . identifier . id } because there is an error while converting it into web extension` , getErrorMessage ( error ) ) ;
345
350
}
@@ -611,6 +616,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
611
616
fallbackPackageNLSUri = undefined ;
612
617
}
613
618
}
619
+ const defaultManifestTranslations : ITranslations | null | undefined = fallbackPackageNLSUri ? await this . getTranslations ( fallbackPackageNLSUri ) : null ;
614
620
615
621
if ( bundleNLSUris === undefined && manifest . browser ) {
616
622
const englishStringsUri = joinPath (
@@ -637,6 +643,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
637
643
packageNLSUris,
638
644
bundleNLSUris,
639
645
fallbackPackageNLSUri : fallbackPackageNLSUri ? fallbackPackageNLSUri : undefined ,
646
+ defaultManifestTranslations,
640
647
metadata,
641
648
} ;
642
649
}
@@ -666,10 +673,12 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
666
673
ImplicitActivationEvents . updateManifest ( manifest ) ;
667
674
668
675
const packageNLSUri = webExtension . packageNLSUris ?. get ( Language . value ( ) . toLowerCase ( ) ) ;
669
- if ( packageNLSUri || webExtension . fallbackPackageNLSUri ) {
670
- manifest = packageNLSUri
671
- ? await this . translateManifest ( manifest , packageNLSUri , webExtension . fallbackPackageNLSUri )
672
- : await this . translateManifest ( manifest , webExtension . fallbackPackageNLSUri ! ) ;
676
+ const fallbackPackageNLS = webExtension . defaultManifestTranslations ?? webExtension . fallbackPackageNLSUri ;
677
+
678
+ if ( packageNLSUri ) {
679
+ manifest = await this . translateManifest ( manifest , packageNLSUri , fallbackPackageNLS ) ;
680
+ } else if ( fallbackPackageNLS ) {
681
+ manifest = await this . translateManifest ( manifest , fallbackPackageNLS ) ;
673
682
}
674
683
675
684
const uuid = ( < IGalleryMetadata | undefined > webExtension . metadata ) ?. id ;
@@ -716,12 +725,12 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
716
725
return [ ] ;
717
726
}
718
727
719
- private async translateManifest ( manifest : IExtensionManifest , nlsURL : URI , fallbackNlsURL ?: URI ) : Promise < IExtensionManifest > {
728
+ private async translateManifest ( manifest : IExtensionManifest , nlsURL : ITranslations | URI , fallbackNLS ?: ITranslations | URI ) : Promise < IExtensionManifest > {
720
729
try {
721
- const content = await this . extensionResourceLoaderService . readExtensionResource ( nlsURL ) ;
722
- const fallbackContent = fallbackNlsURL ? await this . extensionResourceLoaderService . readExtensionResource ( fallbackNlsURL ) : undefined ;
723
- if ( content ) {
724
- manifest = localizeManifest ( manifest , JSON . parse ( content ) , fallbackContent ? JSON . parse ( fallbackContent ) : undefined ) ;
730
+ const translations = URI . isUri ( nlsURL ) ? await this . getTranslations ( nlsURL ) : nlsURL ;
731
+ const fallbackTranslations = URI . isUri ( fallbackNLS ) ? await this . getTranslations ( fallbackNLS ) : fallbackNLS ;
732
+ if ( translations ) {
733
+ manifest = localizeManifest ( manifest , translations , fallbackTranslations ) ;
725
734
}
726
735
} catch ( error ) { /* ignore */ }
727
736
return manifest ;
@@ -756,6 +765,16 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
756
765
return JSON . parse ( content ) ;
757
766
}
758
767
768
+ private async getTranslations ( nlsUrl : URI ) : Promise < ITranslations | undefined > {
769
+ try {
770
+ const content = await this . extensionResourceLoaderService . readExtensionResource ( nlsUrl ) ;
771
+ return JSON . parse ( content ) ;
772
+ } catch ( error ) {
773
+ this . logService . error ( `Error while fetching translations of an extension` , nlsUrl . toString ( ) , getErrorMessage ( error ) ) ;
774
+ }
775
+ return undefined ;
776
+ }
777
+
759
778
private async readInstalledExtensions ( profileLocation : URI ) : Promise < IWebExtension [ ] > {
760
779
if ( this . uriIdentityService . extUri . isEqual ( profileLocation , this . userDataProfilesService . defaultProfile . extensionsResource ) ) {
761
780
await this . migratePackageNLSUris ( ) ;
@@ -814,6 +833,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
814
833
changelogUri : URI . revive ( e . changelogUri ) ,
815
834
packageNLSUris,
816
835
fallbackPackageNLSUri : URI . revive ( e . fallbackPackageNLSUri ) ,
836
+ defaultManifestTranslations : e . defaultManifestTranslations ,
817
837
packageNLSUri : URI . revive ( e . packageNLSUri ) ,
818
838
metadata : e . metadata ,
819
839
} ) ;
@@ -852,6 +872,20 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
852
872
this . logService . error ( `Error while updating manifest of an extension in ${ file . toString ( ) } ` , webExtension . identifier . id , getErrorMessage ( error ) ) ;
853
873
}
854
874
}
875
+ if ( isUndefined ( webExtension . defaultManifestTranslations ) ) {
876
+ if ( webExtension . fallbackPackageNLSUri ) {
877
+ try {
878
+ const content = await this . extensionResourceLoaderService . readExtensionResource ( webExtension . fallbackPackageNLSUri ) ;
879
+ webExtension . defaultManifestTranslations = JSON . parse ( content ) ;
880
+ update = true ;
881
+ } catch ( error ) {
882
+ this . logService . error ( `Error while fetching default manifest translations of an extension` , webExtension . identifier . id , getErrorMessage ( error ) ) ;
883
+ }
884
+ } else {
885
+ update = true ;
886
+ webExtension . defaultManifestTranslations = null ;
887
+ }
888
+ }
855
889
return webExtension ;
856
890
} ) ) ;
857
891
if ( update ) {
@@ -877,6 +911,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
877
911
readmeUri : e . readmeUri ?. toJSON ( ) ,
878
912
changelogUri : e . changelogUri ?. toJSON ( ) ,
879
913
packageNLSUris : toStringDictionary ( e . packageNLSUris ) ,
914
+ defaultManifestTranslations : e . defaultManifestTranslations ,
880
915
fallbackPackageNLSUri : e . fallbackPackageNLSUri ?. toJSON ( ) ,
881
916
metadata : e . metadata
882
917
} ) ) ;
0 commit comments