vscodium/patches/custom-gallery.patch
2022-11-23 21:52:51 +01:00

57 lines
2.3 KiB
Diff

diff --git a/src/vs/platform/product/common/product.ts b/src/vs/platform/product/common/product.ts
index ef798fa..35b848b 100644
--- a/src/vs/platform/product/common/product.ts
+++ b/src/vs/platform/product/common/product.ts
@@ -5,3 +5,4 @@
-import { globals } from 'vs/base/common/platform';
+import { AppResourcePath, FileAccess } from 'vs/base/common/network';
+import { globals, isWindows } from 'vs/base/common/platform';
import { env } from 'vs/base/common/process';
@@ -9,2 +10,3 @@ import { IProductConfiguration } from 'vs/base/common/product';
import { ISandboxConfiguration } from 'vs/base/parts/sandbox/common/sandboxTypes';
+import { getUserDataPath } from 'vs/platform/environment/node/userDataPath';
@@ -29,2 +31,41 @@ else if (globalThis._VSCODE_PRODUCT_JSON && globalThis._VSCODE_PACKAGE_JSON) {
+ // Set user-defined extension gallery
+ const { serviceUrl, searchUrl, itemUrl, controlUrl, recommendationsUrl } = product.extensionsGallery || {}
+
+ Object.assign(product, {
+ extensionsGallery: {
+ serviceUrl: env['VSCODE_GALLERY_SERVICE_URL'] || serviceUrl,
+ searchUrl: env['VSCODE_GALLERY_SEARCH_URL'] || searchUrl,
+ itemUrl: env['VSCODE_GALLERY_ITEM_URL'] || itemUrl,
+ controlUrl: env['VSCODE_GALLERY_CONTROL_URL'] || controlUrl,
+ recommendationsUrl: env['VSCODE_GALLERY_RECOMMENDATIONS_URL'] || recommendationsUrl
+ }
+ })
+
+ // Merge user-customized product.json
+ try {
+ const merge = (...objects: any[]) =>
+ objects.reduce((result, current) => {
+ Object.keys(current).forEach((key) => {
+ if (Array.isArray(result[key]) && Array.isArray(current[key])) {
+ result[key] = current[key];
+ } else if (typeof result[key] === 'object' && typeof current[key] === 'object') {
+ result[key] = merge(result[key], current[key]);
+ } else {
+ result[key] = current[key];
+ }
+ });
+
+ return result;
+ }, {}) as any;
+
+ const userDataPath = getUserDataPath({} as any, product.nameShort);
+ const userProductPath = isWindows ? `file:///${userDataPath}/product.json` : `file://${userDataPath}/product.json`;
+
+ const userProduct = require.__$__nodeRequire(FileAccess.asFileUri(userProductPath as AppResourcePath).fsPath);
+
+ product = merge(product, userProduct);
+ } catch (ex) {
+ }
+
// Running out of sources