incyclist-services 1.9.21 → 1.9.23

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.
Files changed (65) hide show
  1. package/lib/cjs/activities/base/repo/db.js +8 -2
  2. package/lib/cjs/activities/base/utils/helpers.js +26 -11
  3. package/lib/cjs/activities/upload/index.js +1 -0
  4. package/lib/cjs/activities/upload/komoot.js +166 -0
  5. package/lib/cjs/apps/base/api/komoot/api.js +35 -0
  6. package/lib/cjs/apps/komoot/KomootAppConnection.js +6 -4
  7. package/lib/cjs/apps/service.js +1 -1
  8. package/lib/cjs/devices/page/base/guidance/guidance.js +277 -16
  9. package/lib/cjs/devices/page/base/service.js +245 -16
  10. package/lib/cjs/devices/page/desktop/matrix.js +2 -1
  11. package/lib/cjs/devices/page/desktop/service.js +4 -11
  12. package/lib/cjs/devices/page/mobile/service.js +1 -0
  13. package/lib/cjs/devices/pairing/conflict.js +47 -0
  14. package/lib/cjs/devices/pairing/guidance.js +40 -4
  15. package/lib/cjs/devices/pairing/helper.js +3 -1
  16. package/lib/cjs/devices/pairing/index.js +1 -0
  17. package/lib/cjs/devices/pairing/service.js +228 -35
  18. package/lib/cjs/devices/pairing/status.js +1 -0
  19. package/lib/cjs/devices/ride/service.js +20 -4
  20. package/lib/cjs/devices/ride/timeouts.js +9 -0
  21. package/lib/cjs/ride/display/service.js +2 -2
  22. package/lib/cjs/routes/base/api/api.js +1 -0
  23. package/lib/esm/activities/base/repo/db.js +8 -2
  24. package/lib/esm/activities/base/utils/helpers.js +24 -10
  25. package/lib/esm/activities/upload/index.js +1 -0
  26. package/lib/esm/activities/upload/komoot.js +163 -0
  27. package/lib/esm/apps/base/api/komoot/api.js +35 -0
  28. package/lib/esm/apps/komoot/KomootAppConnection.js +6 -4
  29. package/lib/esm/apps/service.js +1 -1
  30. package/lib/esm/devices/page/base/guidance/guidance.js +276 -15
  31. package/lib/esm/devices/page/base/service.js +246 -17
  32. package/lib/esm/devices/page/desktop/matrix.js +2 -1
  33. package/lib/esm/devices/page/desktop/service.js +4 -11
  34. package/lib/esm/devices/page/mobile/service.js +1 -0
  35. package/lib/esm/devices/pairing/conflict.js +9 -4
  36. package/lib/esm/devices/pairing/guidance.js +40 -4
  37. package/lib/esm/devices/pairing/helper.js +1 -0
  38. package/lib/esm/devices/pairing/index.js +1 -0
  39. package/lib/esm/devices/pairing/service.js +228 -35
  40. package/lib/esm/devices/pairing/status.js +1 -0
  41. package/lib/esm/devices/ride/service.js +20 -4
  42. package/lib/esm/ride/display/service.js +2 -2
  43. package/lib/esm/routes/base/api/api.js +1 -0
  44. package/lib/types/activities/base/model/index.d.ts +1 -5
  45. package/lib/types/activities/base/repo/db.d.ts +2 -1
  46. package/lib/types/activities/base/utils/helpers.d.ts +2 -1
  47. package/lib/types/activities/upload/index.d.ts +1 -0
  48. package/lib/types/activities/upload/komoot.d.ts +20 -0
  49. package/lib/types/apps/base/api/komoot/api.d.ts +2 -1
  50. package/lib/types/apps/base/api/komoot/types.d.ts +1 -0
  51. package/lib/types/apps/komoot/KomootAppConnection.d.ts +1 -1
  52. package/lib/types/devices/page/base/guidance/guidance.d.ts +49 -2
  53. package/lib/types/devices/page/base/guidance/types.d.ts +20 -2
  54. package/lib/types/devices/page/base/service.d.ts +36 -2
  55. package/lib/types/devices/page/base/types.d.ts +31 -0
  56. package/lib/types/devices/page/desktop/service.d.ts +1 -2
  57. package/lib/types/devices/pairing/conflict.d.ts +4 -1
  58. package/lib/types/devices/pairing/guidance.d.ts +9 -4
  59. package/lib/types/devices/pairing/helper.d.ts +1 -0
  60. package/lib/types/devices/pairing/index.d.ts +1 -0
  61. package/lib/types/devices/pairing/model.d.ts +1 -0
  62. package/lib/types/devices/pairing/service.d.ts +43 -4
  63. package/lib/types/devices/pairing/status.d.ts +2 -1
  64. package/lib/types/devices/ride/service.d.ts +1 -0
  65. package/package.json +2 -2
@@ -37,6 +37,7 @@ import { useDeviceConfiguration } from "../configuration";
37
37
  import { isCapabilityActive } from "./capability";
38
38
  import { IncyclistCapability } from "incyclist-devices";
39
39
  import { useDeviceRide } from "../ride";
40
+ import { getPairingStartTimeout } from "../ride/timeouts";
40
41
  import clone from "../../utils/clone";
41
42
  import { IncyclistService } from "../../base/service";
42
43
  import { sleep } from "../../utils/sleep";
@@ -86,10 +87,18 @@ let DevicePairingService = (() => {
86
87
  static STALLED_AFTER_MS = 30 * 1000;
87
88
  stalledTimer;
88
89
  stalledLogged = false;
90
+ static ATTEMPT_HUNG_MARGIN_MS = 15 * 1000;
91
+ attemptHungLogged = false;
92
+ retryDelay;
93
+ windingDownAttempt = false;
89
94
  visitOpen = false;
90
95
  visitOpenedAt;
91
96
  pendingConflicts = [];
92
97
  static conflictCounter = 0;
98
+ manualConflicts = new Map();
99
+ settlingConflicts = [];
100
+ conflictSettleTimer;
101
+ static CONFLICT_SETTLE_MS = 2000;
93
102
  static SEARCH_DURATION_MS = { desktop: 60 * 1000, mobile: 30 * 1000 };
94
103
  static STOP_OFFER_DELAY_MS = 2000;
95
104
  search = DevicePairingService.initialSearchState();
@@ -127,7 +136,6 @@ let DevicePairingService = (() => {
127
136
  this.stalledLogged = false;
128
137
  if (this.state.stopped) {
129
138
  this.state.stopped = false;
130
- this.state.deleted = [];
131
139
  }
132
140
  if (this.state.interfaces) {
133
141
  this.initConfigHandlers();
@@ -214,8 +222,10 @@ let DevicePairingService = (() => {
214
222
  if (open) {
215
223
  this.visitOpenedAt ??= Date.now();
216
224
  this.getDeviceConfiguration().clearExclusions({ scope: 'until-next-pairing' });
217
- if (!this.visitOpen)
225
+ if (!this.visitOpen) {
218
226
  this.resetSearch();
227
+ this.attemptHungLogged = false;
228
+ }
219
229
  }
220
230
  else {
221
231
  delete this.visitOpenedAt;
@@ -272,6 +282,35 @@ let DevicePairingService = (() => {
272
282
  this.logError(err, 'searchAgain');
273
283
  }
274
284
  }
285
+ reconnectNow() {
286
+ try {
287
+ if (this.isPairingSettled())
288
+ return [];
289
+ const capabilities = this.getReconnectCapabilities();
290
+ if (!this.isPairing() && !this.windingDownAttempt)
291
+ this.startNextAttempt();
292
+ return capabilities;
293
+ }
294
+ catch (err) {
295
+ this.logError(err, 'reconnectNow');
296
+ return [];
297
+ }
298
+ }
299
+ getReconnectCapabilities() {
300
+ return (this.state.capabilities ?? [])
301
+ .filter(c => isCapabilityActive(c) && c.connectState !== 'connected')
302
+ .map(c => c.capability);
303
+ }
304
+ startNextAttempt() {
305
+ if (this.usage === 'page') {
306
+ this.emit('retry');
307
+ return;
308
+ }
309
+ if (this.retryDelay)
310
+ this.retryDelay.skip();
311
+ else
312
+ this.run().catch(err => { this.logError(err, 'reconnectNow'); });
313
+ }
275
314
  isSearchAllowed() {
276
315
  return !this.visitOpen || this.search.phase !== 'ended';
277
316
  }
@@ -419,20 +458,18 @@ let DevicePairingService = (() => {
419
458
  getPendingConflicts() {
420
459
  return this.pendingConflicts.map(e => clone(e.conflict));
421
460
  }
422
- async resolveConflict(id, replace) {
461
+ async resolveConflict(id, replace, via = 'done') {
423
462
  try {
424
463
  const entry = this.takePendingConflict(id);
425
464
  if (!entry)
426
465
  return;
427
466
  const { udid, conflict } = entry;
428
- const asked = conflict.conflicts.map(c => c.capability);
429
- const stillConflicting = new Set(this.computeSelectionImpact(udid, asked).conflicts.map(c => c.capability));
430
- const toReplace = (replace ?? []).filter(c => stillConflicting.has(c));
467
+ const toReplace = this.getReplaceableRows(udid, conflict, replace);
431
468
  if (toReplace.length > 0) {
432
469
  const [first, ...rest] = toReplace;
433
470
  await this.selectDevice(first, udid, { others: 'fill-empty', replace: rest });
434
471
  }
435
- this.logConflictResolved(conflict, 'done', toReplace.length);
472
+ this.logConflictResolved(conflict, via, toReplace.length);
436
473
  }
437
474
  catch (err) {
438
475
  this.logError(err, 'resolveConflict');
@@ -448,10 +485,72 @@ let DevicePairingService = (() => {
448
485
  this.logError(err, 'dismissConflict');
449
486
  }
450
487
  }
488
+ reevaluatePendingConflicts(changed) {
489
+ try {
490
+ this.pendingConflicts = this.pendingConflicts.filter(entry => this.reevaluateConflict(entry, changed));
491
+ }
492
+ catch (err) {
493
+ this.logError(err, 'reevaluatePendingConflicts');
494
+ }
495
+ }
496
+ reevaluateConflict(entry, changed) {
497
+ const { udid, conflict } = entry;
498
+ const asked = conflict.conflicts.map(c => c.capability);
499
+ if (changed && !asked.some(c => changed.includes(c)))
500
+ return true;
501
+ const current = this.computeSelectionImpact(udid, asked).conflicts;
502
+ if (current.length === 0) {
503
+ this.logConflictResolved(conflict, 'superseded', 0);
504
+ return false;
505
+ }
506
+ conflict.conflicts = current;
507
+ return true;
508
+ }
509
+ startManualConflict(capability, udid) {
510
+ try {
511
+ const { filled, conflicts } = this.previewSelectDevice(capability, udid);
512
+ if (conflicts.length === 0)
513
+ return undefined;
514
+ const deviceName = this.getCapabilityDevice(capability, udid)?.name
515
+ ?? this.getDeviceConfiguration().getAdapter(udid)?.getUniqueName() ?? '';
516
+ const conflict = { id: this.nextConflictId(udid), origin: 'manual', deviceName, filled, conflicts };
517
+ this.manualConflicts.set(conflict.id, { udid, capability, conflict });
518
+ this.logConflictShown(conflict, conflicts.length, 0);
519
+ return clone(conflict);
520
+ }
521
+ catch (err) {
522
+ this.logError(err, 'startManualConflict');
523
+ return undefined;
524
+ }
525
+ }
526
+ async commitManualConflict(id, replace, via = 'done') {
527
+ try {
528
+ const entry = this.manualConflicts.get(id);
529
+ if (!entry)
530
+ return;
531
+ this.manualConflicts.delete(id);
532
+ const { udid, capability, conflict } = entry;
533
+ const toReplace = this.getReplaceableRows(udid, conflict, replace);
534
+ await this.selectDevice(capability, udid, { others: 'fill-empty', replace: toReplace });
535
+ this.logConflictResolved(conflict, via, toReplace.length);
536
+ }
537
+ catch (err) {
538
+ this.logError(err, 'commitManualConflict');
539
+ }
540
+ }
541
+ getReplaceableRows(udid, conflict, replace) {
542
+ const asked = conflict.conflicts.map(c => c.capability);
543
+ const stillConflicting = new Set(this.computeSelectionImpact(udid, asked).conflicts.map(c => c.capability));
544
+ const stale = asked.filter(c => !stillConflicting.has(c)).length;
545
+ if (stale > 0)
546
+ this.logEvent({ message: 'device select conflict stale', origin: conflict.origin, conflictCount: stale });
547
+ return (replace ?? []).filter(c => stillConflicting.has(c));
548
+ }
451
549
  dismissPendingConflicts(via) {
452
550
  const pending = this.pendingConflicts;
453
551
  this.pendingConflicts = [];
454
552
  pending.forEach(e => { this.logConflictResolved(e.conflict, via, 0); });
553
+ this.clearConflictSettleTimer();
455
554
  }
456
555
  takePendingConflict(id) {
457
556
  const idx = this.pendingConflicts.findIndex(e => e.conflict.id === id);
@@ -487,15 +586,33 @@ let DevicePairingService = (() => {
487
586
  this.logConflictResolved(conflict, 'left_page', 0);
488
587
  return;
489
588
  }
490
- const conflict = this.addPendingConflict(udid, deviceName, filled, conflicts);
491
- this.logConflictShown(conflict, conflicts.length, this.pendingConflicts.length - 1);
492
- this.emit('selection-conflict', clone(conflict));
589
+ this.mergeIntoConflictList(this.settlingConflicts, udid, deviceName, filled, conflicts);
590
+ if (this.conflictSettleTimer)
591
+ clearTimeout(this.conflictSettleTimer);
592
+ this.conflictSettleTimer = setTimeout(() => { this.settleDetectionConflicts(); }, DevicePairingService.CONFLICT_SETTLE_MS);
593
+ this.conflictSettleTimer.unref?.();
594
+ }
595
+ settleDetectionConflicts() {
596
+ delete this.conflictSettleTimer;
597
+ const settled = this.settlingConflicts;
598
+ this.settlingConflicts = [];
599
+ settled.forEach(({ udid, conflict }) => {
600
+ const merged = this.mergeIntoConflictList(this.pendingConflicts, udid, conflict.deviceName, conflict.filled, conflict.conflicts);
601
+ this.logConflictShown(merged, merged.conflicts.length, this.pendingConflicts.length - 1);
602
+ this.emit('selection-conflict', clone(merged));
603
+ });
604
+ }
605
+ clearConflictSettleTimer() {
606
+ if (this.conflictSettleTimer)
607
+ clearTimeout(this.conflictSettleTimer);
608
+ delete this.conflictSettleTimer;
609
+ this.settlingConflicts = [];
493
610
  }
494
- addPendingConflict(udid, deviceName, filled, conflicts) {
495
- const existing = this.pendingConflicts.find(e => e.udid === udid)?.conflict;
611
+ mergeIntoConflictList(list, udid, deviceName, filled, conflicts) {
612
+ const existing = list.find(e => e.udid === udid)?.conflict;
496
613
  if (!existing) {
497
614
  const conflict = { id: this.nextConflictId(udid), origin: 'detection', deviceName, filled, conflicts };
498
- this.pendingConflicts.push({ udid, conflict });
615
+ list.push({ udid, conflict });
499
616
  return conflict;
500
617
  }
501
618
  filled.filter(c => !existing.filled.includes(c)).forEach(c => existing.filled.push(c));
@@ -609,7 +726,7 @@ let DevicePairingService = (() => {
609
726
  const capabilityData = this.getCapability(capability);
610
727
  this.settings = Object.assign(this.settings || {}, { onDeviceSelectStateChanged, capabilityForScan: capability });
611
728
  const devices = capabilityData?.devices || [];
612
- const available = devices.filter(d => this.isInterfaceEnabled(d.interface)).filter(d => !this.isOnDeletedList(capability, d.udid));
729
+ const available = devices.filter(d => this.isInterfaceEnabled(d.interface));
613
730
  const startScan = async () => {
614
731
  if (devices.length > 0)
615
732
  await this.stopAdaptersWithCapability(capability);
@@ -689,30 +806,38 @@ let DevicePairingService = (() => {
689
806
  const conflicts = [];
690
807
  candidateCapabilities.forEach(capability => {
691
808
  const c = this.getCapability(capability);
692
- if (!c || c.disabled || this.isOnDeletedList(capability, udid))
809
+ if (!c || c.disabled)
693
810
  return;
694
811
  if (c.selected === udid)
695
812
  unchanged.push(capability);
696
- else if (!c.selected)
697
- filled.push(capability);
813
+ else if (!c.selected) {
814
+ if (!this.isOnDeletedList(capability, udid))
815
+ filled.push(capability);
816
+ }
698
817
  else
699
818
  conflicts.push({ capability, currentName: c.deviceName });
700
819
  });
701
820
  return { filled, unchanged, conflicts };
702
821
  }
703
822
  selectDeviceObjectMode(capability, udid, mode) {
704
- let changed = this.selectCapabilityDevice(capability, udid, false);
705
823
  const adapter = this.getDeviceAdapter(udid);
706
- const others = adapter.getCapabilities().filter(c => c !== capability);
707
- others.forEach(c => {
824
+ const toFill = adapter.getCapabilities().filter(c => {
825
+ if (c === capability)
826
+ return false;
708
827
  const current = this.getCapability(c);
709
- if (!current || current.disabled || this.isOnDeletedList(c, udid))
710
- return;
828
+ if (!current || current.disabled)
829
+ return false;
711
830
  const isEmpty = !current.selected;
712
831
  const shouldReplace = mode.replace.includes(c);
713
- if (!isEmpty && !shouldReplace)
714
- return;
715
- const wasChanged = this.selectCapabilityDevice(c, udid, false);
832
+ if (shouldReplace)
833
+ return true;
834
+ return isEmpty && !this.isOnDeletedList(c, udid);
835
+ });
836
+ const primaryIsLast = toFill.length === 0;
837
+ let changed = this.selectCapabilityDevice(capability, udid, primaryIsLast);
838
+ toFill.forEach((c, idx) => {
839
+ const isLast = idx === toFill.length - 1;
840
+ const wasChanged = this.selectCapabilityDevice(c, udid, isLast);
716
841
  changed = changed || wasChanged;
717
842
  });
718
843
  return changed;
@@ -843,8 +968,7 @@ let DevicePairingService = (() => {
843
968
  const c = this.getCapability(capability);
844
969
  if (!c)
845
970
  return false;
846
- const wouldChange = c.selected !== udid && !this.isOnDeletedList(capability, udid);
847
- return wouldChange;
971
+ return c.selected !== udid;
848
972
  }
849
973
  getCapabilityDevice(capability, udid) {
850
974
  const c = this.getCapability(capability);
@@ -1563,24 +1687,70 @@ let DevicePairingService = (() => {
1563
1687
  const selectedAdapters = target.map(ai => ({ ...ai, isStarted: false }));
1564
1688
  this.setRequestedCapabilties(selectedAdapters);
1565
1689
  this.onPairingStarted();
1690
+ const attemptStartedAt = Date.now();
1566
1691
  const promise = this.rideService.startAdapters(selectedAdapters, 'pair');
1567
1692
  this.state.check = { promise };
1568
1693
  this.logEvent({ message: 'Start Pairing', adapters, props });
1694
+ let settled = true;
1569
1695
  try {
1570
- await this.state.check.promise;
1696
+ settled = await this.waitForAttempt(promise, target);
1571
1697
  }
1572
1698
  catch (err) {
1573
1699
  this.logError(err, 'startPairing');
1574
1700
  }
1575
1701
  if (this.usage !== 'page' && this.isScanning())
1576
1702
  return;
1703
+ if (!settled)
1704
+ this.dropHungAttempt(target, attemptStartedAt);
1705
+ await this.finishAttempt(target, adapters, props, settled);
1706
+ }
1707
+ async waitForAttempt(promise, target) {
1708
+ let watchdog;
1709
+ const expired = new Promise(done => {
1710
+ watchdog = setTimeout(() => { done(false); }, this.getAttemptTimeout(target));
1711
+ });
1712
+ try {
1713
+ return await Promise.race([promise.then(() => true), expired]);
1714
+ }
1715
+ finally {
1716
+ clearTimeout(watchdog);
1717
+ }
1718
+ }
1719
+ getAttemptTimeout(target) {
1720
+ const slowest = Math.max(...target.map(ai => getPairingStartTimeout(ai.adapter)));
1721
+ return slowest + DevicePairingService.ATTEMPT_HUNG_MARGIN_MS;
1722
+ }
1723
+ dropHungAttempt(target, attemptStartedAt) {
1724
+ if (!this.attemptHungLogged) {
1725
+ this.attemptHungLogged = true;
1726
+ const hung = target.filter(ai => !ai.adapter.isStarted())
1727
+ .map(ai => ai.adapter.getSettings?.()?.interface)
1728
+ .filter(name => name !== undefined);
1729
+ this.logEvent({
1730
+ message: 'pairing attempt hung',
1731
+ hungInterfaces: [...new Set(hung)].join(','),
1732
+ attemptMs: Date.now() - attemptStartedAt,
1733
+ platform: this.getPlatform(),
1734
+ });
1735
+ }
1736
+ this.rideService.dropPendingStart();
1737
+ }
1738
+ async finishAttempt(target, adapters, props, settled) {
1577
1739
  this.completeAttempt();
1578
- if (!this.isPairingSettled()) {
1579
- this.logEvent({ message: 'Pairing done', adapters, props });
1740
+ if (this.isPairingSettled())
1741
+ return;
1742
+ this.logEvent({ message: 'Pairing done', adapters, props });
1743
+ if (settled) {
1580
1744
  const failed = target.filter(ai => !ai.adapter.isStarted()).map(ai => ai.udid);
1581
- await this.rideService.stopDevices(failed);
1582
- await this.retryUnsettledPairing();
1745
+ this.windingDownAttempt = true;
1746
+ try {
1747
+ await this.rideService.stopDevices(failed);
1748
+ }
1749
+ finally {
1750
+ this.windingDownAttempt = false;
1751
+ }
1583
1752
  }
1753
+ await this.retryUnsettledPairing();
1584
1754
  }
1585
1755
  getPairingTarget(adapters) {
1586
1756
  const selected = this.state.capabilities.map(c => c.selected);
@@ -1604,10 +1774,23 @@ let DevicePairingService = (() => {
1604
1774
  async retryUnsettledPairing() {
1605
1775
  if (this.usage === 'page' || this.isPairingSettled())
1606
1776
  return;
1607
- await sleep(this.getPairingRetryDelay());
1777
+ await this.waitForRetry(this.getPairingRetryDelay());
1608
1778
  if (!this.state.scan)
1609
1779
  this.run().catch(err => { this.logError(err, 'startPairing'); });
1610
1780
  }
1781
+ waitForRetry(ms) {
1782
+ return new Promise(done => {
1783
+ const delay = { skip: () => { finish(); } };
1784
+ const finish = () => {
1785
+ clearTimeout(timer);
1786
+ if (this.retryDelay === delay)
1787
+ delete this.retryDelay;
1788
+ done();
1789
+ };
1790
+ const timer = setTimeout(finish, ms);
1791
+ this.retryDelay = delay;
1792
+ });
1793
+ }
1611
1794
  setRequestedCapabilties(selectedAdapters) {
1612
1795
  selectedAdapters.forEach(ai => {
1613
1796
  const requested = this.state.capabilities.filter(c => c.selected === ai.udid) ?? [];
@@ -1960,6 +2143,7 @@ let DevicePairingService = (() => {
1960
2143
  selectCapabilityDevice(capability, udid, emitUpdate = true) {
1961
2144
  if (!this.wouldChangeCapability(capability, udid))
1962
2145
  return;
2146
+ this.removeFromDeletedList(capability, udid);
1963
2147
  const c = this.getCapability(capability);
1964
2148
  const device = this.getCapabilityDevice(capability, udid);
1965
2149
  c.value = device?.value;
@@ -2014,6 +2198,12 @@ let DevicePairingService = (() => {
2014
2198
  const c = this.getCapability(capability);
2015
2199
  this.state.deleted.push({ capability: c.capability, udid, settings });
2016
2200
  }
2201
+ removeFromDeletedList(capability, udid) {
2202
+ const c = this.getCapability(capability);
2203
+ if (!c || !this.state.deleted?.length)
2204
+ return;
2205
+ this.state.deleted = this.state.deleted.filter(e => !(e.capability === c.capability && e.udid === udid));
2206
+ }
2017
2207
  isOnDeletedList(c, udid) {
2018
2208
  const capability = this.getCapability(c);
2019
2209
  return this.state.deleted.some(e => e.capability === capability.capability && e.udid === udid);
@@ -2024,8 +2214,8 @@ let DevicePairingService = (() => {
2024
2214
  const available = devices.filter(d => !this.isOnDeletedList(c.capability, d.udid));
2025
2215
  mapped.deviceNames = available.map(d => d.name).join(';');
2026
2216
  mapped.selected = available.find(d => d.selected)?.udid;
2027
- mapped.deviceName = devices.find(d => d.selected)?.name;
2028
- mapped.interface = devices.find(d => d.selected)?.interface;
2217
+ mapped.deviceName = available.find(d => d.selected)?.name;
2218
+ mapped.interface = available.find(d => d.selected)?.interface;
2029
2219
  mapped.devices = devices;
2030
2220
  return mapped;
2031
2221
  }
@@ -2052,7 +2242,10 @@ let DevicePairingService = (() => {
2052
2242
  this.removeScanningCallbacks();
2053
2243
  this.visitOpen = false;
2054
2244
  delete this.visitOpenedAt;
2245
+ this.attemptHungLogged = false;
2055
2246
  this.pendingConflicts = [];
2247
+ this.manualConflicts.clear();
2248
+ this.clearConflictSettleTimer();
2056
2249
  this.resetSearch();
2057
2250
  }
2058
2251
  getUnitConverter() {
@@ -55,6 +55,7 @@ export const getPairingStatusDisplay = (src) => {
55
55
  stillLooking: src.stillLooking,
56
56
  searchEndedWithoutTrainer: src.searchEndedWithoutTrainer,
57
57
  trainerPhase: src.trainerPhase,
58
+ trainerRetry: src.trainerRetry,
58
59
  trainerName: caps.trainer?.deviceName,
59
60
  allRequiredSwitchedOff: caps.allRequiredSwitchedOff,
60
61
  resistanceSwitchedOff: isSwitchedOffWithDevice(caps.trainer),
@@ -43,6 +43,7 @@ import { IncyclistService } from "../../base/service";
43
43
  import { Singleton } from "../../base/types";
44
44
  import { Injectable } from "../../base/decorators/Injection";
45
45
  import { useGoogleMaps } from "../../apps";
46
+ import { getPairingStartTimeout } from "./timeouts";
46
47
  const NO_DATA_THRESHOLD = 10000;
47
48
  const UNHEALTHY_THRESHOLD = 60000;
48
49
  let DeviceRideService = (() => {
@@ -555,7 +556,8 @@ let DeviceRideService = (() => {
555
556
  return allOK;
556
557
  }
557
558
  finally {
558
- this.startPromises = null;
559
+ if (this.startPromises === startPromises)
560
+ this.startPromises = null;
559
561
  }
560
562
  }
561
563
  async startSingleAdapter(ai, duplicates, props, startType) {
@@ -621,9 +623,7 @@ let DeviceRideService = (() => {
621
623
  }
622
624
  }
623
625
  initForPairing(startProps, ai) {
624
- startProps.timeout = 10000;
625
- if (ai.adapter.getSettings().interface === 'ble')
626
- startProps.timeout = 30000;
626
+ startProps.timeout = getPairingStartTimeout(ai.adapter);
627
627
  }
628
628
  initCyclingMode(ai, forceErgMode) {
629
629
  let bike, mode, settings;
@@ -1013,6 +1013,22 @@ let DeviceRideService = (() => {
1013
1013
  delete this.rideAdapters;
1014
1014
  return true;
1015
1015
  }
1016
+ dropPendingStart() {
1017
+ if (!this.startPromises)
1018
+ return;
1019
+ this.logEvent({ message: 'drop pending start' });
1020
+ const adapters = this.getRideAdapters();
1021
+ adapters?.forEach(ai => {
1022
+ const d = ai.adapter;
1023
+ if (d.isStarted())
1024
+ return;
1025
+ this.unsubscribeDeviceEvents(d);
1026
+ this.logEvent({ message: 'drop pending start of device', udid: ai.udid });
1027
+ d.stop().catch(err => { this.logError(err, 'dropPendingStart'); });
1028
+ });
1029
+ this.startPromises = null;
1030
+ delete this.rideAdapters;
1031
+ }
1016
1032
  registerOnDataHandler(adapters) {
1017
1033
  adapters?.forEach(ai => {
1018
1034
  this.unsubscribeDeviceEvents(ai.adapter);
@@ -1038,14 +1038,14 @@ let RideDisplayService = (() => {
1038
1038
  let request;
1039
1039
  if (simMode === 'Power') {
1040
1040
  const currentPowerTarget = mode.getSetting('power');
1041
- const targetPower = Number(currentPowerTarget) + powerInc;
1041
+ const targetPower = Math.max(0, Number(currentPowerTarget) + powerInc);
1042
1042
  mode.setSetting('power', targetPower);
1043
1043
  request = { targetPower };
1044
1044
  }
1045
1045
  else {
1046
1046
  const currentSpeedTarget = mode.getSetting('speed');
1047
1047
  const speedInc = powerInc / 5;
1048
- const speed = Number(currentSpeedTarget) + speedInc;
1048
+ const speed = Math.max(0, Number(currentSpeedTarget) + speedInc, 0);
1049
1049
  mode.setSetting('speed', speed);
1050
1050
  request = { speed };
1051
1051
  }
@@ -56,6 +56,7 @@ const verify = (route) => {
56
56
  const isNoResponseError = (err) => {
57
57
  return err?.message === 'Network Error' ||
58
58
  err?.code === 'ERR_NETWORK' ||
59
+ err?.response?.status === 504 ||
59
60
  (err?.isAxiosError === true && !err.response);
60
61
  };
61
62
  let IncyclistRoutesApi = (() => {
@@ -42,11 +42,7 @@ export interface ActivityAppLink {
42
42
  activity_id?: string;
43
43
  url?: string;
44
44
  }
45
- export type ActivityAppLinks = {
46
- strava?: ActivityAppLink;
47
- velohero?: ActivityAppLink;
48
- intervals?: ActivityAppLink;
49
- };
45
+ export type ActivityAppLinks = Record<string, ActivityAppLink>;
50
46
  export type ScreenShotInfo = {
51
47
  fileName: string;
52
48
  position?: RoutePoint;
@@ -3,7 +3,7 @@ import { JsonRepository } from "../../../api";
3
3
  import { Observer, PromiseObserver } from "../../../base/types/observer";
4
4
  import { ActivityDetails, ActivityInfo } from "../model";
5
5
  import { ActivitySearchCriteria } from "./types";
6
- export declare const DB_VERSION = "5";
6
+ export declare const DB_VERSION = "6";
7
7
  export declare const DB_NAME = "db";
8
8
  export declare class ActivitiesRepository {
9
9
  protected repo: JsonRepository;
@@ -54,6 +54,7 @@ export declare class ActivitiesRepository {
54
54
  protected _load(): Promise<void>;
55
55
  protected getActivity(id: string): ActivityInfo;
56
56
  protected logError(err: Error, fn: string, logProps?: any): void;
57
+ protected logWarning(err: Error, fn: string, logProps?: any): void;
57
58
  protected getRepo(): JsonRepository;
58
59
  protected getRouteList(): import("../../../routes").RouteListService;
59
60
  protected isMobile(): boolean;
@@ -1,4 +1,5 @@
1
1
  export * from './activity';
2
- import { ActivityDetails, ActivitySummary } from "../model";
2
+ import { ActivityAppLinks, ActivityDetails, ActivitySummary, UploadInfo } from "../model";
3
3
  export declare const buildSummary: (activity: ActivityDetails, proposedName?: string) => ActivitySummary;
4
+ export declare const buildUploadStatus: (links?: ActivityAppLinks) => UploadInfo[];
4
5
  export declare const getActivityTotalElevation: (activity: ActivityDetails) => number;
@@ -1,4 +1,5 @@
1
1
  export * from './strava';
2
2
  export * from './intervals';
3
+ export * from './komoot';
3
4
  export * from './types';
4
5
  export * from './factory';
@@ -0,0 +1,20 @@
1
+ import { IncyclistService } from "../../base/service";
2
+ import { ActivityDetails } from "../base";
3
+ import { IActivityUpload } from "./types";
4
+ import { KomootAppConnection } from "../../apps/komoot";
5
+ import { KomootUploadFormat } from "../../apps";
6
+ export declare class KomootUpload extends IncyclistService implements IActivityUpload {
7
+ protected isInitialized: any;
8
+ protected connection: KomootAppConnection;
9
+ constructor();
10
+ init(): boolean;
11
+ isConnected(): boolean;
12
+ upload(activity: ActivityDetails, format?: string): Promise<boolean>;
13
+ getUrl(activityId: string): string;
14
+ protected getKomootFormat(format: string): KomootUploadFormat;
15
+ protected ensureInitialized(): any;
16
+ protected readFile(fileName: string): Promise<string | Buffer<ArrayBufferLike>>;
17
+ protected getKomootAppConnection(): KomootAppConnection;
18
+ protected getApi(): import("../../apps").KomootApi;
19
+ protected getFS(): import("../../api").IFileSystem;
20
+ }
@@ -1,6 +1,6 @@
1
1
  import { EventLogger } from 'gd-eventlog';
2
2
  import { AppApiBase } from '../base';
3
- import { KomootAuthConfig, KomootCoordinate, KomootGetTourRequestFilters, KomootGetTourRequestParams, KomootLoginResponse, KomootTourSummary } from './types';
3
+ import { KomootAuthConfig, KomootCoordinate, KomootGetTourRequestFilters, KomootGetTourRequestParams, KomootLoginResponse, KomootSportType, KomootTourSummary, KomootUploadFormat } from './types';
4
4
  export declare class KomootApi extends AppApiBase {
5
5
  protected username: string;
6
6
  protected password: string;
@@ -12,6 +12,7 @@ export declare class KomootApi extends AppApiBase {
12
12
  isAuthenticated(): boolean;
13
13
  getTours(params?: KomootGetTourRequestParams, filters?: KomootGetTourRequestFilters): Promise<Array<KomootTourSummary>>;
14
14
  getTourCoordinates(id: number): Promise<Array<KomootCoordinate>>;
15
+ uploadTour(data: Buffer | ArrayBuffer | Uint8Array, format: KomootUploadFormat, sport: KomootSportType, name: string): Promise<KomootTourSummary>;
15
16
  protected applyFilter(tours: Array<KomootTourSummary>, filters?: KomootGetTourRequestFilters): KomootTourSummary[];
16
17
  protected getBasicAuthCredentials(): {
17
18
  username: string;
@@ -92,3 +92,4 @@ export interface KomootCoordinate extends KomootPoint {
92
92
  export type KomootTourType = 'tour_planned' | 'tour_recorded';
93
93
  export type KomootSportType = 'hike' | 'touringbicycle' | 'mtb' | 'racebike' | 'jogging' | 'mtb_easy' | 'mtb_advancde' | 'mountaineering';
94
94
  export type KomootSportTypeNames = 'Hiking' | 'Cycling' | 'Mountain biking' | 'Road cycling' | 'Running' | 'Gravel riding' | 'Enduro mountain biking' | 'Mountaineering';
95
+ export type KomootUploadFormat = 'fit' | 'gpx';
@@ -11,7 +11,7 @@ export declare class KomootAppConnection extends ConnectedAppService<KomootCrede
11
11
  isConnected(): boolean;
12
12
  getCredentials(): KomootCredentials;
13
13
  getApi(): KomootApi;
14
- protected iniAuth(): boolean;
14
+ protected initAuth(): boolean;
15
15
  protected checkAuth(): boolean;
16
16
  protected getAuthConfig(): KomootAuth | KomootCredentials;
17
17
  protected getUuid(): any;