zone-patch-electron.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. /**
  3. * @license Angular v<unknown>
  4. * (c) 2010-2025 Google LLC. https://angular.io/
  5. * License: MIT
  6. */
  7. function patchElectron(Zone) {
  8. Zone.__load_patch('electron', (global, Zone, api) => {
  9. function patchArguments(target, name, source) {
  10. return api.patchMethod(target, name, (delegate) => (self, args) => {
  11. return delegate && delegate.apply(self, api.bindArguments(args, source));
  12. });
  13. }
  14. let { desktopCapturer, shell, CallbacksRegistry, ipcRenderer } = require('electron');
  15. if (!CallbacksRegistry) {
  16. try {
  17. // Try to load CallbacksRegistry class from @electron/remote src
  18. // since from electron 14+, the CallbacksRegistry is moved to @electron/remote
  19. // package and not exported to outside, so this is a hack to patch CallbacksRegistry.
  20. CallbacksRegistry =
  21. require('@electron/remote/dist/src/renderer/callbacks-registry').CallbacksRegistry;
  22. }
  23. catch (err) { }
  24. }
  25. // patch api in renderer process directly
  26. // desktopCapturer
  27. if (desktopCapturer) {
  28. patchArguments(desktopCapturer, 'getSources', 'electron.desktopCapturer.getSources');
  29. }
  30. // shell
  31. if (shell) {
  32. patchArguments(shell, 'openExternal', 'electron.shell.openExternal');
  33. }
  34. // patch api in main process through CallbackRegistry
  35. if (!CallbacksRegistry) {
  36. if (ipcRenderer) {
  37. patchArguments(ipcRenderer, 'on', 'ipcRenderer.on');
  38. }
  39. return;
  40. }
  41. patchArguments(CallbacksRegistry.prototype, 'add', 'CallbackRegistry.add');
  42. });
  43. }
  44. patchElectron(Zone);