zone-patch-electron.umd.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict';
  2. /**
  3. * @license Angular v<unknown>
  4. * (c) 2010-2022 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. Zone.__load_patch('electron', function (global, Zone, api) {
  13. function patchArguments(target, name, source) {
  14. return api.patchMethod(target, name, function (delegate) { return function (self, args) {
  15. return delegate && delegate.apply(self, api.bindArguments(args, source));
  16. }; });
  17. }
  18. var _a = require('electron'), desktopCapturer = _a.desktopCapturer, shell = _a.shell, CallbacksRegistry = _a.CallbacksRegistry, ipcRenderer = _a.ipcRenderer;
  19. if (!CallbacksRegistry) {
  20. try {
  21. // Try to load CallbacksRegistry class from @electron/remote src
  22. // since from electron 14+, the CallbacksRegistry is moved to @electron/remote
  23. // package and not exported to outside, so this is a hack to patch CallbacksRegistry.
  24. CallbacksRegistry =
  25. require('@electron/remote/dist/src/renderer/callbacks-registry').CallbacksRegistry;
  26. }
  27. catch (err) {
  28. }
  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. }));