zone-patch-electron.umd.js 2.1 KB

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