Skip to content

Commit 914ec50

Browse files
authored
1 parent dd2f554 commit 914ec50

File tree

1 file changed

+47
-12
lines changed

1 file changed

+47
-12
lines changed

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

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import { CancellationToken } from 'vs/base/common/cancellation';
1818
import { IExtensionGalleryService, IExtensionInfo, IGalleryExtension, IGalleryMetadata, Metadata } from 'vs/platform/extensionManagement/common/extensionManagement';
1919
import { areSameExtensions, getGalleryExtensionId, getExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
2020
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';
2222
import { localize } from 'vs/nls';
2323
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';
2525
import { getErrorMessage } from 'vs/base/common/errors';
2626
import { ResourceMap } from 'vs/base/common/map';
2727
import { IExtensionManifestPropertiesService } from 'vs/workbench/services/extensions/common/extensionManifestPropertiesService';
@@ -66,6 +66,7 @@ interface IStoredWebExtension {
6666
readonly packageNLSUri?: UriComponents;
6767
readonly packageNLSUris?: IStringDictionary<UriComponents>;
6868
readonly fallbackPackageNLSUri?: UriComponents;
69+
readonly defaultManifestTranslations?: ITranslations | null;
6970
readonly metadata?: Metadata;
7071
}
7172

@@ -81,6 +82,7 @@ interface IWebExtension {
8182
packageNLSUris?: Map<string, URI>;
8283
bundleNLSUris?: Map<string, URI>;
8384
fallbackPackageNLSUri?: URI;
85+
defaultManifestTranslations?: ITranslations | null;
8486
metadata?: Metadata;
8587
}
8688

@@ -329,6 +331,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
329331
if (!this._updateCustomBuiltinExtensionsCachePromise) {
330332
this._updateCustomBuiltinExtensionsCachePromise = (async () => {
331333
this.logService.info('Updating additional builtin extensions cache');
334+
const cached = await this.getCustomBuiltinExtensionsFromCache();
332335
const webExtensions: IWebExtension[] = [];
333336
const { extensions } = await this.readCustomBuiltinExtensionsInfoFromEnv();
334337
if (extensions.length) {
@@ -339,7 +342,9 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
339342
}
340343
await Promise.all([...galleryExtensionsMap.values()].map(async gallery => {
341344
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);
343348
} catch (error) {
344349
this.logService.info(`Ignoring additional builtin extension ${gallery.identifier.id} because there is an error while converting it into web extension`, getErrorMessage(error));
345350
}
@@ -611,6 +616,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
611616
fallbackPackageNLSUri = undefined;
612617
}
613618
}
619+
const defaultManifestTranslations: ITranslations | null | undefined = fallbackPackageNLSUri ? await this.getTranslations(fallbackPackageNLSUri) : null;
614620

615621
if (bundleNLSUris === undefined && manifest.browser) {
616622
const englishStringsUri = joinPath(
@@ -637,6 +643,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
637643
packageNLSUris,
638644
bundleNLSUris,
639645
fallbackPackageNLSUri: fallbackPackageNLSUri ? fallbackPackageNLSUri : undefined,
646+
defaultManifestTranslations,
640647
metadata,
641648
};
642649
}
@@ -666,10 +673,12 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
666673
ImplicitActivationEvents.updateManifest(manifest);
667674

668675
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);
673682
}
674683

675684
const uuid = (<IGalleryMetadata | undefined>webExtension.metadata)?.id;
@@ -716,12 +725,12 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
716725
return [];
717726
}
718727

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> {
720729
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);
725734
}
726735
} catch (error) { /* ignore */ }
727736
return manifest;
@@ -756,6 +765,16 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
756765
return JSON.parse(content);
757766
}
758767

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+
759778
private async readInstalledExtensions(profileLocation: URI): Promise<IWebExtension[]> {
760779
if (this.uriIdentityService.extUri.isEqual(profileLocation, this.userDataProfilesService.defaultProfile.extensionsResource)) {
761780
await this.migratePackageNLSUris();
@@ -814,6 +833,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
814833
changelogUri: URI.revive(e.changelogUri),
815834
packageNLSUris,
816835
fallbackPackageNLSUri: URI.revive(e.fallbackPackageNLSUri),
836+
defaultManifestTranslations: e.defaultManifestTranslations,
817837
packageNLSUri: URI.revive(e.packageNLSUri),
818838
metadata: e.metadata,
819839
});
@@ -852,6 +872,20 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
852872
this.logService.error(`Error while updating manifest of an extension in ${file.toString()}`, webExtension.identifier.id, getErrorMessage(error));
853873
}
854874
}
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+
}
855889
return webExtension;
856890
}));
857891
if (update) {
@@ -877,6 +911,7 @@ export class WebExtensionsScannerService extends Disposable implements IWebExten
877911
readmeUri: e.readmeUri?.toJSON(),
878912
changelogUri: e.changelogUri?.toJSON(),
879913
packageNLSUris: toStringDictionary(e.packageNLSUris),
914+
defaultManifestTranslations: e.defaultManifestTranslations,
880915
fallbackPackageNLSUri: e.fallbackPackageNLSUri?.toJSON(),
881916
metadata: e.metadata
882917
}));

0 commit comments

Comments
 (0)