incyclist-services 1.9.21 → 1.9.22

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 (46) hide show
  1. package/lib/cjs/activities/base/repo/db.js +7 -1
  2. package/lib/cjs/devices/page/base/guidance/guidance.js +277 -16
  3. package/lib/cjs/devices/page/base/service.js +245 -16
  4. package/lib/cjs/devices/page/desktop/matrix.js +2 -1
  5. package/lib/cjs/devices/page/desktop/service.js +4 -11
  6. package/lib/cjs/devices/page/mobile/service.js +1 -0
  7. package/lib/cjs/devices/pairing/conflict.js +47 -0
  8. package/lib/cjs/devices/pairing/guidance.js +40 -4
  9. package/lib/cjs/devices/pairing/helper.js +3 -1
  10. package/lib/cjs/devices/pairing/index.js +1 -0
  11. package/lib/cjs/devices/pairing/service.js +228 -35
  12. package/lib/cjs/devices/pairing/status.js +1 -0
  13. package/lib/cjs/devices/ride/service.js +20 -4
  14. package/lib/cjs/devices/ride/timeouts.js +9 -0
  15. package/lib/cjs/ride/display/service.js +2 -2
  16. package/lib/cjs/routes/base/api/api.js +1 -0
  17. package/lib/esm/activities/base/repo/db.js +7 -1
  18. package/lib/esm/devices/page/base/guidance/guidance.js +276 -15
  19. package/lib/esm/devices/page/base/service.js +246 -17
  20. package/lib/esm/devices/page/desktop/matrix.js +2 -1
  21. package/lib/esm/devices/page/desktop/service.js +4 -11
  22. package/lib/esm/devices/page/mobile/service.js +1 -0
  23. package/lib/esm/devices/pairing/conflict.js +9 -4
  24. package/lib/esm/devices/pairing/guidance.js +40 -4
  25. package/lib/esm/devices/pairing/helper.js +1 -0
  26. package/lib/esm/devices/pairing/index.js +1 -0
  27. package/lib/esm/devices/pairing/service.js +228 -35
  28. package/lib/esm/devices/pairing/status.js +1 -0
  29. package/lib/esm/devices/ride/service.js +20 -4
  30. package/lib/esm/ride/display/service.js +2 -2
  31. package/lib/esm/routes/base/api/api.js +1 -0
  32. package/lib/types/activities/base/repo/db.d.ts +1 -0
  33. package/lib/types/devices/page/base/guidance/guidance.d.ts +49 -2
  34. package/lib/types/devices/page/base/guidance/types.d.ts +20 -2
  35. package/lib/types/devices/page/base/service.d.ts +36 -2
  36. package/lib/types/devices/page/base/types.d.ts +31 -0
  37. package/lib/types/devices/page/desktop/service.d.ts +1 -2
  38. package/lib/types/devices/pairing/conflict.d.ts +4 -1
  39. package/lib/types/devices/pairing/guidance.d.ts +9 -4
  40. package/lib/types/devices/pairing/helper.d.ts +1 -0
  41. package/lib/types/devices/pairing/index.d.ts +1 -0
  42. package/lib/types/devices/pairing/model.d.ts +1 -0
  43. package/lib/types/devices/pairing/service.d.ts +43 -4
  44. package/lib/types/devices/pairing/status.d.ts +2 -1
  45. package/lib/types/devices/ride/service.d.ts +1 -0
  46. package/package.json +2 -2
@@ -70,6 +70,10 @@ let PairingPageService = (() => {
70
70
  handingOffToRide = false;
71
71
  guidance;
72
72
  onPairingStateHandler = this.onPairingState.bind(this);
73
+ onExclusionRevertedHandler = this.onExclusionReverted.bind(this);
74
+ onSelectionConflictHandler = this.updatePage.bind(this);
75
+ conflictStep;
76
+ cardChoices;
73
77
  constructor() {
74
78
  super('pairing');
75
79
  this.stateMachine = this.createOrchestrator();
@@ -77,6 +81,7 @@ let PairingPageService = (() => {
77
81
  this.guidance = new guidance_1.PairingGuidance({
78
82
  log: (message, fields) => { this.logEvent({ message, ...fields }); },
79
83
  onChange: () => { this.updatePage(); },
84
+ configuration: () => this.getDeviceConfiguration(),
80
85
  });
81
86
  }
82
87
  get openedCapability() {
@@ -174,40 +179,44 @@ let PairingPageService = (() => {
174
179
  const { capability: cap, deviceName, connectState, value, unit, disabled } = data;
175
180
  const capability = this.getTCapability(cap);
176
181
  const title = this.getDisplayCapability(cap);
177
- const onClick = () => { this.openDeviceSelection(cap); };
182
+ const openList = () => { this.openDeviceSelection(cap); };
178
183
  const role = pairing_1.PAIRING_CAPABILITY_ROLES.find(r => r.capability === cap)?.role;
179
184
  const helpText = {
180
185
  full: (0, pairing_1.getCapabilityHelpText)(capability, 'full') ?? '',
181
186
  short: (0, pairing_1.getCapabilityHelpText)(capability, 'short') ?? '',
182
187
  };
183
188
  if (disabled) {
184
- return this.getDisabledCapabilityDisplayProps(data, { title, capability, role, helpText, onClick });
189
+ return this.getDisabledCapabilityDisplayProps(data, { title, capability, role, helpText, onClick: openList });
185
190
  }
186
191
  const adapaters = this.state.adapters ?? [];
187
192
  const adapter = adapaters.find(ai => data.selected && ai.udid === data.selected);
188
193
  const ifName = adapter?.adapter?.getInterface();
189
- const onUnselect = data.selected ? () => { this.onCapabilityUnselect(cap); } : undefined;
194
+ const tileState = this.getTileState(data, role, noSearch);
195
+ const onUnselect = data.selected && !tileState.dimmed ? () => { this.onCapabilityUnselect(cap); } : undefined;
196
+ const useTrainerAgain = tileState.dimmed && cap === incyclist_devices_1.IncyclistCapability.Control;
197
+ const onClick = useTrainerAgain ? () => { this.onUseTrainerAgain(); } : openList;
190
198
  const emptyFooter = this.getActiveCapabilityEmptyFooter(cap, role, noSearch);
191
199
  const found = Boolean(data.selected) && this.getSearchStatus()?.running === true && adapter?.adapter?.isStarted() !== true;
192
200
  const stateText = found ? 'Found' : undefined;
193
201
  return {
194
202
  title, capability, deviceName, disabled: false, connectState, value: value?.toString(), unit, interface: ifName,
195
203
  role, helpText, emptyFooter, stateText,
196
- ...this.getTileState(data, role, noSearch),
204
+ ...tileState,
197
205
  onClick, onUnselect
198
206
  };
199
207
  }
200
208
  getTileState(data, role, noSearch) {
201
209
  try {
202
210
  const control = (this.state.capabilities ?? []).find(c => c.capability === incyclist_devices_1.IncyclistCapability.Control);
203
- const { trainerPhase } = this.guidance.getState();
211
+ const { trainerPhase, trainerRetry, fallback } = this.guidance.getState();
204
212
  const { selectedReason, separateSensor } = this.guidance.getHelper();
205
213
  return (0, pairing_1.getPairingTileState)({
206
214
  capability: data.capability, role, disabled: data.disabled, selected: data.selected, connectState: data.connectState,
207
215
  noSearch, canStartRide: this.canStartRide(),
208
- trainerPhase, trainerUdid: control?.selected,
216
+ trainerPhase, trainerRetry, trainerUdid: control?.selected,
209
217
  trainerUnavailablePicked: selectedReason === 'trainer_unavailable',
210
218
  separateSensor: separateSensor !== undefined,
219
+ fallbackActive: fallback !== undefined,
211
220
  });
212
221
  }
213
222
  catch (err) {
@@ -255,7 +264,7 @@ let PairingPageService = (() => {
255
264
  onDelete: () => { this.onDeviceDelete(d); }
256
265
  }));
257
266
  const disabled = devices.length > 0 && !devices.some(d => d.isSelected);
258
- return {
267
+ const props = {
259
268
  capability: this.openedCapability,
260
269
  devices,
261
270
  isScanning: this.stateMachine.selectState === 'Active',
@@ -264,6 +273,101 @@ let PairingPageService = (() => {
264
273
  disabled,
265
274
  onClose: () => { this.closeDeviceSelection(); },
266
275
  };
276
+ return this.withConflictStep(props);
277
+ }
278
+ withConflictStep(props) {
279
+ const step = this.conflictStep;
280
+ if (step) {
281
+ props.conflictStep = this.getConflictStepProps(step.conflict, step.choices, 0, {
282
+ onDone: () => { this.closeConflictStep('done'); },
283
+ onDismiss: () => { this.closeConflictStep('dismissed'); },
284
+ });
285
+ }
286
+ return props;
287
+ }
288
+ getPendingConflictDisplayProps() {
289
+ try {
290
+ if (!this.isVisitOpen || this.isPanelSlotTaken())
291
+ return undefined;
292
+ const pending = this.getDevicePairing().getPendingConflicts?.() ?? [];
293
+ const [head] = pending;
294
+ if (!head) {
295
+ delete this.cardChoices;
296
+ return undefined;
297
+ }
298
+ if (this.cardChoices?.id !== head.id)
299
+ this.cardChoices = { id: head.id, choices: new Map() };
300
+ return this.getConflictStepProps(head, this.cardChoices.choices, pending.length - 1, {
301
+ onDone: () => { this.onConflictCardDone(head.id); },
302
+ onDismiss: () => { this.onConflictCardDismissed(head.id); },
303
+ });
304
+ }
305
+ catch (err) {
306
+ this.logError(err, 'getPendingConflictDisplayProps');
307
+ return undefined;
308
+ }
309
+ }
310
+ isPanelSlotTaken() {
311
+ if (this.openedCapability !== undefined)
312
+ return true;
313
+ try {
314
+ return this.guidance.getHelper().phase !== 'hidden';
315
+ }
316
+ catch (err) {
317
+ this.logError(err, 'isPanelSlotTaken');
318
+ return false;
319
+ }
320
+ }
321
+ getConflictStepProps(conflict, choices, queued, handlers) {
322
+ const { id, origin, deviceName, filled } = conflict;
323
+ const props = {
324
+ id, origin, deviceName,
325
+ title: (0, pairing_1.getConflictStepTitle)(deviceName),
326
+ subline: (0, pairing_1.getConflictStepSubline)(origin, deviceName, filled),
327
+ rows: conflict.conflicts.map(c => ({
328
+ capability: this.getTCapability(c.capability),
329
+ capabilityTitle: (0, pairing_1.getCapabilityTitle)(c.capability),
330
+ currentName: c.currentName,
331
+ choice: choices.get(c.capability) ?? 'keep',
332
+ keepLabel: (0, pairing_1.getConflictKeepLabel)(c.currentName),
333
+ replaceLabel: (0, pairing_1.getConflictReplaceLabel)(deviceName),
334
+ })),
335
+ queued,
336
+ onChoice: (capability, choice) => {
337
+ choices.set(capability, choice);
338
+ this.updatePage();
339
+ },
340
+ ...handlers,
341
+ };
342
+ const queuedText = (0, pairing_1.getConflictQueuedText)(queued);
343
+ if (queuedText)
344
+ props.queuedText = queuedText;
345
+ return props;
346
+ }
347
+ getReplacedCapabilities(choices) {
348
+ return [...choices].filter(([, choice]) => choice === 'replace').map(([capability]) => capability);
349
+ }
350
+ onConflictCardDone(id) {
351
+ const replace = this.getReplacedCapabilities(this.cardChoices?.choices ?? new Map());
352
+ delete this.cardChoices;
353
+ this.getDevicePairing().resolveConflict(id, replace)
354
+ .catch(err => { this.logError(err, 'onConflictCardDone'); });
355
+ this.updatePage();
356
+ }
357
+ onConflictCardDismissed(id) {
358
+ const replace = this.getReplacedCapabilities(this.cardChoices?.choices ?? new Map());
359
+ delete this.cardChoices;
360
+ this.getDevicePairing().resolveConflict(id, replace, 'dismissed')
361
+ .catch(err => { this.logError(err, 'onConflictCardDismissed'); });
362
+ this.updatePage();
363
+ }
364
+ reevaluateConflicts(changed) {
365
+ try {
366
+ this.getDevicePairing().reevaluatePendingConflicts?.(changed);
367
+ }
368
+ catch (err) {
369
+ this.logError(err, 'reevaluateConflicts');
370
+ }
267
371
  }
268
372
  updatePage() {
269
373
  this.getPageObserver()?.emit('page-update');
@@ -283,20 +387,80 @@ let PairingPageService = (() => {
283
387
  onDeviceSelected(d, addAll) {
284
388
  const capability = this.openedCapability;
285
389
  this.logEvent({ message: 'device selected', capability, device: d.name });
390
+ if (capability === incyclist_devices_1.IncyclistCapability.Control && addAll === undefined) {
391
+ this.onResistanceDevicePicked(d);
392
+ return;
393
+ }
286
394
  this.closeDeviceSelection();
287
- this.getDevicePairing().selectDevice(capability, d.udid, addAll)
395
+ this.selectDevice(capability, d.udid, addAll ?? false);
396
+ this.updatePage();
397
+ }
398
+ onResistanceDevicePicked(d) {
399
+ const conflict = this.startManualConflict(d.udid);
400
+ if (conflict) {
401
+ this.conflictStep = { conflict, choices: new Map() };
402
+ this.updatePage();
403
+ return;
404
+ }
405
+ this.closeDeviceSelection();
406
+ this.selectDevice(incyclist_devices_1.IncyclistCapability.Control, d.udid, { others: 'fill-empty', replace: [] });
407
+ this.updatePage();
408
+ }
409
+ startManualConflict(udid) {
410
+ try {
411
+ return this.getDevicePairing().startManualConflict?.(incyclist_devices_1.IncyclistCapability.Control, udid);
412
+ }
413
+ catch (err) {
414
+ this.logError(err, 'startManualConflict');
415
+ return undefined;
416
+ }
417
+ }
418
+ selectDevice(capability, udid, mode) {
419
+ this.getDevicePairing().selectDevice(capability, udid, mode)
288
420
  .catch(err => { this.logError(err, 'onDeviceSelected'); });
421
+ this.reevaluateConflicts(mode === false ? [capability] : undefined);
422
+ }
423
+ closeConflictStep(via) {
424
+ if (!this.commitConflictStep(via))
425
+ return;
426
+ this.closeDeviceSelection();
289
427
  this.updatePage();
290
428
  }
429
+ commitConflictStep(via) {
430
+ const step = this.conflictStep;
431
+ if (!step)
432
+ return false;
433
+ delete this.conflictStep;
434
+ this.getDevicePairing().commitManualConflict(step.conflict.id, this.getReplacedCapabilities(step.choices), via)
435
+ .catch(err => { this.logError(err, 'commitConflictStep'); });
436
+ this.reevaluateConflicts();
437
+ return true;
438
+ }
291
439
  onCapabilityUnselect(cap) {
292
440
  this.logEvent({ message: 'capability unselect clicked', capability: cap, eventSource: 'user' });
441
+ if (cap === incyclist_devices_1.IncyclistCapability.Control && this.getResistanceUnselectAction() === 'open-helper') {
442
+ this.withGuidance(g => g.openHelperForUnavailableTrainer('tile_unselect'), 'onCapabilityUnselect');
443
+ this.updatePage();
444
+ return;
445
+ }
293
446
  this.getDevicePairing().unselectDevices(cap)
294
447
  .catch(err => { this.logError(err, 'onCapabilityUnselect'); });
448
+ this.reevaluateConflicts([cap]);
295
449
  this.updatePage();
296
450
  }
451
+ getResistanceUnselectAction() {
452
+ try {
453
+ return this.guidance.getResistanceUnselectAction();
454
+ }
455
+ catch (err) {
456
+ this.logError(err, 'getResistanceUnselectAction');
457
+ return 'unselect';
458
+ }
459
+ }
297
460
  onCapabilityUse(cap) {
298
461
  this.logEvent({ message: 'capability use clicked', capability: cap, eventSource: 'user' });
299
462
  this.getDevicePairing().useCapability(cap);
463
+ this.reevaluateConflicts([cap]);
300
464
  this.updatePage();
301
465
  }
302
466
  onDeviceDelete(d) {
@@ -304,10 +468,12 @@ let PairingPageService = (() => {
304
468
  this.logEvent({ message: 'device delete requested', capability, device: d.name });
305
469
  this.getDevicePairing().deleteDevice(capability, d.udid)
306
470
  .catch(err => { this.logError(err, 'onDeviceDelete'); });
471
+ this.reevaluateConflicts([capability]);
307
472
  this.updatePage();
308
473
  }
309
474
  closeDeviceSelection() {
310
475
  this.logEvent({ message: 'capability closed', capability: this.openedCapability, caller: new Error().stack });
476
+ this.commitConflictStep('dismissed');
311
477
  this.openedCapability = undefined;
312
478
  Promise.resolve(this.stateMachine.onDeviceSelectionClosed())
313
479
  .catch(err => { this.logError(err, 'closeDeviceSelection'); });
@@ -387,6 +553,8 @@ let PairingPageService = (() => {
387
553
  this.isVisitOpen = true;
388
554
  }
389
555
  closeVisit(via) {
556
+ this.commitConflictStep('left_page');
557
+ delete this.cardChoices;
390
558
  this.trackVisit(t => t.closeVisit(via, { canStartRide: this.canStartRide() }), 'closeVisit');
391
559
  this.trackVisit(t => t.setExitFields(undefined), 'closeVisit');
392
560
  this.withGuidance(g => g.closeVisit(), 'closeVisit');
@@ -405,8 +573,13 @@ let PairingPageService = (() => {
405
573
  try {
406
574
  const pairing = this.getDevicePairing();
407
575
  pairing.off?.('pairing-state', this.onPairingStateHandler);
408
- if (listen)
576
+ pairing.off?.('exclusion-reverted', this.onExclusionRevertedHandler);
577
+ pairing.off?.('selection-conflict', this.onSelectionConflictHandler);
578
+ if (listen) {
409
579
  pairing.on?.('pairing-state', this.onPairingStateHandler);
580
+ pairing.on?.('exclusion-reverted', this.onExclusionRevertedHandler);
581
+ pairing.on?.('selection-conflict', this.onSelectionConflictHandler);
582
+ }
410
583
  }
411
584
  catch (err) {
412
585
  this.logError(err, 'listenToPairingState');
@@ -415,6 +588,10 @@ let PairingPageService = (() => {
415
588
  onPairingState(state) {
416
589
  this.withGuidance(g => g.onPairingState(state), 'onPairingState');
417
590
  }
591
+ onExclusionReverted(event) {
592
+ this.withGuidance(g => g.onFallbackReverted(event?.udid), 'onExclusionReverted');
593
+ this.updatePage();
594
+ }
418
595
  getStatusDisplayProps(interfaces) {
419
596
  const src = {
420
597
  platform: this.getPlatform(),
@@ -441,15 +618,25 @@ let PairingPageService = (() => {
441
618
  .map(r => capProps.find(c => c.capability === this.getTCapability(r.capability)))
442
619
  .filter(c => c !== undefined);
443
620
  const trainerSelected = (0, pairing_1.isCapabilityActive)(caps.find(c => c.capability === incyclist_devices_1.IncyclistCapability.Control));
621
+ const fallbackReady = this.isFallbackActive() && this.canStartRide();
444
622
  return {
445
623
  top: row('required'),
446
624
  bottom: row('optional'),
447
625
  rowLabels: {
448
- top: (0, pairing_1.getPairingGuidanceText)((0, pairing_1.getPairingRowLabelId)(trainerSelected, this.isStillLooking(), this.getTrainerPhase())),
626
+ top: (0, pairing_1.getPairingGuidanceText)((0, pairing_1.getPairingRowLabelId)(trainerSelected, this.isStillLooking(), this.getTrainerPhase(), fallbackReady)),
449
627
  bottom: (0, pairing_1.getPairingGuidanceText)('row-optional'),
450
628
  },
451
629
  };
452
630
  }
631
+ isFallbackActive() {
632
+ try {
633
+ return this.guidance.getState().fallback !== undefined;
634
+ }
635
+ catch (err) {
636
+ this.logError(err, 'isFallbackActive');
637
+ return false;
638
+ }
639
+ }
453
640
  getTrainerPhase() {
454
641
  try {
455
642
  return this.guidance.getState().trainerPhase;
@@ -495,18 +682,60 @@ let PairingPageService = (() => {
495
682
  return props;
496
683
  }
497
684
  props.tip = (0, pairing_1.getPairingHelperTip)(selectedReason, { platform, separateSensor });
498
- if ((0, pairing_1.hasContinueWithoutDeviceAction)(selectedReason, separateSensor)) {
499
- const { label, note } = this.guidance.getContinueWithoutDeviceAction();
500
- props.action = { label, onClick: () => { this.onContinueWithoutDevice(); } };
501
- if (note)
502
- props.action.note = note;
503
- }
685
+ const action = this.getHelperActionProps(selectedReason, helper);
686
+ if (action)
687
+ props.action = action;
504
688
  return props;
505
689
  }
690
+ getHelperActionProps(reason, helper) {
691
+ const { fallbackCandidate, separateSensor } = helper;
692
+ if (reason === 'trainer_unavailable' && fallbackCandidate)
693
+ return { label: (0, pairing_1.getFallbackActionLabel)(fallbackCandidate), onClick: () => { this.onChooseFallback(); } };
694
+ if (!(0, pairing_1.hasContinueWithoutDeviceAction)(reason, separateSensor))
695
+ return undefined;
696
+ const { label, note } = this.guidance.getContinueWithoutDeviceAction();
697
+ const action = { label, onClick: () => { this.onContinueWithoutDevice(); } };
698
+ if (note)
699
+ action.note = note;
700
+ return action;
701
+ }
702
+ onChooseFallback() {
703
+ this.withGuidance(g => { g.chooseFallback(); }, 'onChooseFallback');
704
+ this.updatePage();
705
+ }
706
+ onUseTrainerAgain() {
707
+ this.logEvent({ message: 'use trainer again clicked', eventSource: 'user' });
708
+ let started = false;
709
+ this.withGuidance(g => {
710
+ g.cancelFallback();
711
+ started = g.startRiderRetry({ trigger: 'tile' });
712
+ }, 'onUseTrainerAgain');
713
+ const covered = this.reconnectNow();
714
+ if (started)
715
+ this.withGuidance(g => g.logRiderRetry(covered), 'onUseTrainerAgain');
716
+ this.updatePage();
717
+ }
718
+ reconnectNow() {
719
+ try {
720
+ return this.getDevicePairing().reconnectNow() ?? [];
721
+ }
722
+ catch (err) {
723
+ this.logError(err, 'reconnectNow');
724
+ return [];
725
+ }
726
+ }
506
727
  onHelperOpen() {
728
+ if (this.getTrainerPhase() === 'unavailable') {
729
+ this.onTrainerUnavailable();
730
+ return;
731
+ }
507
732
  this.withGuidance(g => g.openHelper(), 'onHelperOpen');
508
733
  this.updatePage();
509
734
  }
735
+ onTrainerUnavailable() {
736
+ this.withGuidance(g => g.openHelperForUnavailableTrainer('trainer_unavailable_link'), 'onTrainerUnavailable');
737
+ this.updatePage();
738
+ }
510
739
  onHelperDismissed() {
511
740
  this.withGuidance(g => g.dismissHelper(), 'onHelperDismissed');
512
741
  this.updatePage();
@@ -16,7 +16,8 @@ exports.DESKTOP_MATRIX = [
16
16
  { area: 'simulator', name: 'Shift+S adds the simulator', given: 'Shift+S pressed', expected: 'deviceConfig.add({name:"Simulator", interface:"simulator"}); the key is disabled afterwards' },
17
17
  { area: 'tiles', name: 'Tile ✕ unselects the capability', given: 'a selected tile', expected: 'devicePairing.unselectDevices(capability)' },
18
18
  { area: 'device-list', name: 'Opening a tile opens its device list', given: 'tile clicked', expected: 'DeviceSelector opens for that capability' },
19
- { area: 'device-list', name: 'Select with changeForAll default for Resistance', given: 'capability=control, device clicked', expected: 'selectDevice(control, udid, true); the dialog closes' },
19
+ { area: 'device-list', name: 'Select for Resistance', given: 'capability=control, device clicked without a "for all" value', expected: 'free slots are filled; slots held by another device are asked about in the list (conflictStep) before selectDevice(control, udid, {others:"fill-empty", replace}); the dialog closes once answered' },
20
+ { area: 'device-list', name: 'Select for Resistance with the deprecated "for all" value', given: 'capability=control, device clicked with addAll', expected: 'selectDevice(control, udid, addAll); the dialog closes' },
20
21
  { area: 'device-list', name: 'Select with changeForAll default for other capabilities', given: 'capability!=control, device clicked', expected: 'selectDevice(capability, udid, false); the dialog closes' },
21
22
  { area: 'device-list', name: 'Select-all is offered for Resistance only', given: 'capability=control', expected: 'canSelectAll true; other capabilities false' },
22
23
  { area: 'device-list', name: 'Delete a device in the list', given: 'delete clicked on a device', expected: 'devicePairing.deleteDevice(capability, udid); the list stays open' },
@@ -95,6 +95,7 @@ let DesktopPairingPageService = (() => {
95
95
  buttons: this.getButtonsDisplayProps(noSearch),
96
96
  showInterfaceSettings: this.getInterfaceSettingsDisplayProps(),
97
97
  ...this.getGuidanceDisplayProps(),
98
+ pendingConflict: this.getPendingConflictDisplayProps(),
98
99
  };
99
100
  }
100
101
  catch (err) {
@@ -117,17 +118,9 @@ let DesktopPairingPageService = (() => {
117
118
  });
118
119
  this.updatePage();
119
120
  }
120
- onDeviceSelected(d, addAll) {
121
- const capability = this.openedCapability;
122
- this.logEvent({ message: 'device selected', capability, device: d.name });
123
- const changeForAll = addAll ?? (capability === incyclist_devices_1.IncyclistCapability.Control);
124
- this.closeDeviceSelection();
125
- this.getDevicePairing().selectDevice(capability, d.udid, changeForAll)
126
- .catch(err => { this.logError(err, 'onDeviceSelected'); });
127
- this.updatePage();
128
- }
129
121
  closeDeviceSelection() {
130
122
  this.logEvent({ message: 'capability closed', capability: this.openedCapability });
123
+ this.commitConflictStep('dismissed');
131
124
  this.getDevicePairing().stopDeviceSelection()
132
125
  .catch(err => { this.logError(err, 'closeDeviceSelection'); });
133
126
  this.openedCapability = undefined;
@@ -149,7 +142,7 @@ let DesktopPairingPageService = (() => {
149
142
  }));
150
143
  const disabled = devices.length > 0 && !devices.some(d => d.isSelected);
151
144
  const canSelectAll = this.openedCapability === incyclist_devices_1.IncyclistCapability.Control;
152
- return {
145
+ return this.withConflictStep({
153
146
  capability: this.openedCapability,
154
147
  devices,
155
148
  isScanning: Boolean(this.deviceSelectState?.isScanning),
@@ -157,7 +150,7 @@ let DesktopPairingPageService = (() => {
157
150
  canSelectAll,
158
151
  disabled,
159
152
  onClose: () => { this.closeDeviceSelection(); },
160
- };
153
+ });
161
154
  }
162
155
  getInterfaceDisplayProps(info) {
163
156
  const { name, state, isScanning, enabled, protocol, port } = info;
@@ -104,6 +104,7 @@ let MobilePairingPageService = (() => {
104
104
  buttons: this.getButtonsDisplayProps(noSearch),
105
105
  onExit,
106
106
  ...this.getGuidanceDisplayProps(),
107
+ pendingConflict: this.getPendingConflictDisplayProps(),
107
108
  };
108
109
  }
109
110
  catch (err) {
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getConflictQueuedText = exports.getConflictReplaceLabel = exports.getConflictKeepLabel = exports.getConflictStepSubline = exports.getConflictStepTitle = exports.getCapabilityTitle = void 0;
4
+ const CAPABILITY_TITLES = {
5
+ control: 'Resistance',
6
+ power: 'Power',
7
+ speed: 'Speed',
8
+ cadence: 'Cadence',
9
+ heartrate: 'Heartrate',
10
+ app_control: 'Controller',
11
+ };
12
+ const joinNames = (names) => {
13
+ if (names.length <= 1)
14
+ return names.join('');
15
+ return `${names.slice(0, -1).join(', ')} and ${names.at(-1)}`;
16
+ };
17
+ const getCapabilityTitle = (capability) => CAPABILITY_TITLES[capability] ?? capability;
18
+ exports.getCapabilityTitle = getCapabilityTitle;
19
+ const getConflictStepTitle = (deviceName) => `${deviceName} can also measure more`;
20
+ exports.getConflictStepTitle = getConflictStepTitle;
21
+ const getConflictStepSubline = (origin, deviceName, filled) => {
22
+ const names = filled.map(exports.getCapabilityTitle);
23
+ const freed = names.length > 1 ? `${joinNames(names)} were free and now use` : `${joinNames(names)} was free and now uses`;
24
+ if (origin === 'manual') {
25
+ const full = names.length > 0
26
+ ? `Choose which device to use for each. ${freed} ${deviceName}.`
27
+ : 'Choose which device to use for each.';
28
+ return { full, short: 'Choose which device to use for each.' };
29
+ }
30
+ const short = `Just found ${deviceName}. Nothing changes until you choose.`;
31
+ const full = names.length > 0
32
+ ? `We just found your ${deviceName}. Nothing changes until you choose. ${freed} ${deviceName}.`
33
+ : `We just found your ${deviceName}. Nothing changes until you choose.`;
34
+ return { full, short };
35
+ };
36
+ exports.getConflictStepSubline = getConflictStepSubline;
37
+ const getConflictKeepLabel = (currentName) => `Keep ${currentName}`;
38
+ exports.getConflictKeepLabel = getConflictKeepLabel;
39
+ const getConflictReplaceLabel = (deviceName) => `Use ${deviceName}`;
40
+ exports.getConflictReplaceLabel = getConflictReplaceLabel;
41
+ const getConflictQueuedText = (queued) => {
42
+ if (queued <= 0)
43
+ return undefined;
44
+ const device = queued === 1 ? 'device' : 'devices';
45
+ return { full: `${queued} more ${device} to check`, short: `${queued} more to check` };
46
+ };
47
+ exports.getConflictQueuedText = getConflictQueuedText;
@@ -62,11 +62,12 @@ const isPartialOutageShown = (input) => {
62
62
  const now = input.now ?? Date.now();
63
63
  return now - input.partialOutageSince >= exports.PARTIAL_OUTAGE_DEBOUNCE_MS;
64
64
  };
65
+ const UNAVAILABLE_STATUS_BY_RETRY = { running: 'S7a', failed: 'S7b' };
65
66
  const getTrainerStatus = (input) => {
66
67
  if (input.trainerPhase === 'connecting')
67
68
  return 'S3';
68
69
  if (input.trainerPhase === 'unavailable')
69
- return 'S7';
70
+ return input.trainerRetry ? UNAVAILABLE_STATUS_BY_RETRY[input.trainerRetry] : 'S7';
70
71
  if (input.connectingDeviceName)
71
72
  return 'S3';
72
73
  return undefined;
@@ -186,6 +187,16 @@ const getTrainerUnreachableText = (trainer, isShort) => isShort
186
187
  link: 'Not available today?',
187
188
  stateOnlyText: `Can't reach your trainer ${trainer}.`,
188
189
  };
190
+ const getTrainerRetryRunningText = (trainer, isShort) => isShort
191
+ ? { text: `Trying to reach ${trainer}…`, link: 'Not available?' }
192
+ : { text: `Trying to reach your trainer ${trainer}…`, link: 'Not available today?' };
193
+ const getTrainerRetryFailedText = (trainer, isShort) => isShort
194
+ ? { text: `Still can't reach ${trainer}`, link: 'Not available?' }
195
+ : {
196
+ text: `Still can't reach your trainer ${trainer}. Check it's switched on and not connected to another app.`,
197
+ link: 'Not available today?',
198
+ stateOnlyText: `Still can't reach your trainer ${trainer}.`,
199
+ };
189
200
  const getAllSwitchedOffText = (canToggle, isShort) => {
190
201
  if (isShort)
191
202
  return { text: canToggle ? 'To ride: all switched off. Switch one on.' : 'To ride: all switched off. Tap one to choose.' };
@@ -211,6 +222,8 @@ const getRowLabelText = (id) => {
211
222
  return { text: 'TO RIDE', subtext: 'waiting for your trainer' };
212
223
  case 'row-ready':
213
224
  return { text: '✓ READY TO RIDE' };
225
+ case 'row-ready-without-resistance':
226
+ return { text: '✓ READY TO RIDE', subtext: 'without resistance control' };
214
227
  case 'row-optional':
215
228
  return { text: 'OPTIONAL', subtext: 'extras, not needed' };
216
229
  case 'row-searching-trainer':
@@ -229,6 +242,12 @@ const getTileText = (id, isShort) => {
229
242
  return { text: 'via your trainer' };
230
243
  case 'tile-trainer-waiting':
231
244
  return { text: isShort ? 'Waiting…' : 'Waiting to connect' };
245
+ case 'tile-trainer-connecting':
246
+ return { text: 'Connecting…' };
247
+ case 'tile-tap-to-use-again':
248
+ return { text: 'Tap to use again' };
249
+ case 'tile-not-used':
250
+ return { text: 'Not used' };
232
251
  case 'tile-waiting-for-trainer':
233
252
  return { text: isShort ? 'Waiting…' : 'Waiting for trainer' };
234
253
  case 'tile-optional-for-now':
@@ -275,6 +294,10 @@ const getPairingGuidanceText = (id, params = {}, variant = 'full') => {
275
294
  return getStillSearchingText(isShort);
276
295
  case 'S7':
277
296
  return getTrainerUnreachableText(params.trainerName ?? '', isShort);
297
+ case 'S7a':
298
+ return getTrainerRetryRunningText(params.trainerName ?? '', isShort);
299
+ case 'S7b':
300
+ return getTrainerRetryFailedText(params.trainerName ?? '', isShort);
278
301
  case 'S8':
279
302
  return getAllSwitchedOffText(params.switchedOffCanToggle, isShort);
280
303
  case 'S9':
@@ -282,9 +305,11 @@ const getPairingGuidanceText = (id, params = {}, variant = 'full') => {
282
305
  }
283
306
  };
284
307
  exports.getPairingGuidanceText = getPairingGuidanceText;
285
- const getPairingRowLabelId = (trainerSelected, stillLooking = false, trainerPhase) => {
308
+ const getPairingRowLabelId = (trainerSelected, stillLooking = false, trainerPhase, fallbackReady = false) => {
286
309
  if (stillLooking)
287
310
  return trainerSelected ? 'row-searching-found' : 'row-searching-trainer';
311
+ if (fallbackReady)
312
+ return 'row-ready-without-resistance';
288
313
  if (!trainerSelected)
289
314
  return 'row-required';
290
315
  return trainerPhase === 'unavailable' ? 'row-required-trainer-waiting' : 'row-required-trainer';
@@ -312,10 +337,21 @@ const tileFooter = (id) => ({
312
337
  short: (0, exports.getPairingGuidanceText)(id, {}, 'short').text,
313
338
  });
314
339
  const tileRoleLabel = (id) => (0, exports.getPairingGuidanceText)(id).text;
340
+ const getFallbackTileState = (input) => {
341
+ if (input.capability === 'control')
342
+ return { trainerRole: 'trainer', roleLabel: tileRoleLabel('tile-role-trainer'), footerText: tileFooter('tile-tap-to-use-again'), awaited: false, dimmed: true };
343
+ if (input.selected !== undefined && input.selected === input.trainerUdid)
344
+ return { trainerRole: 'via-trainer', footerText: tileFooter('tile-not-used'), awaited: false, dimmed: true };
345
+ return undefined;
346
+ };
315
347
  const getUnavailableTrainerTileState = (input) => {
316
348
  const { capability, selected, trainerUdid } = input;
317
- if (capability === 'control')
318
- return { trainerRole: 'trainer', roleLabel: tileRoleLabel('tile-role-trainer'), footerText: tileFooter('tile-trainer-waiting'), awaited: true };
349
+ if (input.fallbackActive)
350
+ return getFallbackTileState(input);
351
+ if (capability === 'control') {
352
+ const footer = input.trainerRetry === 'running' ? 'tile-trainer-connecting' : 'tile-trainer-waiting';
353
+ return { trainerRole: 'trainer', roleLabel: tileRoleLabel('tile-role-trainer'), footerText: tileFooter(footer), awaited: true };
354
+ }
319
355
  const canReplace = TRAINER_REPLACEMENTS.has(capability);
320
356
  const needsReplacement = canReplace && input.trainerUnavailablePicked === true && !input.separateSensor;
321
357
  if (selected !== undefined && selected === trainerUdid)
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getPairingHelperTip = exports.getPairingHelperReasonLabel = exports.getPairingHelperFooter = exports.PAIRING_HELPER_RESOLVED_TEXT = exports.PAIRING_HELPER_SUBLINE = exports.getPairingHelperTitle = exports.hasContinueWithoutDeviceAction = exports.getContinueWithoutDeviceAction = exports.getPairingHelperReasons = void 0;
3
+ exports.getPairingHelperTip = exports.getPairingHelperReasonLabel = exports.getPairingHelperFooter = exports.PAIRING_HELPER_RESOLVED_TEXT = exports.PAIRING_HELPER_SUBLINE = exports.getPairingHelperTitle = exports.getFallbackActionLabel = exports.hasContinueWithoutDeviceAction = exports.getContinueWithoutDeviceAction = exports.getPairingHelperReasons = void 0;
4
4
  const COMMON_REASONS = ['asleep', 'other_app', 'interface'];
5
5
  const getPairingHelperReasons = (trainerPhase) => {
6
6
  if (trainerPhase === undefined)
@@ -22,6 +22,8 @@ exports.getContinueWithoutDeviceAction = getContinueWithoutDeviceAction;
22
22
  const hasContinueWithoutDeviceAction = (reason, separateSensor) => reason === 'no_device' || (reason === 'trainer_unavailable' && separateSensor === undefined);
23
23
  exports.hasContinueWithoutDeviceAction = hasContinueWithoutDeviceAction;
24
24
  const SENSOR_LABELS = { power: 'power meter', speed: 'speed sensor' };
25
+ const getFallbackActionLabel = (capability) => `Ride with ${SENSOR_LABELS[capability]} only`;
26
+ exports.getFallbackActionLabel = getFallbackActionLabel;
25
27
  const getPairingHelperTitle = (trainerConfigured) => trainerConfigured ? "Can't connect to your trainer?" : "Can't find your trainer?";
26
28
  exports.getPairingHelperTitle = getPairingHelperTitle;
27
29
  exports.PAIRING_HELPER_SUBLINE = "Pick what fits best and we'll show you what to try.";
@@ -20,3 +20,4 @@ __exportStar(require("./guidance"), exports);
20
20
  __exportStar(require("./status"), exports);
21
21
  __exportStar(require("./capability"), exports);
22
22
  __exportStar(require("./helper"), exports);
23
+ __exportStar(require("./conflict"), exports);