custom-gallery.patch 2.2 KB

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