incyclist-services 1.9.16 → 1.9.17
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.
- package/lib/cjs/activities/ride/service.js +11 -11
- package/lib/cjs/devices/access/service.js +2 -1
- package/lib/cjs/devices/configuration/model/add/index.js +2 -0
- package/lib/cjs/devices/configuration/model/exclusion/index.js +2 -0
- package/lib/cjs/devices/configuration/model/index.js +2 -0
- package/lib/cjs/devices/configuration/service.js +119 -18
- package/lib/cjs/devices/page/base/service.js +96 -20
- package/lib/cjs/devices/page/desktop/service.js +4 -3
- package/lib/cjs/devices/page/mobile/service.js +4 -3
- package/lib/cjs/devices/page/mobile/statemachine.js +36 -20
- package/lib/cjs/devices/pairing/capability.js +5 -0
- package/lib/cjs/devices/pairing/guidance.js +81 -22
- package/lib/cjs/devices/pairing/index.js +1 -0
- package/lib/cjs/devices/pairing/service.js +507 -43
- package/lib/cjs/devices/pairing/status.js +17 -5
- package/lib/esm/activities/ride/service.js +11 -11
- package/lib/esm/devices/access/service.js +2 -1
- package/lib/esm/devices/configuration/model/index.js +2 -0
- package/lib/esm/devices/configuration/service.js +119 -18
- package/lib/esm/devices/page/base/service.js +96 -20
- package/lib/esm/devices/page/desktop/service.js +5 -4
- package/lib/esm/devices/page/mobile/service.js +5 -4
- package/lib/esm/devices/page/mobile/statemachine.js +36 -20
- package/lib/esm/devices/pairing/guidance.js +81 -22
- package/lib/esm/devices/pairing/index.js +1 -0
- package/lib/esm/devices/pairing/service.js +507 -43
- package/lib/esm/devices/pairing/status.js +17 -5
- package/lib/types/devices/access/service.d.ts +1 -0
- package/lib/types/devices/configuration/model/app/index.d.ts +5 -0
- package/lib/types/devices/configuration/model/index.d.ts +2 -0
- package/lib/types/devices/configuration/service.d.ts +23 -1
- package/lib/types/devices/page/base/service.d.ts +22 -2
- package/lib/types/devices/page/base/types.d.ts +1 -0
- package/lib/types/devices/page/mobile/statemachine.d.ts +3 -0
- package/lib/types/devices/pairing/guidance.d.ts +7 -3
- package/lib/types/devices/pairing/index.d.ts +1 -0
- package/lib/types/devices/pairing/model.d.ts +40 -1
- package/lib/types/devices/pairing/service.d.ts +83 -4
- package/lib/types/devices/pairing/status.d.ts +11 -6
- package/package.json +1 -1
|
@@ -338,7 +338,7 @@ let ActivityRideService = (() => {
|
|
|
338
338
|
{ value: distanceRemaining === undefined ? undefined : `-${C(distanceRemaining, 'distance', { from: 'km' }).toFixed(2)}` }
|
|
339
339
|
]
|
|
340
340
|
});
|
|
341
|
-
const sport = this.activity
|
|
341
|
+
const sport = this.activity?.sport ?? 'cycling';
|
|
342
342
|
info.push({ title: 'Speed',
|
|
343
343
|
data: [
|
|
344
344
|
this.speedHandler[sport](speed),
|
|
@@ -353,7 +353,7 @@ let ActivityRideService = (() => {
|
|
|
353
353
|
info.push({ title: 'Slope', data: [{ value: (0, utils_1.formatNumber)(slope, 1), unit: '%', info: slopeInfo }, elevationGain] });
|
|
354
354
|
}
|
|
355
355
|
info.push({ title: 'Heartrate', data: [{ value: (0, utils_1.formatNumber)(heartrate, 0), unit: 'bpm' }, heartrateDetails], dataState: this.current.dataState?.heartrate });
|
|
356
|
-
const cadenceUnit = this.activity
|
|
356
|
+
const cadenceUnit = this.activity?.sport === 'rowing' ? 'spm' : 'rpm';
|
|
357
357
|
const cadenceInfo = { title: 'Cadence', data: [{ value: (0, utils_1.formatNumber)(cadence, 0), unit: cadenceUnit }, cadenceDetails], dataState: this.current.dataState?.cadence };
|
|
358
358
|
info.push(cadenceInfo);
|
|
359
359
|
if (gear) {
|
|
@@ -383,7 +383,7 @@ let ActivityRideService = (() => {
|
|
|
383
383
|
distanceRemaining = 0;
|
|
384
384
|
let timeRemaining;
|
|
385
385
|
if (speed > 0 && this.durationCalculator) {
|
|
386
|
-
timeRemaining = this.durationCalculator.getRemainingTime({ route: this.current.route, speed: this.current.deviceData?.speed, routePos: this.activity
|
|
386
|
+
timeRemaining = this.durationCalculator.getRemainingTime({ route: this.current.route, speed: this.current.deviceData?.speed, routePos: (this.activity?.distance ?? 0) + (this.activity?.startPos ?? 0), endPos: this.current?.endPos });
|
|
387
387
|
}
|
|
388
388
|
return { position, distance, routeDistance, time, speed, power, slope, heartrate, cadence, timeRemaining, distanceRemaining, lap, gear };
|
|
389
389
|
}
|
|
@@ -392,9 +392,9 @@ let ActivityRideService = (() => {
|
|
|
392
392
|
const [C, U] = this.getUnitConversionShortcuts();
|
|
393
393
|
const stats = this.activity?.stats;
|
|
394
394
|
const maxSpeed = stats?.speed?.max;
|
|
395
|
-
const sport = this.activity
|
|
395
|
+
const sport = this.activity?.sport ?? 'cycling';
|
|
396
396
|
const data = this.speedHandler[sport](maxSpeed);
|
|
397
|
-
const speedDetails = this.activity
|
|
397
|
+
const speedDetails = this.activity?.sport === 'cycling' ?
|
|
398
398
|
{ value: (0, utils_1.formatNumber)(C(maxSpeed, 'speed'), 1), label: 'max' } :
|
|
399
399
|
{ value: data.value, label: 'max' };
|
|
400
400
|
const powerDetails = { value: (0, utils_1.formatNumber)(stats?.power?.max, 0), label: 'max' };
|
|
@@ -413,9 +413,9 @@ let ActivityRideService = (() => {
|
|
|
413
413
|
const [C, U] = this.getUnitConversionShortcuts();
|
|
414
414
|
const stats = this.activity?.stats;
|
|
415
415
|
const avgSpeed = stats?.speed?.avg;
|
|
416
|
-
const sport = this.activity
|
|
416
|
+
const sport = this.activity?.sport ?? 'cycling';
|
|
417
417
|
const data = this.speedHandler[sport](avgSpeed);
|
|
418
|
-
const speedDetails = this.activity
|
|
418
|
+
const speedDetails = this.activity?.sport === 'cycling' ?
|
|
419
419
|
{ value: (0, utils_1.formatNumber)(C(avgSpeed, 'speed'), 1), label: 'avg' } :
|
|
420
420
|
{ value: data.value, label: 'max' };
|
|
421
421
|
const powerDetails = { value: (0, utils_1.formatNumber)(stats?.power?.avg, 0), label: 'avg' };
|
|
@@ -475,10 +475,10 @@ let ActivityRideService = (() => {
|
|
|
475
475
|
const workout = activity?.workout;
|
|
476
476
|
if (!workout)
|
|
477
477
|
return undefined;
|
|
478
|
-
const ftp = activity
|
|
478
|
+
const ftp = activity?.user?.ftp ?? 0;
|
|
479
479
|
const bars = (0, workouts_1.getWorkoutGraphSeries)(workout, { ftp, absValues: true });
|
|
480
480
|
const lastBarX = bars.length ? bars.at(-1).x : 0;
|
|
481
|
-
const lastLogTime = activity
|
|
481
|
+
const lastLogTime = activity?.logs?.length ? activity?.logs.at(-1).time : 0;
|
|
482
482
|
const maxXCandidates = [lastLogTime, lastBarX, workout.duration ?? 0].filter(Number.isFinite);
|
|
483
483
|
const maxX = maxXCandidates.length ? Math.max(...maxXCandidates) : 0;
|
|
484
484
|
const maxBarPower = bars.length ? Math.max(...bars.map(b => b.y)) : 0;
|
|
@@ -489,10 +489,10 @@ let ActivityRideService = (() => {
|
|
|
489
489
|
domain: { x: [0, maxX], y: [0, maxBarPower * 1.1] }
|
|
490
490
|
};
|
|
491
491
|
const actuals = {
|
|
492
|
-
power: (activity
|
|
492
|
+
power: (activity?.logs ?? [])
|
|
493
493
|
.filter(log => Number.isFinite(log.time) && Number.isFinite(log.power))
|
|
494
494
|
.map(log => ({ x: log.time, y: log.power })),
|
|
495
|
-
heartrate: (activity
|
|
495
|
+
heartrate: (activity?.logs ?? [])
|
|
496
496
|
.filter(log => Number.isFinite(log.time) && Number.isFinite(log.heartrate))
|
|
497
497
|
.map(log => ({ x: log.time, y: log.heartrate })),
|
|
498
498
|
position: -1
|
|
@@ -363,7 +363,8 @@ let DeviceAccessService = (() => {
|
|
|
363
363
|
const scanProps = info.properties || this.defaultProps;
|
|
364
364
|
const { scanTimeout, port, protocol } = scanProps;
|
|
365
365
|
const timeout = this.getScanTimeout(props.timeout, scanTimeout);
|
|
366
|
-
const
|
|
366
|
+
const otherTimeout = props.timeoutAllInterfaces && timeout ? timeout : scanTimeout;
|
|
367
|
+
const properties = ifaceName === 'tcpip' || ifaceName === 'serial' ? { timeout, port: port?.toString(), protocol } : { timeout: otherTimeout };
|
|
367
368
|
this.scanState.promises.push(i.scan(properties));
|
|
368
369
|
});
|
|
369
370
|
this.emitScanStateChange('started');
|
|
@@ -17,3 +17,5 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./app"), exports);
|
|
18
18
|
__exportStar(require("./repository"), exports);
|
|
19
19
|
__exportStar(require("./service"), exports);
|
|
20
|
+
__exportStar(require("./exclusion"), exports);
|
|
21
|
+
__exportStar(require("./add"), exports);
|
|
@@ -82,6 +82,8 @@ let DeviceConfigurationService = (() => {
|
|
|
82
82
|
settings = __runInitializers(this, _instanceExtraInitializers);
|
|
83
83
|
adapters = {};
|
|
84
84
|
features;
|
|
85
|
+
exclusions = [];
|
|
86
|
+
exclusionLeakLogged = false;
|
|
85
87
|
constructor() {
|
|
86
88
|
super('DeviceConfig');
|
|
87
89
|
this.features = {};
|
|
@@ -206,6 +208,8 @@ let DeviceConfigurationService = (() => {
|
|
|
206
208
|
const settings = this.settings.capabilities.find(c => c.capability === capability);
|
|
207
209
|
if (settings) {
|
|
208
210
|
settings.selected = null;
|
|
211
|
+
if (capability !== 'bike')
|
|
212
|
+
this.removeExclusions({ capability: capability });
|
|
209
213
|
this.updateUserSettings();
|
|
210
214
|
if (shouldEmit)
|
|
211
215
|
this.emitCapabiltyChanged(settings.capability);
|
|
@@ -238,6 +242,13 @@ let DeviceConfigurationService = (() => {
|
|
|
238
242
|
this.emitCapabiltyChanged(capability);
|
|
239
243
|
}
|
|
240
244
|
add(deviceSettings, props) {
|
|
245
|
+
const result = this.addDevice(deviceSettings, props);
|
|
246
|
+
if (result.udid)
|
|
247
|
+
props?.onAdded?.(result);
|
|
248
|
+
return result.udid;
|
|
249
|
+
}
|
|
250
|
+
addDevice(deviceSettings, props) {
|
|
251
|
+
const result = { newlyKnown: [], autoSelected: [] };
|
|
241
252
|
let udid = this.getUdid(deviceSettings);
|
|
242
253
|
udid ??= this.getUdidForWifiAddressChange(deviceSettings);
|
|
243
254
|
const { legacy = false } = props || {};
|
|
@@ -262,7 +273,7 @@ let DeviceConfigurationService = (() => {
|
|
|
262
273
|
adapter = this.getAdapterFromSetting(deviceSettings);
|
|
263
274
|
if (!adapter) {
|
|
264
275
|
this.logEvent({ message: 'could not create adapter' });
|
|
265
|
-
return;
|
|
276
|
+
return result;
|
|
266
277
|
}
|
|
267
278
|
udid = this.settings.devices?.find(d => adapter.isEqual(d.settings))?.udid ?? this.getUdidForWifiAddressChange(deviceSettings);
|
|
268
279
|
if (udid) {
|
|
@@ -279,21 +290,37 @@ let DeviceConfigurationService = (() => {
|
|
|
279
290
|
this.adapters[udid] = adapter;
|
|
280
291
|
}
|
|
281
292
|
this.initCapabilties();
|
|
293
|
+
if (adapter.hasCapability(incyclist_devices_1.IncyclistCapability.AppControl))
|
|
294
|
+
this.verifyCapabilityExists(incyclist_devices_1.IncyclistCapability.AppControl);
|
|
295
|
+
result.udid = udid;
|
|
282
296
|
this.settings.capabilities.forEach(c => {
|
|
283
|
-
|
|
284
|
-
return udid;
|
|
285
|
-
const isBike = adapter.hasCapability(incyclist_devices_1.IncyclistCapability.Control);
|
|
286
|
-
if (adapter.hasCapability(c.capability) && c.capability !== 'bike') {
|
|
287
|
-
if (!c.devices.includes(udid)) {
|
|
288
|
-
c.devices.push(udid);
|
|
289
|
-
}
|
|
290
|
-
if (!c.selected && !c.disabled && (isBike || c.capability === incyclist_devices_1.IncyclistCapability.HeartRate))
|
|
291
|
-
c.selected = udid;
|
|
292
|
-
}
|
|
297
|
+
this.addToCapabilityRecord(c, udid, adapter, result);
|
|
293
298
|
});
|
|
294
299
|
this.updateUserSettings();
|
|
295
300
|
this.emitCapabiltyChanged();
|
|
296
|
-
return
|
|
301
|
+
return result;
|
|
302
|
+
}
|
|
303
|
+
addToCapabilityRecord(c, udid, adapter, result) {
|
|
304
|
+
if (c.capability === 'bike')
|
|
305
|
+
return;
|
|
306
|
+
const capability = c.capability;
|
|
307
|
+
if (!adapter.hasCapability(capability))
|
|
308
|
+
return;
|
|
309
|
+
if (!c.devices.includes(udid)) {
|
|
310
|
+
c.devices.push(udid);
|
|
311
|
+
result.newlyKnown.push(capability);
|
|
312
|
+
}
|
|
313
|
+
if (c.selected || c.disabled)
|
|
314
|
+
return;
|
|
315
|
+
c.selected = udid;
|
|
316
|
+
result.autoSelected.push({ capability, rule: this.getAutoSelectRule(adapter, capability) });
|
|
317
|
+
}
|
|
318
|
+
getAutoSelectRule(adapter, capability) {
|
|
319
|
+
if (adapter.hasCapability(incyclist_devices_1.IncyclistCapability.Control))
|
|
320
|
+
return 'control';
|
|
321
|
+
if (capability === incyclist_devices_1.IncyclistCapability.HeartRate)
|
|
322
|
+
return 'heartrate';
|
|
323
|
+
return 'new-rule';
|
|
297
324
|
}
|
|
298
325
|
delete(udid, capability, forceSingle = false) {
|
|
299
326
|
const deviceSettings = this.settings.devices.find(d => d.udid === udid)?.settings;
|
|
@@ -307,6 +334,8 @@ let DeviceConfigurationService = (() => {
|
|
|
307
334
|
const deviceIdx = record.devices.findIndex(d => d === udid);
|
|
308
335
|
if (record.selected === udid) {
|
|
309
336
|
record.selected = undefined;
|
|
337
|
+
if (capability !== 'bike')
|
|
338
|
+
this.removeExclusions({ capability: capability });
|
|
310
339
|
const items = record.devices.length;
|
|
311
340
|
if (deviceIdx === items - 1 && items > 1) {
|
|
312
341
|
record.selected = record.devices[deviceIdx - 1];
|
|
@@ -398,9 +427,9 @@ let DeviceConfigurationService = (() => {
|
|
|
398
427
|
return;
|
|
399
428
|
try {
|
|
400
429
|
const udid = requestedUdid ||
|
|
401
|
-
capabilities.find(d => d.capability === incyclist_devices_1.IncyclistCapability.Control)?.selected ||
|
|
402
|
-
capabilities.find(d => d.capability === incyclist_devices_1.IncyclistCapability.Power)?.selected ||
|
|
403
|
-
capabilities.find(d => d.capability === incyclist_devices_1.IncyclistCapability.Speed)?.selected;
|
|
430
|
+
capabilities.find(d => d.capability === incyclist_devices_1.IncyclistCapability.Control && !d.disabled && !this.isExcluded(d.capability))?.selected ||
|
|
431
|
+
capabilities.find(d => d.capability === incyclist_devices_1.IncyclistCapability.Power && !d.disabled && !this.isExcluded(d.capability))?.selected ||
|
|
432
|
+
capabilities.find(d => d.capability === incyclist_devices_1.IncyclistCapability.Speed && !d.disabled && !this.isExcluded(d.capability))?.selected;
|
|
404
433
|
if (!udid)
|
|
405
434
|
return;
|
|
406
435
|
const device = devices.find(d => d.udid === udid);
|
|
@@ -489,7 +518,7 @@ let DeviceConfigurationService = (() => {
|
|
|
489
518
|
const { capabilities = [], devices = [] } = this.settings || {};
|
|
490
519
|
const adapters = [];
|
|
491
520
|
capabilities.forEach(c => {
|
|
492
|
-
if (c.disabled || !c.selected)
|
|
521
|
+
if (c.disabled || !c.selected || this.isExcluded(c.capability))
|
|
493
522
|
return;
|
|
494
523
|
if (!devices.some(d => d.udid === c.selected))
|
|
495
524
|
return;
|
|
@@ -526,7 +555,7 @@ let DeviceConfigurationService = (() => {
|
|
|
526
555
|
if (!capabilities)
|
|
527
556
|
return;
|
|
528
557
|
const found = capabilities.find(c => c.capability === capability);
|
|
529
|
-
if (!found || found.disabled || !found.selected)
|
|
558
|
+
if (!found || found.disabled || !found.selected || this.isExcluded(capability))
|
|
530
559
|
return;
|
|
531
560
|
const udid = found.selected;
|
|
532
561
|
return this.adapters[udid];
|
|
@@ -536,11 +565,67 @@ let DeviceConfigurationService = (() => {
|
|
|
536
565
|
if (capability) {
|
|
537
566
|
capabilites = this.settings?.capabilities.filter(c => c.capability === capability);
|
|
538
567
|
}
|
|
539
|
-
return capabilites.filter(c => c.capability !== 'bike' && c.disabled !== true && c.selected).map(c => {
|
|
568
|
+
return capabilites.filter(c => c.capability !== 'bike' && c.disabled !== true && c.selected && !this.isExcluded(c.capability)).map(c => {
|
|
540
569
|
const { capability, selected } = c;
|
|
541
570
|
return { capability: capability, selected };
|
|
542
571
|
});
|
|
543
572
|
}
|
|
573
|
+
excludeCapability(capability, opts) {
|
|
574
|
+
const udid = this.settings?.capabilities?.find(c => c.capability === capability)?.selected;
|
|
575
|
+
if (!udid)
|
|
576
|
+
return;
|
|
577
|
+
this.setExclusion(capability, udid, opts);
|
|
578
|
+
}
|
|
579
|
+
excludeDevice(udid, opts) {
|
|
580
|
+
const capabilities = (this.settings?.capabilities ?? []).filter(c => c.selected === udid);
|
|
581
|
+
capabilities.forEach(c => this.setExclusion(c.capability, udid, opts));
|
|
582
|
+
}
|
|
583
|
+
includeCapability(capability) {
|
|
584
|
+
const hadExclusion = this.exclusions.some(e => e.capability === capability);
|
|
585
|
+
this.exclusions = this.exclusions.filter(e => e.capability !== capability);
|
|
586
|
+
if (hadExclusion)
|
|
587
|
+
this.emitCapabiltyChanged(capability);
|
|
588
|
+
}
|
|
589
|
+
clearExclusions(filter) {
|
|
590
|
+
if (this.removeExclusions(filter))
|
|
591
|
+
this.emitCapabiltyChanged();
|
|
592
|
+
}
|
|
593
|
+
getExclusions() {
|
|
594
|
+
return [...this.exclusions];
|
|
595
|
+
}
|
|
596
|
+
getConfiguredSelection(capability) {
|
|
597
|
+
return this.settings?.capabilities?.find(c => c.capability === capability)?.selected;
|
|
598
|
+
}
|
|
599
|
+
isExcluded(capability) {
|
|
600
|
+
const setting = this.settings?.capabilities?.find(c => c.capability === capability);
|
|
601
|
+
return this.findExclusion(setting) !== undefined;
|
|
602
|
+
}
|
|
603
|
+
findExclusion(setting) {
|
|
604
|
+
if (!setting?.selected)
|
|
605
|
+
return undefined;
|
|
606
|
+
return this.exclusions.find(e => e.capability === setting.capability && e.udid === setting.selected);
|
|
607
|
+
}
|
|
608
|
+
setExclusion(capability, udid, opts) {
|
|
609
|
+
const { reason, scope, wasConnected = false } = opts;
|
|
610
|
+
this.removeExclusions({ capability });
|
|
611
|
+
this.exclusions.push({ capability, udid, reason, scope, wasConnected, since: Date.now() });
|
|
612
|
+
this.emitCapabiltyChanged(capability);
|
|
613
|
+
}
|
|
614
|
+
removeExclusions(filter) {
|
|
615
|
+
if (!filter) {
|
|
616
|
+
if (this.exclusions.length === 0)
|
|
617
|
+
return false;
|
|
618
|
+
this.exclusions = [];
|
|
619
|
+
return true;
|
|
620
|
+
}
|
|
621
|
+
const remaining = this.exclusions.filter(e => !((filter.capability === undefined || e.capability === filter.capability) &&
|
|
622
|
+
(filter.udid === undefined || e.udid === filter.udid) &&
|
|
623
|
+
(filter.scope === undefined || e.scope === filter.scope)));
|
|
624
|
+
if (remaining.length === this.exclusions.length)
|
|
625
|
+
return false;
|
|
626
|
+
this.exclusions = remaining;
|
|
627
|
+
return true;
|
|
628
|
+
}
|
|
544
629
|
initWifiInterface() {
|
|
545
630
|
const wifi = this.settings?.interfaces?.find(i => i.name === 'wifi');
|
|
546
631
|
if (!this.doesAppSupportsWifi()) {
|
|
@@ -621,10 +706,20 @@ let DeviceConfigurationService = (() => {
|
|
|
621
706
|
this.emitInterfaceChanged(ifName);
|
|
622
707
|
}
|
|
623
708
|
updateUserSettings() {
|
|
709
|
+
this.checkNoExclusionLeak();
|
|
624
710
|
this.getUserSettings().set('devices', this.settings.devices);
|
|
625
711
|
this.getUserSettings().set('capabilities', this.settings.capabilities);
|
|
626
712
|
this.getUserSettings().set('interfaces', this.settings.interfaces);
|
|
627
713
|
}
|
|
714
|
+
checkNoExclusionLeak() {
|
|
715
|
+
if (this.exclusionLeakLogged)
|
|
716
|
+
return;
|
|
717
|
+
const leaked = (this.settings?.capabilities ?? []).some(c => c.excluded !== undefined);
|
|
718
|
+
if (leaked) {
|
|
719
|
+
this.exclusionLeakLogged = true;
|
|
720
|
+
this.logEvent({ message: 'pairing exclusion leaked' });
|
|
721
|
+
}
|
|
722
|
+
}
|
|
628
723
|
isLegacyConfiguration() {
|
|
629
724
|
return this.getUserSettings().get('gearSelection', 'removed') !== 'removed' || this.getUserSettings().get('connections', 'removed') !== 'removed';
|
|
630
725
|
}
|
|
@@ -896,9 +991,11 @@ let DeviceConfigurationService = (() => {
|
|
|
896
991
|
const { capabilities = [], devices = [] } = this.settings;
|
|
897
992
|
const { adapters } = this;
|
|
898
993
|
const info = capabilities.map(c => {
|
|
994
|
+
const exclusion = this.findExclusion(c);
|
|
899
995
|
const ci = {
|
|
900
996
|
capability: c.capability,
|
|
901
997
|
disabled: c.disabled || false,
|
|
998
|
+
excluded: exclusion ? { reason: exclusion.reason, scope: exclusion.scope } : undefined,
|
|
902
999
|
devices: (c.devices ?? []).filter(udid => devices.find(d => d.udid === udid)).map(udid => {
|
|
903
1000
|
const adapter = adapters[udid];
|
|
904
1001
|
const device = devices.find(d => d.udid === udid);
|
|
@@ -935,6 +1032,8 @@ let DeviceConfigurationService = (() => {
|
|
|
935
1032
|
capSettings.selected = udid;
|
|
936
1033
|
if (capSettings.disabled)
|
|
937
1034
|
delete capSettings.disabled;
|
|
1035
|
+
if (capability !== 'bike')
|
|
1036
|
+
this.removeExclusions({ capability: capability });
|
|
938
1037
|
}
|
|
939
1038
|
deleteFromDeviceList(udid) {
|
|
940
1039
|
const { devices = [] } = this.settings || {};
|
|
@@ -999,6 +1098,8 @@ let DeviceConfigurationService = (() => {
|
|
|
999
1098
|
reset() {
|
|
1000
1099
|
super.reset();
|
|
1001
1100
|
this.settings = undefined;
|
|
1101
|
+
this.exclusions = [];
|
|
1102
|
+
this.exclusionLeakLogged = false;
|
|
1002
1103
|
}
|
|
1003
1104
|
getAdapterFromSetting(settings) {
|
|
1004
1105
|
return this.getAdapterFactory().create(settings);
|
|
@@ -40,6 +40,7 @@ const decorators_1 = require("../../../base/decorators");
|
|
|
40
40
|
const pages_1 = require("../../../base/pages");
|
|
41
41
|
const pairing_1 = require("../../pairing");
|
|
42
42
|
const logobserver_1 = require("./logobserver");
|
|
43
|
+
const incyclist_devices_1 = require("incyclist-devices");
|
|
43
44
|
const configuration_1 = require("../../configuration");
|
|
44
45
|
const visit_log_factory_1 = require("./visit-log-factory");
|
|
45
46
|
let PairingPageService = (() => {
|
|
@@ -107,6 +108,7 @@ let PairingPageService = (() => {
|
|
|
107
108
|
try {
|
|
108
109
|
this.logEvent({ message: 'page closed', page: 'Pairing' });
|
|
109
110
|
this.isVisitOpen = false;
|
|
111
|
+
this.setPairingVisitOpen(false);
|
|
110
112
|
gd_eventlog_1.EventLogger.setGlobalConfig('page', null);
|
|
111
113
|
this.isPairingForRide = false;
|
|
112
114
|
void this.stateMachine.stop();
|
|
@@ -159,32 +161,44 @@ let PairingPageService = (() => {
|
|
|
159
161
|
short: (0, pairing_1.getCapabilityHelpText)(capability, 'short') ?? '',
|
|
160
162
|
};
|
|
161
163
|
if (disabled) {
|
|
162
|
-
|
|
163
|
-
return {
|
|
164
|
-
title, capability,
|
|
165
|
-
deviceName: hasRememberedDevice ? deviceName : undefined,
|
|
166
|
-
disabled: true,
|
|
167
|
-
role, helpText,
|
|
168
|
-
emptyFooter: hasRememberedDevice ? 'Not used' : 'Not used · tap to search',
|
|
169
|
-
onClick,
|
|
170
|
-
onUse: hasRememberedDevice ? () => { this.onCapabilityUse(cap); } : undefined,
|
|
171
|
-
};
|
|
164
|
+
return this.getDisabledCapabilityDisplayProps(data, { title, capability, role, helpText, onClick });
|
|
172
165
|
}
|
|
173
166
|
const adapaters = this.state.adapters ?? [];
|
|
174
167
|
const adapter = adapaters.find(ai => data.selected && ai.udid === data.selected);
|
|
175
168
|
const ifName = adapter?.adapter?.getInterface();
|
|
176
169
|
const onUnselect = data.selected ? () => { this.onCapabilityUnselect(cap); } : undefined;
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
else if (role)
|
|
181
|
-
emptyFooter = (0, pairing_1.getEmptyTileFooterText)(role);
|
|
170
|
+
const emptyFooter = this.getActiveCapabilityEmptyFooter(cap, role, noSearch);
|
|
171
|
+
const found = Boolean(data.selected) && this.getSearchStatus()?.running === true && adapter?.adapter?.isStarted() !== true;
|
|
172
|
+
const stateText = found ? 'Found' : undefined;
|
|
182
173
|
return {
|
|
183
174
|
title, capability, deviceName, disabled: false, connectState, value: value?.toString(), unit, interface: ifName,
|
|
184
|
-
role, helpText, emptyFooter,
|
|
175
|
+
role, helpText, emptyFooter, stateText,
|
|
185
176
|
onClick, onUnselect
|
|
186
177
|
};
|
|
187
178
|
}
|
|
179
|
+
getDisabledCapabilityDisplayProps(data, common) {
|
|
180
|
+
const { capability: cap, deviceName } = data;
|
|
181
|
+
const { title, capability, role, helpText, onClick } = common;
|
|
182
|
+
const hasRememberedDevice = Boolean(deviceName);
|
|
183
|
+
return {
|
|
184
|
+
title, capability,
|
|
185
|
+
deviceName: hasRememberedDevice ? deviceName : undefined,
|
|
186
|
+
disabled: true,
|
|
187
|
+
role, helpText,
|
|
188
|
+
emptyFooter: hasRememberedDevice ? 'Not used' : 'Not used · tap to search',
|
|
189
|
+
onClick,
|
|
190
|
+
onUse: hasRememberedDevice ? () => { this.onCapabilityUse(cap); } : undefined,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
getActiveCapabilityEmptyFooter(cap, role, noSearch) {
|
|
194
|
+
if (noSearch)
|
|
195
|
+
return 'Not searching';
|
|
196
|
+
if (role === 'required' && this.getSearchStatus()?.ended)
|
|
197
|
+
return cap === incyclist_devices_1.IncyclistCapability.Control && this.canStartRide() ? 'Not found · tap to search' : 'Not found';
|
|
198
|
+
if (role)
|
|
199
|
+
return (0, pairing_1.getEmptyTileFooterText)(role);
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
188
202
|
getDeviceListDisplayProps() {
|
|
189
203
|
if (!this.openedCapability)
|
|
190
204
|
return;
|
|
@@ -259,16 +273,30 @@ let PairingPageService = (() => {
|
|
|
259
273
|
.catch(err => { this.logError(err, 'closeDeviceSelection'); });
|
|
260
274
|
this.updatePage();
|
|
261
275
|
}
|
|
262
|
-
getButtonsDisplayProps() {
|
|
276
|
+
getButtonsDisplayProps(noSearch = false) {
|
|
263
277
|
const labelOK = this.isPairingForRide ? 'Start' : 'OK';
|
|
264
278
|
const labelSkip = this.isPairingForRide ? 'Cancel' : 'Skip';
|
|
265
|
-
|
|
279
|
+
const search = this.getSearchStatus();
|
|
280
|
+
const skip = (primary) => ({ label: labelSkip, primary, onClick: this.onSkip.bind(this) });
|
|
281
|
+
const searchAgain = (primary) => ({ label: 'Search again', primary, onClick: this.onSearchAgain.bind(this) });
|
|
282
|
+
if (search?.running && search.canStop)
|
|
266
283
|
return [
|
|
267
|
-
{ label:
|
|
284
|
+
{ label: 'Stop searching', primary: true, onClick: this.onStopSearch.bind(this) },
|
|
285
|
+
skip(false)
|
|
268
286
|
];
|
|
287
|
+
const offerSearchAgain = !noSearch && search?.canSearchAgain === true;
|
|
288
|
+
if (this.canStartRide()) {
|
|
289
|
+
const ok = { label: labelOK, primary: true, onClick: this.onOK.bind(this) };
|
|
290
|
+
return offerSearchAgain ? [ok, searchAgain(false)] : [ok];
|
|
291
|
+
}
|
|
292
|
+
const nothingFound = offerSearchAgain && !search?.rideCapableFound;
|
|
269
293
|
if (!this.isPairingForRide)
|
|
294
|
+
return nothingFound ? [searchAgain(true), skip(false)] : [skip(true)];
|
|
295
|
+
if (nothingFound)
|
|
270
296
|
return [
|
|
271
|
-
|
|
297
|
+
searchAgain(true),
|
|
298
|
+
{ label: 'Simulate', primary: false, onClick: this.onSimulate.bind(this) },
|
|
299
|
+
skip(false)
|
|
272
300
|
];
|
|
273
301
|
return [
|
|
274
302
|
{ label: 'Simulate', primary: true, onClick: this.onSimulate.bind(this) },
|
|
@@ -306,6 +334,7 @@ let PairingPageService = (() => {
|
|
|
306
334
|
}
|
|
307
335
|
}
|
|
308
336
|
openVisit() {
|
|
337
|
+
this.setPairingVisitOpen(true);
|
|
309
338
|
if (this.isVisitOpen)
|
|
310
339
|
return;
|
|
311
340
|
this.trackVisit(t => t.openVisit({ forRide: this.isPairingForRide }), 'openVisit');
|
|
@@ -314,10 +343,57 @@ let PairingPageService = (() => {
|
|
|
314
343
|
closeVisit(via) {
|
|
315
344
|
this.trackVisit(t => t.closeVisit(via, { canStartRide: this.canStartRide() }), 'closeVisit');
|
|
316
345
|
this.isVisitOpen = false;
|
|
346
|
+
this.setPairingVisitOpen(false);
|
|
347
|
+
}
|
|
348
|
+
setPairingVisitOpen(open) {
|
|
349
|
+
try {
|
|
350
|
+
this.getDevicePairing().setVisitOpen(open);
|
|
351
|
+
}
|
|
352
|
+
catch (err) {
|
|
353
|
+
this.logError(err, 'setPairingVisitOpen');
|
|
354
|
+
}
|
|
317
355
|
}
|
|
318
356
|
canStartRide() {
|
|
357
|
+
if (this.getSearchStatus()?.running)
|
|
358
|
+
return false;
|
|
319
359
|
return this.state?.canStartRide ?? false;
|
|
320
360
|
}
|
|
361
|
+
getSearchStatus() {
|
|
362
|
+
try {
|
|
363
|
+
return this.getDevicePairing().getSearchStatus?.();
|
|
364
|
+
}
|
|
365
|
+
catch (err) {
|
|
366
|
+
this.logError(err, 'getSearchStatus');
|
|
367
|
+
return undefined;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
isSearchEndedWithNothing() {
|
|
371
|
+
const search = this.getSearchStatus();
|
|
372
|
+
return search?.ended === true && !search.rideCapableFound;
|
|
373
|
+
}
|
|
374
|
+
isStillLooking() {
|
|
375
|
+
const search = this.getSearchStatus();
|
|
376
|
+
return search?.running === true && search.canStop;
|
|
377
|
+
}
|
|
378
|
+
getSearchStatusSource() {
|
|
379
|
+
const search = this.getSearchStatus();
|
|
380
|
+
return {
|
|
381
|
+
searchEndedWithNothing: this.isSearchEndedWithNothing(),
|
|
382
|
+
stillLooking: this.isStillLooking(),
|
|
383
|
+
missing: search?.missing ?? [],
|
|
384
|
+
searchEndedWithoutTrainer: search?.ended === true && !search.trainerFound,
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
onStopSearch() {
|
|
388
|
+
this.logEvent({ message: 'stop searching clicked', eventSource: 'user' });
|
|
389
|
+
this.getDevicePairing().stopSearch();
|
|
390
|
+
this.updatePage();
|
|
391
|
+
}
|
|
392
|
+
onSearchAgain() {
|
|
393
|
+
this.logEvent({ message: 'search again clicked', eventSource: 'user' });
|
|
394
|
+
this.getDevicePairing().searchAgain();
|
|
395
|
+
this.updatePage();
|
|
396
|
+
}
|
|
321
397
|
onSkip() {
|
|
322
398
|
this.closeVisit('skip');
|
|
323
399
|
const nextPage = this.getAppState().getPersistedState('page') ?? 'routes';
|
|
@@ -88,6 +88,7 @@ let DesktopPairingPageService = (() => {
|
|
|
88
88
|
canStartRide: this.canStartRide(),
|
|
89
89
|
loading: this.promiseOpen !== undefined,
|
|
90
90
|
rideMode: this.isPairingForRide,
|
|
91
|
+
...this.getSearchStatusSource(),
|
|
91
92
|
});
|
|
92
93
|
const capProps = caps.map(c => this.getCapabilityDisplayProps(c, status.id === 'S1'));
|
|
93
94
|
const CP = (cap) => capProps.find(c => c.capability === cap);
|
|
@@ -101,12 +102,12 @@ let DesktopPairingPageService = (() => {
|
|
|
101
102
|
CP(incyclist_devices_1.IncyclistCapability.Cadence),
|
|
102
103
|
CP(incyclist_devices_1.IncyclistCapability.AppControl)
|
|
103
104
|
].filter(c => c !== null && c !== undefined);
|
|
104
|
-
const trainerSelected =
|
|
105
|
+
const trainerSelected = (0, pairing_1.isCapabilityActive)(caps.find(c => c.capability === incyclist_devices_1.IncyclistCapability.Control));
|
|
105
106
|
const rowLabels = {
|
|
106
|
-
top: (0, pairing_1.getPairingGuidanceText)((0, pairing_1.getPairingRowLabelId)(trainerSelected)),
|
|
107
|
+
top: (0, pairing_1.getPairingGuidanceText)((0, pairing_1.getPairingRowLabelId)(trainerSelected, this.isStillLooking())),
|
|
107
108
|
bottom: (0, pairing_1.getPairingGuidanceText)('row-optional'),
|
|
108
109
|
};
|
|
109
|
-
const buttons = this.getButtonsDisplayProps();
|
|
110
|
+
const buttons = this.getButtonsDisplayProps(status.id === 'S1');
|
|
110
111
|
return {
|
|
111
112
|
title,
|
|
112
113
|
readyToStart: this.canStartRide(),
|
|
@@ -98,6 +98,7 @@ let MobilePairingPageService = (() => {
|
|
|
98
98
|
canStartRide: this.canStartRide(),
|
|
99
99
|
loading,
|
|
100
100
|
rideMode: this.isPairingForRide,
|
|
101
|
+
...this.getSearchStatusSource(),
|
|
101
102
|
});
|
|
102
103
|
const capProps = caps.map(c => this.getCapabilityDisplayProps(c, status.id === 'S1'));
|
|
103
104
|
const CP = (cap) => capProps.find(c => c.capability === cap);
|
|
@@ -111,12 +112,12 @@ let MobilePairingPageService = (() => {
|
|
|
111
112
|
CP('cadence'),
|
|
112
113
|
CP('app_control')
|
|
113
114
|
].filter(c => c !== null && c !== undefined);
|
|
114
|
-
const trainerSelected =
|
|
115
|
+
const trainerSelected = (0, pairing_1.isCapabilityActive)(caps.find(c => c.capability === incyclist_devices_1.IncyclistCapability.Control));
|
|
115
116
|
const rowLabels = {
|
|
116
|
-
top: (0, pairing_1.getPairingGuidanceText)((0, pairing_1.getPairingRowLabelId)(trainerSelected)),
|
|
117
|
+
top: (0, pairing_1.getPairingGuidanceText)((0, pairing_1.getPairingRowLabelId)(trainerSelected, this.isStillLooking())),
|
|
117
118
|
bottom: (0, pairing_1.getPairingGuidanceText)('row-optional'),
|
|
118
119
|
};
|
|
119
|
-
const buttons = this.getButtonsDisplayProps();
|
|
120
|
+
const buttons = this.getButtonsDisplayProps(status.id === 'S1');
|
|
120
121
|
return {
|
|
121
122
|
title,
|
|
122
123
|
readyToStart: this.canStartRide(),
|
|
@@ -146,6 +146,13 @@ let PairingPageStateMachine = (() => {
|
|
|
146
146
|
this.registerHandler('scanning-start', this.onScanningStarted.bind(this));
|
|
147
147
|
this.registerHandler('scanning-done', this.onScanningFinished.bind(this));
|
|
148
148
|
this.registerHandler('retry', this.onRetry.bind(this));
|
|
149
|
+
this.registerHandler('search-again', this.onSearchAgain.bind(this));
|
|
150
|
+
}
|
|
151
|
+
onSearchAgain() {
|
|
152
|
+
if (this.state === 'Idle' || this.state === 'Done') {
|
|
153
|
+
this.resetTimeouts();
|
|
154
|
+
this.performCheck();
|
|
155
|
+
}
|
|
149
156
|
}
|
|
150
157
|
unregisterServiceEventHandlers() {
|
|
151
158
|
const service = this.getDevicePairing();
|
|
@@ -194,28 +201,14 @@ let PairingPageStateMachine = (() => {
|
|
|
194
201
|
const service = this.getDevicePairing();
|
|
195
202
|
const hasDevices = configuration.canStartRide();
|
|
196
203
|
const adapters = configuration.getAdapters(false);
|
|
204
|
+
const searchPending = this.selectState === 'Closed' && service.isSearchPending?.() === true;
|
|
205
|
+
const searchEnded = this.selectState === 'Closed' && service.isSearchAllowed?.() === false;
|
|
197
206
|
this.logger.logEvent({ message: 'check next action', hasDevices });
|
|
198
|
-
if (hasDevices && this.selectState === 'Closed') {
|
|
199
|
-
|
|
200
|
-
if (pairingDone) {
|
|
201
|
-
service.prepareForRide();
|
|
202
|
-
this.resetTimeouts();
|
|
203
|
-
this.setState('Done');
|
|
204
|
-
}
|
|
205
|
-
else if (!this.pairingPromise) {
|
|
206
|
-
this.setState('Pairing');
|
|
207
|
-
this.pairingPromise = Promise.resolve(service.startPairing(adapters, {}))
|
|
208
|
-
.catch(err => { this.logError(err, 'startPairing'); })
|
|
209
|
-
.finally(() => { delete this.pairingPromise; });
|
|
210
|
-
}
|
|
207
|
+
if (hasDevices && this.selectState === 'Closed' && !searchPending) {
|
|
208
|
+
this.checkPairingProgress(service, adapters);
|
|
211
209
|
}
|
|
212
|
-
else if (this.selectState === 'Closed' || this.selectState === 'Active') {
|
|
213
|
-
|
|
214
|
-
this.setState('Scanning');
|
|
215
|
-
this.scanningPromise = Promise.resolve(service.startScanning(adapters, {}))
|
|
216
|
-
.catch(err => { this.logError(err, 'startScanning'); })
|
|
217
|
-
.finally(() => { delete this.scanningPromise; });
|
|
218
|
-
}
|
|
210
|
+
else if ((this.selectState === 'Closed' && !searchEnded) || this.selectState === 'Active') {
|
|
211
|
+
this.checkScanningProgress(service, adapters);
|
|
219
212
|
}
|
|
220
213
|
if (this.state !== oldState)
|
|
221
214
|
this.logger.logEvent({ message: 'state changed', stateTransition: { from: oldState, to: this.state } });
|
|
@@ -224,6 +217,29 @@ let PairingPageStateMachine = (() => {
|
|
|
224
217
|
this.logError(err, 'performCheck');
|
|
225
218
|
}
|
|
226
219
|
}
|
|
220
|
+
checkPairingProgress(service, adapters) {
|
|
221
|
+
const pairingDone = service.isPairingSettled();
|
|
222
|
+
if (pairingDone) {
|
|
223
|
+
service.prepareForRide();
|
|
224
|
+
this.resetTimeouts();
|
|
225
|
+
this.setState('Done');
|
|
226
|
+
}
|
|
227
|
+
else if (!this.pairingPromise) {
|
|
228
|
+
this.setState('Pairing');
|
|
229
|
+
this.pairingPromise = Promise.resolve(service.startPairing(adapters, {}))
|
|
230
|
+
.catch(err => { this.logError(err, 'startPairing'); })
|
|
231
|
+
.finally(() => { delete this.pairingPromise; });
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
checkScanningProgress(service, adapters) {
|
|
235
|
+
if (!this.scanningPromise) {
|
|
236
|
+
this.setState('Scanning');
|
|
237
|
+
const props = this.selectState === 'Active' ? { deviceList: true } : {};
|
|
238
|
+
this.scanningPromise = Promise.resolve(service.startScanning(adapters, props))
|
|
239
|
+
.catch(err => { this.logError(err, 'startScanning'); })
|
|
240
|
+
.finally(() => { delete this.scanningPromise; });
|
|
241
|
+
}
|
|
242
|
+
}
|
|
227
243
|
onPairingStarted() {
|
|
228
244
|
if (this.state !== 'Pairing') {
|
|
229
245
|
this.logError(new Error('Illegal state'), 'onPairingStarted');
|