@sumaris-net/ngx-components 0.25.7 → 0.25.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15678,7 +15678,7 @@
15678
15678
  this.browser = browser;
15679
15679
  this.downloader = downloader;
15680
15680
  this._started = false;
15681
- this._downloadingPromise = new Map();
15681
+ this._downloadingJobs = new Map();
15682
15682
  this._debug = !environment.production;
15683
15683
  if (this._debug)
15684
15684
  console.debug('[platform] Creating service');
@@ -15808,56 +15808,43 @@
15808
15808
  window.open(url, target, features, replace);
15809
15809
  }
15810
15810
  };
15811
- PlatformService.prototype.getDownloadingPromise = function (uri) {
15812
- return __awaiter(this, void 0, void 0, function () {
15813
- return __generator(this, function (_a) {
15814
- return [2 /*return*/, this._downloadingPromise.get(uri)];
15815
- });
15816
- });
15811
+ PlatformService.prototype.getDownloadingJob = function (uri) {
15812
+ return this._downloadingJobs.get(uri);
15817
15813
  };
15818
15814
  PlatformService.prototype.download = function (request) {
15819
- return __awaiter(this, void 0, void 0, function () {
15820
- var promise, location, err_1;
15821
- return __generator(this, function (_a) {
15822
- switch (_a.label) {
15823
- case 0:
15824
- if (!request || !request.uri)
15825
- throw new Error('Missing argument \'request\' or \'request.uri\'');
15826
- if (!(this._android && this.downloader)) return [3 /*break*/, 6];
15827
- promise = this._downloadingPromise.get(request.uri);
15828
- if (promise)
15829
- return [2 /*return*/, promise];
15830
- request = Object.assign({ visibleInDownloadsUi: true, notificationVisibility: ngx$6.NotificationVisibility.VisibleNotifyCompleted, title: request.title || request.filename }, request);
15831
- _a.label = 1;
15832
- case 1:
15833
- _a.trys.push([1, 3, 4, 5]);
15834
- console.debug('[platform] Downloading, using request: ' + JSON.stringify(request));
15835
- // Start download
15836
- promise = this.downloader.download(request);
15837
- // Remember this request uri
15838
- this._downloadingPromise.set(request.uri, promise);
15839
- return [4 /*yield*/, promise];
15840
- case 2:
15841
- location = _a.sent();
15842
- console.info('[platform] File successfully downloaded at:' + location);
15843
- return [2 /*return*/, location];
15844
- case 3:
15845
- err_1 = _a.sent();
15846
- console.error('[platform] Unable to download: ' + (err_1 && err_1.message || err_1));
15847
- throw err_1;
15848
- case 4:
15849
- // Forget the request
15850
- this._downloadingPromise.delete(request.uri);
15851
- return [7 /*endfinally*/];
15852
- case 5: return [3 /*break*/, 7];
15853
- case 6:
15854
- console.warn('[platform] Cannot use Android downloader: using browser open()');
15855
- this.open(request.uri, '_system', 'location=no', true);
15856
- return [2 /*return*/, undefined];
15857
- case 7: return [2 /*return*/];
15858
- }
15859
- });
15860
- });
15815
+ var _this = this;
15816
+ if (!request || !request.uri)
15817
+ throw new Error('Missing argument \'request\' or \'request.uri\'');
15818
+ if (this._android && this.downloader) {
15819
+ // Check if not already downloading file
15820
+ var location$ = this._downloadingJobs.get(request.uri);
15821
+ if (location$)
15822
+ return location$;
15823
+ request = Object.assign({ visibleInDownloadsUi: true, notificationVisibility: ngx$6.NotificationVisibility.VisibleNotifyCompleted, title: request.title || request.filename }, request);
15824
+ console.debug('[platform] Downloading, using request: ' + JSON.stringify(request));
15825
+ // Start download
15826
+ location$ = rxjs.from(this.downloader.download(request));
15827
+ // Remember this request uri
15828
+ this._downloadingJobs.set(request.uri, location$);
15829
+ return location$
15830
+ .pipe(operators.tap(function (location) {
15831
+ console.info('[platform] File successfully downloaded at:' + location);
15832
+ // Forget the request
15833
+ _this._downloadingJobs.delete(request.uri);
15834
+ }), operators.catchError(function (err) {
15835
+ console.error('[platform] Unable to download: ' + (err && err.message || err));
15836
+ // Forget the request
15837
+ _this._downloadingJobs.delete(request.uri);
15838
+ throw err;
15839
+ }));
15840
+ }
15841
+ // Fallback (if not Android and Cordova): opening the URI using the browser
15842
+ // TODO: find a way to download under iOS (see https://www.c-sharpcorner.com/article/how-to-download-a-file-using-file-transfer-plugin-in-ionic-3/)
15843
+ else {
15844
+ console.warn('[platform] Cannot use Android downloader: using browser open()');
15845
+ this.open(request.uri, '_system', 'location=no', true);
15846
+ return rxjs.of();
15847
+ }
15861
15848
  };
15862
15849
  /* -- protected methods -- */
15863
15850
  PlatformService.prototype.configureCordovaPlugins = function (mobile) {
@@ -15953,7 +15940,7 @@
15953
15940
  };
15954
15941
  PlatformService.prototype.migrateStorage = function (forage) {
15955
15942
  return __awaiter(this, void 0, void 0, function () {
15956
- var canMigrate, oldForage, keys, now, toast_1, duration, err_2;
15943
+ var canMigrate, oldForage, keys, now, toast_1, duration, err_1;
15957
15944
  return __generator(this, function (_a) {
15958
15945
  switch (_a.label) {
15959
15946
  case 0:
@@ -16006,8 +15993,8 @@
16006
15993
  _a.sent();
16007
15994
  return [3 /*break*/, 12];
16008
15995
  case 9:
16009
- err_2 = _a.sent();
16010
- console.error(err_2 && err_2.message || err_2, err_2);
15996
+ err_1 = _a.sent();
15997
+ console.error(err_1 && err_1.message || err_1, err_1);
16011
15998
  return [4 /*yield*/, toast_1.dismiss()];
16012
15999
  case 10:
16013
16000
  _a.sent();
@@ -21393,7 +21380,7 @@
21393
21380
  console.error('[install-upgrade-card] Missing required argument \'link.url\'');
21394
21381
  return [2 /*return*/]; // Skip
21395
21382
  }
21396
- return [2 /*return*/, this.listenDownloadPromise(link.url, this.platform.download({
21383
+ return [2 /*return*/, this.listenDownloadJob(link.url, this.platform.download({
21397
21384
  uri: link.url,
21398
21385
  title: link.title,
21399
21386
  filename: link.filename,
@@ -21470,9 +21457,9 @@
21470
21457
  case 4:
21471
21458
  // Listening downloading promise, if exists
21472
21459
  (this.upgradeLinks || []).forEach(function (link) {
21473
- var promise = _this.platform.getDownloadingPromise(link.url);
21474
- if (promise)
21475
- _this.listenDownloadPromise(link.url, promise);
21460
+ var job = _this.platform.getDownloadingJob(link.url);
21461
+ if (job)
21462
+ _this.listenDownloadJob(link.url, job);
21476
21463
  });
21477
21464
  return [2 /*return*/];
21478
21465
  }
@@ -21585,13 +21572,13 @@
21585
21572
  });
21586
21573
  });
21587
21574
  };
21588
- AppInstallUpgradeCard.prototype.listenDownloadPromise = function (url, promise) {
21575
+ AppInstallUpgradeCard.prototype.listenDownloadJob = function (url, job) {
21589
21576
  return __awaiter(this, void 0, void 0, function () {
21590
21577
  var location, err_1;
21591
21578
  return __generator(this, function (_a) {
21592
21579
  switch (_a.label) {
21593
21580
  case 0:
21594
- if (!url || !promise)
21581
+ if (!url || !job)
21595
21582
  return [2 /*return*/]; // Skip
21596
21583
  _a.label = 1;
21597
21584
  case 1:
@@ -21602,10 +21589,13 @@
21602
21589
  this.downloading = true;
21603
21590
  this.markForCheck();
21604
21591
  }
21605
- return [4 /*yield*/, promise];
21592
+ return [4 /*yield*/, job.toPromise()];
21606
21593
  case 2:
21607
21594
  location = _a.sent();
21608
- console.info('[install-upgrade-card] File downloaded at: ' + location);
21595
+ if (location) {
21596
+ console.info('[install-upgrade-card] File downloaded at: ' + location);
21597
+ return [2 /*return*/, this.showDownloadCompleteDialog()];
21598
+ }
21609
21599
  return [3 /*break*/, 5];
21610
21600
  case 3:
21611
21601
  err_1 = _a.sent();
@@ -21615,7 +21605,7 @@
21615
21605
  this.downloading = false;
21616
21606
  this.markForCheck();
21617
21607
  return [7 /*endfinally*/];
21618
- case 5: return [2 /*return*/, this.showDownloadCompleteDialog()];
21608
+ case 5: return [2 /*return*/];
21619
21609
  }
21620
21610
  });
21621
21611
  });