incyclist-services 1.9.15 → 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/README.MD +117 -15
- 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/cjs/routes/list/cards/RouteCard.js +28 -2
- package/lib/cjs/routes/list/loaders/db.js +2 -1
- package/lib/cjs/routes/list/service.js +23 -0
- 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/esm/routes/list/cards/RouteCard.js +28 -2
- package/lib/esm/routes/list/loaders/db.js +2 -1
- package/lib/esm/routes/list/service.js +23 -0
- 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/lib/types/routes/list/cards/RouteCard.d.ts +3 -0
- package/lib/types/routes/list/service.d.ts +2 -0
- package/package.json +4 -4
package/README.MD
CHANGED
|
@@ -1,29 +1,131 @@
|
|
|
1
1
|
# incyclist-services
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
This repository contains the business logic of the [Incyclist](https://incyclist.com)
|
|
4
|
+
indoor cycling app, published on npm as
|
|
5
|
+
[`incyclist-services`](https://www.npmjs.com/package/incyclist-services).
|
|
4
6
|
|
|
5
|
-
Incyclist
|
|
7
|
+
Incyclist separates its user interfaces from its business logic. The front-ends,
|
|
8
|
+
[`web-ui`](https://github.com/incyclist/web-ui) (React, used by the desktop app) and the
|
|
9
|
+
mobile app (React Native), decide *how* things are rendered. This library decides *what* is
|
|
10
|
+
rendered: device pairing, rides, workouts, routes, activities, settings, third-party app
|
|
11
|
+
connections, and so on. A front-end should not contain business logic. If you're changing
|
|
12
|
+
behaviour, this is usually the right repo.
|
|
6
13
|
|
|
7
|
-
|
|
14
|
+
```
|
|
15
|
+
incyclist-devices ──► incyclist-services ──► web-ui ──► desktop app (Electron)
|
|
16
|
+
(trainers, sensors) (this repo) └─► mobile app (React Native)
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Getting started
|
|
20
|
+
|
|
21
|
+
**Prerequisites:** Node.js 24 or newer (CI tests against 24.x and 25.x) and npm.
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
git clone https://github.com/incyclist/services.git
|
|
25
|
+
cd services
|
|
26
|
+
npm install
|
|
27
|
+
npm run build
|
|
28
|
+
npm test
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
If the build and the unit tests pass, you're set up. You don't need any devices, accounts or
|
|
32
|
+
credentials to work on this repo: unit tests mock everything external.
|
|
33
|
+
|
|
34
|
+
## Available scripts
|
|
35
|
+
|
|
36
|
+
| Script | Purpose |
|
|
37
|
+
|---|---|
|
|
38
|
+
| `npm run build` | Build ESM (`lib/esm`) and CJS (`lib/cjs`) output |
|
|
39
|
+
| `npm run dev` | Watch mode: rebuilds `lib/esm` on every change (see below) |
|
|
40
|
+
| `npm test` | Run the unit tests. Scope to a file or folder with `npm test -- <path>` |
|
|
41
|
+
| `npm run coverage` | Unit tests with a coverage report |
|
|
42
|
+
| `npm run lint` | ESLint |
|
|
43
|
+
| `npm run typecheck` | TypeScript type check (`tsc --noEmit`), including test files |
|
|
44
|
+
| `npm run test:e2e` | E2E tests against real backends. Maintainers only, see below |
|
|
45
|
+
|
|
46
|
+
Don't run bare `npx jest` or `npm run test:all`: both include the E2E tests.
|
|
47
|
+
|
|
48
|
+
### About E2E tests
|
|
49
|
+
|
|
50
|
+
Files named `*.e2e.test.ts` talk to real services (Incyclist backend, Strava, Komoot,
|
|
51
|
+
intervals.icu, VeloHero, ...). They need credentials in a local `.env` file and can create or
|
|
52
|
+
change real data. Contributors don't need them. CI runs the unit tests, lint and type check
|
|
53
|
+
only.
|
|
8
54
|
|
|
55
|
+
## Working on services together with a front-end
|
|
56
|
+
|
|
57
|
+
To see your changes in the running app, clone [`web-ui`](https://github.com/incyclist/web-ui)
|
|
58
|
+
and [`devices`](https://github.com/incyclist/devices) next to this repo:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
<your-folder>
|
|
62
|
+
├── services (this repo)
|
|
63
|
+
├── devices
|
|
64
|
+
└── web-ui
|
|
9
65
|
```
|
|
10
|
-
import {useXXX, initXXX} from {incyclist-devices}
|
|
11
66
|
|
|
67
|
+
In dev mode, `web-ui` loads both `incyclist-services` and `incyclist-devices` from these
|
|
68
|
+
sibling folders (`../services/lib/esm`, `../devices/lib/esm`) instead of `node_modules`. So:
|
|
69
|
+
|
|
70
|
+
1. Run `npm install` and `npm run build` once in `devices` and in `services`.
|
|
71
|
+
`lib/esm` must exist in both.
|
|
72
|
+
2. Run `npm run dev` here. It rebuilds on every change.
|
|
73
|
+
3. Run `npm run dev` in `web-ui`. Every change you save here now shows up in the UI.
|
|
74
|
+
|
|
75
|
+
See the [web-ui README](https://github.com/incyclist/web-ui#readme) for how to point the
|
|
76
|
+
desktop app at your local UI.
|
|
77
|
+
|
|
78
|
+
## Project structure
|
|
79
|
+
|
|
80
|
+
Each folder under `src/` is a domain module with its own `index.ts`, `types.ts`, service
|
|
81
|
+
classes and colocated `*.unit.test.ts` files.
|
|
82
|
+
|
|
83
|
+
| Module | What it covers |
|
|
84
|
+
|---|---|
|
|
85
|
+
| `activities` | Recording, saving, listing and uploading completed rides |
|
|
86
|
+
| `api` | Platform bindings (file system, settings, BLE/ANT+/serial, MQTT, ...) and REST helpers |
|
|
87
|
+
| `apps` | Connected third-party apps: Strava, intervals.icu, Komoot, ... |
|
|
88
|
+
| `appstate` | App state and feature toggles |
|
|
89
|
+
| `autoupdate` | UI bundle update checks |
|
|
90
|
+
| `avatars` | Rider avatars |
|
|
91
|
+
| `base` | Base classes and decorators shared by all services |
|
|
92
|
+
| `coaches` | Virtual riders to ride against |
|
|
93
|
+
| `devices` | Device configuration, access, pairing and in-ride device handling |
|
|
94
|
+
| `fileaccess` | Loading local and external files |
|
|
95
|
+
| `i18n` | Localization, countries, units |
|
|
96
|
+
| `maps`, `services` | Map areas and OpenStreetMap (Overpass) queries |
|
|
97
|
+
| `monitoring` | Online/offline status |
|
|
98
|
+
| `ride` | The live ride: display, controls, route/workout/video ride modes |
|
|
99
|
+
| `routes` | Route list, parsing, download and import |
|
|
100
|
+
| `settings` | User settings |
|
|
101
|
+
| `ui` | UI-facing helpers |
|
|
102
|
+
| `video` | Video handling for video routes |
|
|
103
|
+
| `workouts` | Workout list, import, parsing and execution |
|
|
104
|
+
|
|
105
|
+
Everything consumers may use is exported from `src/index.ts`:
|
|
106
|
+
|
|
107
|
+
```ts
|
|
108
|
+
import { useDeviceConfiguration, initUserSettings } from 'incyclist-services'
|
|
12
109
|
```
|
|
13
110
|
|
|
14
|
-
|
|
15
|
-
|
|
111
|
+
`useXXX()` returns a service singleton, and `initXXX()` initializes one where needed.
|
|
112
|
+
|
|
113
|
+
## Using this library in your own app
|
|
114
|
+
|
|
115
|
+
The library never calls platform APIs directly. File access, settings storage, secrets,
|
|
116
|
+
Bluetooth, ANT+ and so on all go through bindings (`src/api/bindings/`) that the host app
|
|
117
|
+
must provide at startup. A fork or a new front-end has to supply its own implementations.
|
|
118
|
+
The existing front-ends (`web-ui` for browser/Electron, the mobile app for React Native)
|
|
119
|
+
are the reference for how this is done.
|
|
16
120
|
|
|
17
|
-
|
|
121
|
+
## Contributing
|
|
18
122
|
|
|
19
|
-
|
|
123
|
+
Contributions are welcome. Please read:
|
|
20
124
|
|
|
21
|
-
|
|
22
|
-
- [
|
|
125
|
+
- [CONTRIBUTING.md](./CONTRIBUTING.md): workflow, branches, pull requests
|
|
126
|
+
- [docs/CODEBASE_GUIDE.md](./docs/CODEBASE_GUIDE.md): architecture, coding style and testing
|
|
127
|
+
conventions. Please read this before writing code.
|
|
23
128
|
|
|
129
|
+
## License
|
|
24
130
|
|
|
25
|
-
|
|
26
|
-
- [DeviceConfiguration](./doc/classes/DeviceConfigurationService.md): manages the user configuration of scanned/added/selected devices
|
|
27
|
-
- [DeviceAccess](./doc/classes/DeviceAccessService.md): manages the basic communication to the device (setting up interfacs, scanning,... )
|
|
28
|
-
- [Device](./src/devices/device/README.MD): allows the Front-End to communicate with a device (reading, writing data)
|
|
29
|
-
- [DevicePairing](./doc/classes/DevicePairingService.md): implements the business logic og the DevicePairing screens
|
|
131
|
+
[MIT](./LICENSE)
|
|
@@ -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);
|