incyclist-services 1.8.9 → 1.9.1
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/types.js +1 -0
- package/lib/cjs/apps/service.js +2 -2
- package/lib/cjs/base/pages/service.js +6 -8
- package/lib/cjs/devices/configuration/service.js +4 -0
- package/lib/cjs/devices/page/base/logobserver.js +19 -0
- package/lib/cjs/devices/page/base/orchestrator.js +2 -0
- package/lib/cjs/devices/page/base/service.js +383 -0
- package/lib/cjs/devices/page/base/types.js +2 -0
- package/lib/cjs/devices/page/base/visit-log-factory.js +41 -0
- package/lib/cjs/devices/page/base/visit-log.js +143 -0
- package/lib/cjs/devices/page/desktop/matrix.js +26 -0
- package/lib/cjs/devices/page/desktop/orchestrator.js +21 -0
- package/lib/cjs/devices/page/desktop/service.js +253 -0
- package/lib/cjs/devices/page/desktop/types.js +2 -0
- package/lib/cjs/devices/page/index.js +13 -18
- package/lib/cjs/devices/page/mobile/orchestrator.js +6 -0
- package/lib/cjs/devices/page/mobile/service.js +197 -0
- package/lib/cjs/devices/page/mobile/statemachine.js +348 -0
- package/lib/cjs/devices/pairing/guidance.js +9 -5
- package/lib/cjs/devices/pairing/service.js +54 -1
- package/lib/cjs/devices/ride/service.js +1 -22
- package/lib/cjs/ride/display/service.js +21 -11
- package/lib/cjs/ride/route/GpxDisplayService.js +3 -0
- package/lib/cjs/ui/service.js +20 -17
- package/lib/cjs/workouts/ride/service.js +8 -8
- package/lib/esm/activities/types.js +1 -0
- package/lib/esm/apps/service.js +1 -1
- package/lib/esm/base/pages/service.js +6 -8
- package/lib/esm/devices/configuration/service.js +4 -0
- package/lib/esm/devices/page/__tests__/desktop-matrix.js +23 -0
- package/lib/esm/devices/page/base/logobserver.js +15 -0
- package/lib/esm/devices/page/base/orchestrator.js +1 -0
- package/lib/esm/devices/page/base/service.js +380 -0
- package/lib/esm/devices/page/base/types.js +1 -0
- package/lib/esm/devices/page/base/visit-log-factory.js +33 -0
- package/lib/esm/devices/page/base/visit-log.js +138 -0
- package/lib/esm/devices/page/desktop/matrix.js +23 -0
- package/lib/esm/devices/page/desktop/orchestrator.js +17 -0
- package/lib/esm/devices/page/desktop/service.js +250 -0
- package/lib/esm/devices/page/desktop/types.js +1 -0
- package/lib/esm/devices/page/desktop-service.js +204 -0
- package/lib/esm/devices/page/index.js +11 -3
- package/lib/esm/devices/page/mobile/orchestrator.js +2 -0
- package/lib/esm/devices/page/mobile/service.js +194 -0
- package/lib/esm/devices/page/mobile/statemachine.js +345 -0
- package/lib/esm/devices/page/orchestrator.js +19 -0
- package/lib/esm/devices/page/pairing-page-service.js +385 -0
- package/lib/esm/devices/pairing/guidance.js +9 -5
- package/lib/esm/devices/pairing/service.js +54 -1
- package/lib/esm/devices/ride/service.js +1 -22
- package/lib/esm/ride/display/service.js +13 -3
- package/lib/esm/ride/route/GpxDisplayService.js +3 -0
- package/lib/esm/ui/service.js +4 -1
- package/lib/esm/workouts/ride/service.js +1 -1
- package/lib/types/activities/types.d.ts +1 -0
- package/lib/types/api/ui/index.d.ts +1 -1
- package/lib/types/apps/service.d.ts +1 -1
- package/lib/types/base/pages/service.d.ts +1 -1
- package/lib/types/devices/page/__tests__/desktop-matrix.d.ts +8 -0
- package/lib/types/devices/page/base/logobserver.d.ts +8 -0
- package/lib/types/devices/page/base/orchestrator.d.ts +11 -0
- package/lib/types/devices/page/base/service.d.ts +54 -0
- package/lib/types/devices/page/base/types.d.ts +130 -0
- package/lib/types/devices/page/base/visit-log-factory.d.ts +13 -0
- package/lib/types/devices/page/base/visit-log.d.ts +25 -0
- package/lib/types/devices/page/desktop/matrix.d.ts +8 -0
- package/lib/types/devices/page/desktop/orchestrator.d.ts +2 -0
- package/lib/types/devices/page/desktop/service.d.ts +32 -0
- package/lib/types/devices/page/desktop/types.d.ts +25 -0
- package/lib/types/devices/page/desktop-service.d.ts +28 -0
- package/lib/types/devices/page/index.d.ts +5 -3
- package/lib/types/devices/page/mobile/orchestrator.d.ts +2 -0
- package/lib/types/devices/page/mobile/service.d.ts +24 -0
- package/lib/types/devices/page/mobile/statemachine.d.ts +49 -0
- package/lib/types/devices/page/orchestrator.d.ts +13 -0
- package/lib/types/devices/page/pairing-page-service.d.ts +53 -0
- package/lib/types/devices/page/types.d.ts +2 -129
- package/lib/types/devices/pairing/service.d.ts +8 -0
- package/lib/types/devices/ride/service.d.ts +0 -1
- package/lib/types/ride/base/base.d.ts +1 -2
- package/lib/types/ride/base/types.d.ts +1 -0
- package/lib/types/ride/display/service.d.ts +8 -6
- package/lib/types/routes/list/cards/RouteCard.d.ts +1 -1
- package/lib/types/workouts/ride/service.d.ts +1 -1
- package/package.json +1 -1
|
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./ride/types"), exports);
|
|
18
18
|
__exportStar(require("./page/types"), exports);
|
|
19
|
+
__exportStar(require("./base/model/index"), exports);
|
package/lib/cjs/apps/service.js
CHANGED
|
@@ -35,7 +35,7 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
|
|
|
35
35
|
};
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
37
|
exports.useAppsService = exports.AppsService = void 0;
|
|
38
|
-
const
|
|
38
|
+
const upload_1 = require("../activities/upload");
|
|
39
39
|
const decorators_1 = require("../base/decorators");
|
|
40
40
|
const service_1 = require("../base/service");
|
|
41
41
|
const types_1 = require("../base/types");
|
|
@@ -181,7 +181,7 @@ let AppsService = (() => {
|
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
getActivityUploadFactory() {
|
|
184
|
-
return new
|
|
184
|
+
return new upload_1.ActivityUploadFactory();
|
|
185
185
|
}
|
|
186
186
|
getUserSettings() {
|
|
187
187
|
return (0, settings_1.useUserSettings)();
|
|
@@ -101,14 +101,12 @@ let IncyclistPageService = (() => {
|
|
|
101
101
|
const contentPage = this.getAppState().getPersistedState('page');
|
|
102
102
|
return contentPage ?? 'routes';
|
|
103
103
|
}
|
|
104
|
-
moveTo(route, close = true) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
this.getUIBinding().openPage(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
this.getUIBinding().openPage(route);
|
|
111
|
-
}
|
|
104
|
+
moveTo(route, close = true, state) {
|
|
105
|
+
const target = route === '$contentPage' ? this.getPrevContentPage() : route;
|
|
106
|
+
if (state !== undefined)
|
|
107
|
+
this.getUIBinding().openPage(target, state);
|
|
108
|
+
else
|
|
109
|
+
this.getUIBinding().openPage(target);
|
|
112
110
|
if (close) {
|
|
113
111
|
this.closePage();
|
|
114
112
|
}
|
|
@@ -172,7 +172,11 @@ let DeviceConfigurationService = (() => {
|
|
|
172
172
|
return { capabilities, interfaces };
|
|
173
173
|
}
|
|
174
174
|
disableCapability(cability, disabled = true) {
|
|
175
|
+
if (!this.settings?.capabilities)
|
|
176
|
+
return;
|
|
175
177
|
const cabilitySettings = this.settings.capabilities.find(c => c.capability === cability);
|
|
178
|
+
if (!cabilitySettings)
|
|
179
|
+
return;
|
|
176
180
|
cabilitySettings.disabled = disabled;
|
|
177
181
|
this.updateUserSettings();
|
|
178
182
|
this.emitCapabiltyChanged();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PageLogObserver = void 0;
|
|
4
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
5
|
+
const observer_1 = require("../../../base/types/observer");
|
|
6
|
+
class PageLogObserver extends observer_1.Observer {
|
|
7
|
+
loggerContext;
|
|
8
|
+
logger;
|
|
9
|
+
constructor(loggerContext) {
|
|
10
|
+
super();
|
|
11
|
+
this.loggerContext = loggerContext;
|
|
12
|
+
this.logger = new gd_eventlog_1.EventLogger(loggerContext);
|
|
13
|
+
}
|
|
14
|
+
emit(event, ...data) {
|
|
15
|
+
super.emit(event, ...data);
|
|
16
|
+
this.logger.logEvent({ message: 'Pairing page state event', event });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.PageLogObserver = PageLogObserver;
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
3
|
+
var useValue = arguments.length > 2;
|
|
4
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
5
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
6
|
+
}
|
|
7
|
+
return useValue ? value : void 0;
|
|
8
|
+
};
|
|
9
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
10
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
11
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
12
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
13
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
14
|
+
var _, done = false;
|
|
15
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
16
|
+
var context = {};
|
|
17
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
18
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
19
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
20
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
21
|
+
if (kind === "accessor") {
|
|
22
|
+
if (result === void 0) continue;
|
|
23
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
24
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
25
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
26
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
27
|
+
}
|
|
28
|
+
else if (_ = accept(result)) {
|
|
29
|
+
if (kind === "field") initializers.unshift(_);
|
|
30
|
+
else descriptor[key] = _;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
34
|
+
done = true;
|
|
35
|
+
};
|
|
36
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
+
exports.PairingPageService = void 0;
|
|
38
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
39
|
+
const decorators_1 = require("../../../base/decorators");
|
|
40
|
+
const pages_1 = require("../../../base/pages");
|
|
41
|
+
const pairing_1 = require("../../pairing");
|
|
42
|
+
const logobserver_1 = require("./logobserver");
|
|
43
|
+
const configuration_1 = require("../../configuration");
|
|
44
|
+
const visit_log_factory_1 = require("./visit-log-factory");
|
|
45
|
+
let PairingPageService = (() => {
|
|
46
|
+
let _classSuper = pages_1.IncyclistPageService;
|
|
47
|
+
let _instanceExtraInitializers = [];
|
|
48
|
+
let _getDevicePairing_decorators;
|
|
49
|
+
let _getDeviceConfiguration_decorators;
|
|
50
|
+
let _getPairingVisitTracker_decorators;
|
|
51
|
+
return class PairingPageService extends _classSuper {
|
|
52
|
+
static {
|
|
53
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
54
|
+
_getDevicePairing_decorators = [decorators_1.Injectable];
|
|
55
|
+
_getDeviceConfiguration_decorators = [decorators_1.Injectable];
|
|
56
|
+
_getPairingVisitTracker_decorators = [decorators_1.Injectable];
|
|
57
|
+
__esDecorate(this, null, _getDevicePairing_decorators, { kind: "method", name: "getDevicePairing", static: false, private: false, access: { has: obj => "getDevicePairing" in obj, get: obj => obj.getDevicePairing }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
58
|
+
__esDecorate(this, null, _getDeviceConfiguration_decorators, { kind: "method", name: "getDeviceConfiguration", static: false, private: false, access: { has: obj => "getDeviceConfiguration" in obj, get: obj => obj.getDeviceConfiguration }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
59
|
+
__esDecorate(this, null, _getPairingVisitTracker_decorators, { kind: "method", name: "getPairingVisitTracker", static: false, private: false, access: { has: obj => "getPairingVisitTracker" in obj, get: obj => obj.getPairingVisitTracker }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
60
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
61
|
+
}
|
|
62
|
+
promiseOpen = __runInitializers(this, _instanceExtraInitializers);
|
|
63
|
+
stateMachine;
|
|
64
|
+
logObserver;
|
|
65
|
+
openedCapability;
|
|
66
|
+
isPairingForRide = false;
|
|
67
|
+
isVisitOpen = false;
|
|
68
|
+
handingOffToRide = false;
|
|
69
|
+
constructor() {
|
|
70
|
+
super('pairing');
|
|
71
|
+
this.stateMachine = this.createOrchestrator();
|
|
72
|
+
this.logObserver = new logobserver_1.PageLogObserver('Pairing');
|
|
73
|
+
}
|
|
74
|
+
openPage(forRide) {
|
|
75
|
+
try {
|
|
76
|
+
this.logEvent({ message: 'page shown', page: 'Pairing', forRide });
|
|
77
|
+
this.isPairingForRide = forRide ?? false;
|
|
78
|
+
this.handingOffToRide = false;
|
|
79
|
+
this.openVisit();
|
|
80
|
+
gd_eventlog_1.EventLogger.setGlobalConfig('page', 'Pairing');
|
|
81
|
+
super.openPage();
|
|
82
|
+
if (this.promiseOpen !== undefined) {
|
|
83
|
+
return this.getPageObserver();
|
|
84
|
+
}
|
|
85
|
+
const onStateMachineUpdate = () => {
|
|
86
|
+
this.getPageObserver().emit('page-update');
|
|
87
|
+
};
|
|
88
|
+
this.stateMachine.start(onStateMachineUpdate);
|
|
89
|
+
if (this.stateMachine.state !== 'Idle') {
|
|
90
|
+
this.logEvent({ message: 'state machine was not in expected state on open, resetting', page: 'Pairing', state: this.stateMachine.state });
|
|
91
|
+
void this.stateMachine.stop();
|
|
92
|
+
this.stateMachine.start(onStateMachineUpdate);
|
|
93
|
+
}
|
|
94
|
+
this.promiseOpen = new Promise((done) => {
|
|
95
|
+
this.start()
|
|
96
|
+
.catch((err) => { this.logError(err, 'openPage'); })
|
|
97
|
+
.finally(done);
|
|
98
|
+
})
|
|
99
|
+
.then(() => { delete this.promiseOpen; });
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
this.logError(err, 'openPage');
|
|
103
|
+
}
|
|
104
|
+
return this.getPageObserver();
|
|
105
|
+
}
|
|
106
|
+
closePage() {
|
|
107
|
+
try {
|
|
108
|
+
this.logEvent({ message: 'page closed', page: 'Pairing' });
|
|
109
|
+
this.isVisitOpen = false;
|
|
110
|
+
gd_eventlog_1.EventLogger.setGlobalConfig('page', null);
|
|
111
|
+
this.isPairingForRide = false;
|
|
112
|
+
super.closePage();
|
|
113
|
+
if (!this.handingOffToRide)
|
|
114
|
+
this.stop().catch(err => { this.logError(err, 'closePage'); });
|
|
115
|
+
this.handingOffToRide = false;
|
|
116
|
+
void this.stateMachine.stop();
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
this.logError(err, 'closePage');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async pausePage() {
|
|
123
|
+
try {
|
|
124
|
+
this.trackVisit(t => t.onBackground({ canStartRide: this.canStartRide() }), 'onBackground');
|
|
125
|
+
await this.stateMachine.pause();
|
|
126
|
+
this.logEvent({ message: 'page paused', page: 'Pairing' });
|
|
127
|
+
}
|
|
128
|
+
catch (err) {
|
|
129
|
+
this.logError(err, 'pausePage');
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async resumePage() {
|
|
133
|
+
try {
|
|
134
|
+
this.trackVisit(t => t.onForeground(), 'onForeground');
|
|
135
|
+
this.stateMachine.resume();
|
|
136
|
+
if (this.promiseOpen !== undefined)
|
|
137
|
+
return;
|
|
138
|
+
this.promiseOpen = new Promise((done) => {
|
|
139
|
+
this.start()
|
|
140
|
+
.catch((err) => { this.logError(err, 'openPage'); })
|
|
141
|
+
.finally(done);
|
|
142
|
+
});
|
|
143
|
+
await this.promiseOpen;
|
|
144
|
+
delete this.promiseOpen;
|
|
145
|
+
this.logEvent({ message: 'page resumed', page: 'Pairing' });
|
|
146
|
+
}
|
|
147
|
+
catch (err) {
|
|
148
|
+
this.logError(err, 'pausePage');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
getCapabilityDisplayProps(data, noSearch = false) {
|
|
152
|
+
const { capability: cap, deviceName, connectState, value, unit, disabled } = data;
|
|
153
|
+
const capability = this.getTCapability(cap);
|
|
154
|
+
const title = this.getDisplayCapability(cap);
|
|
155
|
+
const onClick = () => { this.openDeviceSelection(cap); };
|
|
156
|
+
const role = pairing_1.PAIRING_CAPABILITY_ROLES.find(r => r.capability === cap)?.role;
|
|
157
|
+
const helpText = {
|
|
158
|
+
full: (0, pairing_1.getCapabilityHelpText)(capability, 'full') ?? '',
|
|
159
|
+
short: (0, pairing_1.getCapabilityHelpText)(capability, 'short') ?? '',
|
|
160
|
+
};
|
|
161
|
+
if (disabled) {
|
|
162
|
+
const hasRememberedDevice = Boolean(deviceName);
|
|
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
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const adapaters = this.state.adapters ?? [];
|
|
174
|
+
const adapter = adapaters.find(ai => data.selected && ai.udid === data.selected);
|
|
175
|
+
const ifName = adapter?.adapter?.getInterface();
|
|
176
|
+
const onUnselect = data.selected ? () => { this.onCapabilityUnselect(cap); } : undefined;
|
|
177
|
+
let emptyFooter = undefined;
|
|
178
|
+
if (noSearch)
|
|
179
|
+
emptyFooter = 'Not searching';
|
|
180
|
+
else if (role)
|
|
181
|
+
emptyFooter = (0, pairing_1.getEmptyTileFooterText)(role);
|
|
182
|
+
return {
|
|
183
|
+
title, capability, deviceName, disabled: false, connectState, value: value?.toString(), unit, interface: ifName,
|
|
184
|
+
role, helpText, emptyFooter,
|
|
185
|
+
onClick, onUnselect
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
getDeviceListDisplayProps() {
|
|
189
|
+
if (!this.openedCapability)
|
|
190
|
+
return;
|
|
191
|
+
const all = this.state.capabilities ?? [];
|
|
192
|
+
const requested = all.find(c => c.capability === this.openedCapability);
|
|
193
|
+
const capDevices = requested?.devices ?? [];
|
|
194
|
+
const devices = capDevices.map(d => ({
|
|
195
|
+
connectState: d.connectState,
|
|
196
|
+
deviceName: d.name,
|
|
197
|
+
value: d.value,
|
|
198
|
+
interface: d.interface,
|
|
199
|
+
isSelected: d.selected,
|
|
200
|
+
onClick: (addAll) => { this.onDeviceSelected(d, addAll); },
|
|
201
|
+
onDelete: () => { this.onDeviceDelete(d); }
|
|
202
|
+
}));
|
|
203
|
+
const disabled = devices.length > 0 && !devices.some(d => d.isSelected);
|
|
204
|
+
return {
|
|
205
|
+
capability: this.openedCapability,
|
|
206
|
+
devices,
|
|
207
|
+
isScanning: this.stateMachine.selectState === 'Active',
|
|
208
|
+
changeForAll: false,
|
|
209
|
+
canSelectAll: this.openedCapability === 'control',
|
|
210
|
+
disabled,
|
|
211
|
+
onClose: () => { this.closeDeviceSelection(); },
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
updatePage() {
|
|
215
|
+
this.getPageObserver().emit('page-update');
|
|
216
|
+
}
|
|
217
|
+
onEnableCapability(enabled) {
|
|
218
|
+
const all = this.state.capabilities ?? [];
|
|
219
|
+
const requested = all.find(c => c.capability === this.openedCapability);
|
|
220
|
+
requested.disabled = !enabled;
|
|
221
|
+
this.updatePage();
|
|
222
|
+
}
|
|
223
|
+
openDeviceSelection(cap) {
|
|
224
|
+
this.logEvent({ message: 'capability clicked', capability: cap, eventSource: 'user' });
|
|
225
|
+
this.openedCapability = cap;
|
|
226
|
+
this.stateMachine.onDeviceSelectionOpened(() => { this.updatePage(); });
|
|
227
|
+
this.updatePage();
|
|
228
|
+
}
|
|
229
|
+
onDeviceSelected(d, addAll) {
|
|
230
|
+
const capability = this.openedCapability;
|
|
231
|
+
this.logEvent({ message: 'device selected', capability, device: d.name });
|
|
232
|
+
this.closeDeviceSelection();
|
|
233
|
+
this.getDevicePairing().selectDevice(capability, d.udid, addAll);
|
|
234
|
+
this.updatePage();
|
|
235
|
+
}
|
|
236
|
+
onCapabilityUnselect(cap) {
|
|
237
|
+
this.logEvent({ message: 'capability unselect clicked', capability: cap, eventSource: 'user' });
|
|
238
|
+
this.getDevicePairing().unselectDevices(cap)
|
|
239
|
+
.catch(err => { this.logError(err, 'onCapabilityUnselect'); });
|
|
240
|
+
this.updatePage();
|
|
241
|
+
}
|
|
242
|
+
onCapabilityUse(cap) {
|
|
243
|
+
this.logEvent({ message: 'capability use clicked', capability: cap, eventSource: 'user' });
|
|
244
|
+
this.getDevicePairing().useCapability(cap);
|
|
245
|
+
this.updatePage();
|
|
246
|
+
}
|
|
247
|
+
onDeviceDelete(d) {
|
|
248
|
+
const capability = this.openedCapability;
|
|
249
|
+
this.logEvent({ message: 'device delete requested', capability, device: d.name });
|
|
250
|
+
this.getDevicePairing().deleteDevice(capability, d.udid);
|
|
251
|
+
this.updatePage();
|
|
252
|
+
}
|
|
253
|
+
closeDeviceSelection() {
|
|
254
|
+
this.logEvent({ message: 'capability closed', capability: this.openedCapability, caller: new Error().stack });
|
|
255
|
+
this.openedCapability = undefined;
|
|
256
|
+
this.stateMachine.onDeviceSelectionClosed();
|
|
257
|
+
this.updatePage();
|
|
258
|
+
}
|
|
259
|
+
getButtonsDisplayProps() {
|
|
260
|
+
const labelOK = this.isPairingForRide ? 'Start' : 'OK';
|
|
261
|
+
const labelSkip = this.isPairingForRide ? 'Cancel' : 'Skip';
|
|
262
|
+
if (this.state?.canStartRide)
|
|
263
|
+
return [
|
|
264
|
+
{ label: labelOK, primary: true, onClick: this.onOK.bind(this) }
|
|
265
|
+
];
|
|
266
|
+
if (!this.isPairingForRide)
|
|
267
|
+
return [
|
|
268
|
+
{ label: labelSkip, primary: true, onClick: this.onSkip.bind(this) }
|
|
269
|
+
];
|
|
270
|
+
return [
|
|
271
|
+
{ label: 'Simulate', primary: true, onClick: this.onSimulate.bind(this) },
|
|
272
|
+
{ label: labelSkip, primary: false, onClick: this.onSkip.bind(this) }
|
|
273
|
+
];
|
|
274
|
+
}
|
|
275
|
+
getTCapability(capabability) {
|
|
276
|
+
const mapping = {
|
|
277
|
+
'app_control': 'app_control',
|
|
278
|
+
'cadence': 'cadence',
|
|
279
|
+
'control': 'control',
|
|
280
|
+
'heartrate': 'heartrate',
|
|
281
|
+
'power': 'power',
|
|
282
|
+
'speed': 'speed'
|
|
283
|
+
};
|
|
284
|
+
return mapping[capabability];
|
|
285
|
+
}
|
|
286
|
+
getDisplayCapability(capabability) {
|
|
287
|
+
const mapping = {
|
|
288
|
+
'app_control': 'controller',
|
|
289
|
+
'cadence': 'cadence',
|
|
290
|
+
'control': 'resistance',
|
|
291
|
+
'heartrate': 'heartrate',
|
|
292
|
+
'power': 'power',
|
|
293
|
+
'speed': 'speed'
|
|
294
|
+
};
|
|
295
|
+
return mapping[capabability];
|
|
296
|
+
}
|
|
297
|
+
trackVisit(fn, name) {
|
|
298
|
+
try {
|
|
299
|
+
fn(this.getPairingVisitTracker());
|
|
300
|
+
}
|
|
301
|
+
catch (err) {
|
|
302
|
+
this.logError(err, name);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
openVisit() {
|
|
306
|
+
if (this.isVisitOpen)
|
|
307
|
+
return;
|
|
308
|
+
this.trackVisit(t => t.openVisit({ forRide: this.isPairingForRide }), 'openVisit');
|
|
309
|
+
this.isVisitOpen = true;
|
|
310
|
+
}
|
|
311
|
+
closeVisit(via) {
|
|
312
|
+
this.trackVisit(t => t.closeVisit(via, { canStartRide: this.canStartRide() }), 'closeVisit');
|
|
313
|
+
this.isVisitOpen = false;
|
|
314
|
+
}
|
|
315
|
+
canStartRide() {
|
|
316
|
+
return this.state?.canStartRide ?? false;
|
|
317
|
+
}
|
|
318
|
+
onSkip() {
|
|
319
|
+
this.closeVisit('skip');
|
|
320
|
+
const nextPage = this.getAppState().getPersistedState('page') ?? 'routes';
|
|
321
|
+
this.moveTo(`/${nextPage}`);
|
|
322
|
+
}
|
|
323
|
+
prepareForRide(adapterFilter = []) {
|
|
324
|
+
this.getDevicePairing().prepareStart(adapterFilter)
|
|
325
|
+
.catch(err => { this.logError(err, 'prepareForRide'); });
|
|
326
|
+
this.handingOffToRide = true;
|
|
327
|
+
}
|
|
328
|
+
onOK() {
|
|
329
|
+
this.closeVisit('ok');
|
|
330
|
+
this.prepareForRide();
|
|
331
|
+
this.getDevicePairing().setReadyToStart();
|
|
332
|
+
this.getAppState().setState('paired', true);
|
|
333
|
+
const prevContentPage = this.getPrevContentPage();
|
|
334
|
+
const prevPage = this.getAppState().getState('prevPage');
|
|
335
|
+
if (!prevPage) {
|
|
336
|
+
this.moveTo(`/${prevContentPage}`);
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
if (this.isPairingForRide)
|
|
340
|
+
this.moveTo('/rideDeviceOK');
|
|
341
|
+
else
|
|
342
|
+
this.moveTo(`/${prevContentPage}`);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
onSimulate() {
|
|
346
|
+
this.closeVisit('simulate');
|
|
347
|
+
const simulator = this.getDeviceConfiguration().getSimulatorAdapterId();
|
|
348
|
+
this.prepareForRide([simulator]);
|
|
349
|
+
const prevContentPage = this.getPrevContentPage();
|
|
350
|
+
if (this.isPairingForRide)
|
|
351
|
+
this.moveTo('/rideSimulate');
|
|
352
|
+
else
|
|
353
|
+
this.moveTo(`/${prevContentPage}`);
|
|
354
|
+
}
|
|
355
|
+
onCancel() {
|
|
356
|
+
this.closeVisit('cancel');
|
|
357
|
+
const nextPage = this.getAppState().getState('prevPage');
|
|
358
|
+
this.moveTo(`/${nextPage}`);
|
|
359
|
+
}
|
|
360
|
+
async start() {
|
|
361
|
+
this.getDevicePairing().usage = this.getUsageMode();
|
|
362
|
+
this.getDevicePairing().start(() => {
|
|
363
|
+
this.updatePage();
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
async stop(adapters = [], forExit = false) {
|
|
367
|
+
return await this.getDevicePairing().stop(adapters, forExit);
|
|
368
|
+
}
|
|
369
|
+
get state() {
|
|
370
|
+
return this.getDevicePairing().getState();
|
|
371
|
+
}
|
|
372
|
+
getDevicePairing() {
|
|
373
|
+
return (0, pairing_1.useDevicePairing)();
|
|
374
|
+
}
|
|
375
|
+
getDeviceConfiguration() {
|
|
376
|
+
return (0, configuration_1.useDeviceConfiguration)();
|
|
377
|
+
}
|
|
378
|
+
getPairingVisitTracker() {
|
|
379
|
+
return (0, visit_log_factory_1.usePairingVisitTracker)();
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
})();
|
|
383
|
+
exports.PairingPageService = PairingPageService;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePairingVisitTracker = exports.initPairingVisitTracker = exports.toVisitPlatform = exports.formatLocalDate = exports.createPairingVisitStore = exports.PAIRING_VISITS_STATE_KEY = void 0;
|
|
4
|
+
const gd_eventlog_1 = require("gd-eventlog");
|
|
5
|
+
const api_1 = require("../../../api");
|
|
6
|
+
const appstate_1 = require("../../../appstate");
|
|
7
|
+
const visit_log_1 = require("./visit-log");
|
|
8
|
+
exports.PAIRING_VISITS_STATE_KEY = 'pairingVisits';
|
|
9
|
+
let instance;
|
|
10
|
+
let logger;
|
|
11
|
+
const createPairingVisitStore = (appState) => ({
|
|
12
|
+
get: () => appState.getPersistedState(exports.PAIRING_VISITS_STATE_KEY) ?? undefined,
|
|
13
|
+
set: (record) => { appState.setPersistedState(exports.PAIRING_VISITS_STATE_KEY, record); },
|
|
14
|
+
});
|
|
15
|
+
exports.createPairingVisitStore = createPairingVisitStore;
|
|
16
|
+
const formatLocalDate = (date) => {
|
|
17
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
18
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
19
|
+
};
|
|
20
|
+
exports.formatLocalDate = formatLocalDate;
|
|
21
|
+
const toVisitPlatform = (platform) => platform?.startsWith('mobile') ? 'mobile' : 'desktop';
|
|
22
|
+
exports.toVisitPlatform = toVisitPlatform;
|
|
23
|
+
const log = (message, fields) => {
|
|
24
|
+
logger = logger ?? new gd_eventlog_1.EventLogger('Pairing');
|
|
25
|
+
logger.logEvent({ message, ...fields });
|
|
26
|
+
};
|
|
27
|
+
const initPairingVisitTracker = (platform) => {
|
|
28
|
+
const appInfo = (0, api_1.getBindings)()?.appInfo;
|
|
29
|
+
instance = new visit_log_1.PairingVisitTracker({
|
|
30
|
+
store: (0, exports.createPairingVisitStore)((0, appstate_1.useAppState)()),
|
|
31
|
+
sessionId: appInfo?.session ?? '',
|
|
32
|
+
platform: (0, exports.toVisitPlatform)(platform ?? appInfo?.getChannel()),
|
|
33
|
+
now: () => Date.now(),
|
|
34
|
+
today: () => (0, exports.formatLocalDate)(new Date()),
|
|
35
|
+
log,
|
|
36
|
+
});
|
|
37
|
+
return instance;
|
|
38
|
+
};
|
|
39
|
+
exports.initPairingVisitTracker = initPairingVisitTracker;
|
|
40
|
+
const usePairingVisitTracker = () => instance ?? (0, exports.initPairingVisitTracker)();
|
|
41
|
+
exports.usePairingVisitTracker = usePairingVisitTracker;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PairingVisitTracker = exports.getPreviousVisitOutcome = exports.VISIT_UNCLOSED_EVENT = exports.PAGE_LEFT_EVENT = void 0;
|
|
4
|
+
let visitSequence = 0;
|
|
5
|
+
exports.PAGE_LEFT_EVENT = 'pairing page left';
|
|
6
|
+
exports.VISIT_UNCLOSED_EVENT = 'pairing visit unclosed';
|
|
7
|
+
const getPreviousVisitOutcome = (last) => {
|
|
8
|
+
if (!last || !last.closed || !last.via)
|
|
9
|
+
return 'none';
|
|
10
|
+
switch (last.via) {
|
|
11
|
+
case 'ok':
|
|
12
|
+
return 'ready';
|
|
13
|
+
case 'simulate':
|
|
14
|
+
return 'simulate';
|
|
15
|
+
case 'skip':
|
|
16
|
+
case 'cancel':
|
|
17
|
+
if (last.rideAfter === 'device')
|
|
18
|
+
return 'skip-then-ride';
|
|
19
|
+
if (last.rideAfter === 'simulate')
|
|
20
|
+
return 'simulate';
|
|
21
|
+
return 'skip-no-ride';
|
|
22
|
+
case 'app_exit':
|
|
23
|
+
return last.canStartRide ? 'app-exit-ready' : 'app-exit-not-ready';
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.getPreviousVisitOutcome = getPreviousVisitOutcome;
|
|
27
|
+
class PairingVisitTracker {
|
|
28
|
+
deps;
|
|
29
|
+
constructor(deps) {
|
|
30
|
+
this.deps = deps;
|
|
31
|
+
}
|
|
32
|
+
onAppLaunch(isNewUser) {
|
|
33
|
+
const record = this.deps.store.get();
|
|
34
|
+
if (!record) {
|
|
35
|
+
this.deps.store.set({ date: this.deps.today(), countToday: 0, firstEverPending: isNewUser });
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const last = record.last;
|
|
39
|
+
if (!last || last.closed)
|
|
40
|
+
return;
|
|
41
|
+
const now = this.deps.now();
|
|
42
|
+
this.deps.log(exports.VISIT_UNCLOSED_EVENT, {
|
|
43
|
+
visitId: last.visitId,
|
|
44
|
+
visitSessionId: last.sessionId,
|
|
45
|
+
dwellMs: last.backgroundedAt !== undefined ? last.backgroundedAt - last.openedAt : null,
|
|
46
|
+
backgroundMs: last.backgroundMs,
|
|
47
|
+
forRide: last.forRide,
|
|
48
|
+
canStartRide: last.canStartRide,
|
|
49
|
+
visitIndexToday: last.visitIndexToday,
|
|
50
|
+
firstEverVisit: last.firstEverVisit,
|
|
51
|
+
visitAgeMs: now - last.openedAt,
|
|
52
|
+
platform: this.deps.platform,
|
|
53
|
+
});
|
|
54
|
+
this.deps.store.set({
|
|
55
|
+
...record,
|
|
56
|
+
last: { ...last, closed: true, via: 'app_exit', inferred: true, closedAt: last.backgroundedAt ?? last.openedAt, backgroundedAt: undefined },
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
openVisit({ forRide }) {
|
|
60
|
+
const now = this.deps.now();
|
|
61
|
+
const today = this.deps.today();
|
|
62
|
+
const previous = this.deps.store.get();
|
|
63
|
+
if (previous?.last && !previous.last.closed)
|
|
64
|
+
this.closeVisit('app_exit', { canStartRide: previous.last.canStartRide });
|
|
65
|
+
const record = this.deps.store.get() ?? { date: today, countToday: 0, firstEverPending: false };
|
|
66
|
+
const countToday = record.date === today ? record.countToday + 1 : 1;
|
|
67
|
+
const visitId = `${now}-${++visitSequence}`;
|
|
68
|
+
const prevLast = record.last;
|
|
69
|
+
this.deps.store.set({
|
|
70
|
+
date: today,
|
|
71
|
+
countToday,
|
|
72
|
+
firstEverPending: false,
|
|
73
|
+
last: {
|
|
74
|
+
visitId,
|
|
75
|
+
sessionId: this.deps.sessionId,
|
|
76
|
+
openedAt: now,
|
|
77
|
+
backgroundMs: 0,
|
|
78
|
+
forRide,
|
|
79
|
+
canStartRide: false,
|
|
80
|
+
visitIndexToday: countToday,
|
|
81
|
+
firstEverVisit: record.firstEverPending,
|
|
82
|
+
previousVisitOutcome: (0, exports.getPreviousVisitOutcome)(prevLast),
|
|
83
|
+
previousVisitAgeMs: prevLast?.closedAt !== undefined ? now - prevLast.closedAt : undefined,
|
|
84
|
+
closed: false,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
return { visitId };
|
|
88
|
+
}
|
|
89
|
+
onBackground({ canStartRide } = {}) {
|
|
90
|
+
const record = this.deps.store.get();
|
|
91
|
+
const last = record?.last;
|
|
92
|
+
if (!record || !last || last.closed || last.backgroundedAt !== undefined)
|
|
93
|
+
return;
|
|
94
|
+
const refreshed = canStartRide ?? last.canStartRide;
|
|
95
|
+
this.deps.store.set({ ...record, last: { ...last, canStartRide: refreshed, backgroundedAt: this.deps.now() } });
|
|
96
|
+
}
|
|
97
|
+
onForeground() {
|
|
98
|
+
const record = this.deps.store.get();
|
|
99
|
+
const last = record?.last;
|
|
100
|
+
if (!record || !last || last.closed || last.backgroundedAt === undefined)
|
|
101
|
+
return;
|
|
102
|
+
const backgroundMs = last.backgroundMs + (this.deps.now() - last.backgroundedAt);
|
|
103
|
+
this.deps.store.set({ ...record, last: { ...last, backgroundMs, backgroundedAt: undefined } });
|
|
104
|
+
}
|
|
105
|
+
closeVisit(via, { canStartRide }) {
|
|
106
|
+
const record = this.deps.store.get();
|
|
107
|
+
const last = record?.last;
|
|
108
|
+
if (!record || !last || last.closed)
|
|
109
|
+
return;
|
|
110
|
+
const now = this.deps.now();
|
|
111
|
+
const backgroundMs = last.backgroundMs + (last.backgroundedAt !== undefined ? now - last.backgroundedAt : 0);
|
|
112
|
+
this.deps.log(exports.PAGE_LEFT_EVENT, {
|
|
113
|
+
visitId: last.visitId,
|
|
114
|
+
via,
|
|
115
|
+
dwellMs: now - last.openedAt,
|
|
116
|
+
backgroundMs,
|
|
117
|
+
forRide: last.forRide,
|
|
118
|
+
canStartRide,
|
|
119
|
+
visitIndexToday: last.visitIndexToday,
|
|
120
|
+
firstEverVisit: last.firstEverVisit,
|
|
121
|
+
previousVisitOutcome: last.previousVisitOutcome,
|
|
122
|
+
previousVisitAgeMs: last.previousVisitAgeMs,
|
|
123
|
+
platform: this.deps.platform,
|
|
124
|
+
});
|
|
125
|
+
this.deps.store.set({
|
|
126
|
+
...record,
|
|
127
|
+
last: { ...last, closed: true, via, canStartRide, backgroundMs, backgroundedAt: undefined, closedAt: now },
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
onAppExit(canStartRide) {
|
|
131
|
+
this.closeVisit('app_exit', { canStartRide });
|
|
132
|
+
}
|
|
133
|
+
onRideStarted({ simulate }) {
|
|
134
|
+
const record = this.deps.store.get();
|
|
135
|
+
const last = record?.last;
|
|
136
|
+
if (!record || !last || !last.closed || last.rideAfter)
|
|
137
|
+
return;
|
|
138
|
+
if (last.via !== 'skip' && last.via !== 'cancel')
|
|
139
|
+
return;
|
|
140
|
+
this.deps.store.set({ ...record, last: { ...last, rideAfter: simulate ? 'simulate' : 'device' } });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.PairingVisitTracker = PairingVisitTracker;
|