electron.ts 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * @license
  3. * Copyright Google Inc. All Rights Reserved.
  4. *
  5. * Use of this source code is governed by an MIT-style license that can be
  6. * found in the LICENSE file at https://angular.io/license
  7. */
  8. Zone.__load_patch('electron', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
  9. function patchArguments(target: any, name: string, source: string): Function|null {
  10. return api.patchMethod(target, name, (delegate: Function) => (self: any, args: any[]) => {
  11. return delegate && delegate.apply(self, api.bindArguments(args, source));
  12. });
  13. }
  14. const {desktopCapturer, shell, CallbacksRegistry} = require('electron');
  15. // patch api in renderer process directly
  16. // desktopCapturer
  17. if (desktopCapturer) {
  18. patchArguments(desktopCapturer, 'getSources', 'electron.desktopCapturer.getSources');
  19. }
  20. // shell
  21. if (shell) {
  22. patchArguments(shell, 'openExternal', 'electron.shell.openExternal');
  23. }
  24. // patch api in main process through CallbackRegistry
  25. if (!CallbacksRegistry) {
  26. return;
  27. }
  28. patchArguments(CallbacksRegistry.prototype, 'add', 'CallbackRegistry.add');
  29. });