custom-gallery.patch 2.3 KB

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