zone-patch-cordova.js 1.7 KB

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