custom-gallery.patch 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. diff --git a/src/vs/platform/product/common/product.ts b/src/vs/platform/product/common/product.ts
  2. index ef798fa..5a0550b 100644
  3. --- a/src/vs/platform/product/common/product.ts
  4. +++ b/src/vs/platform/product/common/product.ts
  5. @@ -5,3 +5,4 @@
  6. -import { globals } from 'vs/base/common/platform';
  7. +import { AppResourcePath, FileAccess } from 'vs/base/common/network';
  8. +import { globals, isWindows } from 'vs/base/common/platform';
  9. import { env } from 'vs/base/common/process';
  10. @@ -9,2 +10,3 @@ import { IProductConfiguration } from 'vs/base/common/product';
  11. import { ISandboxConfiguration } from 'vs/base/parts/sandbox/common/sandboxTypes';
  12. +import { getUserDataPath } from 'vs/platform/environment/node/userDataPath';
  13. @@ -29,2 +31,40 @@ else if (globalThis._VSCODE_PRODUCT_JSON && globalThis._VSCODE_PACKAGE_JSON) {
  14. + // Set user-defined extension gallery
  15. + const { serviceUrl, searchUrl, itemUrl, controlUrl } = product.extensionsGallery || {}
  16. +
  17. + Object.assign(product, {
  18. + extensionsGallery: {
  19. + serviceUrl: env['VSCODE_GALLERY_SERVICE_URL'] || serviceUrl,
  20. + searchUrl: env['VSCODE_GALLERY_SEARCH_URL'] || searchUrl,
  21. + itemUrl: env['VSCODE_GALLERY_ITEM_URL'] || itemUrl,
  22. + controlUrl: env['VSCODE_GALLERY_CONTROL_URL'] || controlUrl,
  23. + }
  24. + })
  25. +
  26. + // Merge user-customized product.json
  27. + try {
  28. + const merge = (...objects: any[]) =>
  29. + objects.reduce((result, current) => {
  30. + Object.keys(current).forEach((key) => {
  31. + if (Array.isArray(result[key]) && Array.isArray(current[key])) {
  32. + result[key] = current[key];
  33. + } else if (typeof result[key] === 'object' && typeof current[key] === 'object') {
  34. + result[key] = merge(result[key], current[key]);
  35. + } else {
  36. + result[key] = current[key];
  37. + }
  38. + });
  39. +
  40. + return result;
  41. + }, {}) as any;
  42. +
  43. + const userDataPath = getUserDataPath({} as any, product.nameShort);
  44. + const userProductPath = isWindows ? `file:///${userDataPath}/product.json` : `file://${userDataPath}/product.json`;
  45. +
  46. + const userProduct = require.__$__nodeRequire(FileAccess.asFileUri(userProductPath as AppResourcePath).fsPath);
  47. +
  48. + product = merge(product, userProduct);
  49. + } catch (ex) {
  50. + }
  51. +
  52. // Running out of sources