cordova.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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('cordova', (global: any, Zone: ZoneType, api: _ZonePrivate) => {
  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: Function|null =
  14. api.patchMethod(global.cordova, 'exec', () => function(self: any, args: any[]) {
  15. if (args.length > 0 && typeof args[0] === FUNCTION) {
  16. args[0] = Zone.current.wrap(args[0], SUCCESS_SOURCE);
  17. }
  18. if (args.length > 1 && typeof args[1] === FUNCTION) {
  19. args[1] = Zone.current.wrap(args[1], ERROR_SOURCE);
  20. }
  21. return nativeExec!.apply(self, args);
  22. });
  23. }
  24. });
  25. Zone.__load_patch('cordova.FileReader', (global: any, Zone: ZoneType) => {
  26. if (global.cordova && typeof global['FileReader'] !== 'undefined') {
  27. document.addEventListener('deviceReady', () => {
  28. const FileReader = global['FileReader'];
  29. ['abort', 'error', 'load', 'loadstart', 'loadend', 'progress'].forEach(prop => {
  30. const eventNameSymbol = Zone.__symbol__('ON_PROPERTY' + prop);
  31. Object.defineProperty(FileReader.prototype, eventNameSymbol, {
  32. configurable: true,
  33. get: function() {
  34. return this._realReader && this._realReader[eventNameSymbol];
  35. }
  36. });
  37. });
  38. });
  39. }
  40. });