zone-patch-cordova.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. /**
  3. * @license Angular v<unknown>
  4. * (c) 2010-2022 Google LLC. https://angular.io/
  5. * License: MIT
  6. */
  7. Zone.__load_patch('cordova', (global, Zone, api) => {
  8. if (global.cordova) {
  9. const SUCCESS_SOURCE = 'cordova.exec.success';
  10. const ERROR_SOURCE = 'cordova.exec.error';
  11. const FUNCTION = 'function';
  12. const nativeExec = api.patchMethod(global.cordova, 'exec', () => function (self, args) {
  13. if (args.length > 0 && typeof args[0] === FUNCTION) {
  14. args[0] = Zone.current.wrap(args[0], SUCCESS_SOURCE);
  15. }
  16. if (args.length > 1 && typeof args[1] === FUNCTION) {
  17. args[1] = Zone.current.wrap(args[1], ERROR_SOURCE);
  18. }
  19. return nativeExec.apply(self, args);
  20. });
  21. }
  22. });
  23. Zone.__load_patch('cordova.FileReader', (global, Zone) => {
  24. if (global.cordova && typeof global['FileReader'] !== 'undefined') {
  25. document.addEventListener('deviceReady', () => {
  26. const FileReader = global['FileReader'];
  27. ['abort', 'error', 'load', 'loadstart', 'loadend', 'progress'].forEach(prop => {
  28. const eventNameSymbol = Zone.__symbol__('ON_PROPERTY' + prop);
  29. Object.defineProperty(FileReader.prototype, eventNameSymbol, {
  30. configurable: true,
  31. get: function () {
  32. return this._realReader && this._realReader[eventNameSymbol];
  33. }
  34. });
  35. });
  36. });
  37. }
  38. });