incyclist-services 1.9.11 → 1.9.13
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/apps/googleMaps/consts.js +10 -0
- package/lib/cjs/apps/googleMaps/index.js +1 -0
- package/lib/cjs/apps/googleMaps/service.js +46 -1
- package/lib/cjs/maps/MapArea/options.js +2 -3
- package/lib/cjs/ride/display/service.js +95 -0
- package/lib/cjs/ride/index.js +1 -0
- package/lib/cjs/ride/page/service.js +69 -1
- package/lib/cjs/ride/route/FreeRideDisplayService.js +36 -5
- package/lib/cjs/ride/route/GpxDisplayService.js +46 -1
- package/lib/cjs/ride/view-restriction/index.js +18 -0
- package/lib/cjs/ride/view-restriction/service.js +221 -0
- package/lib/cjs/ride/view-restriction/types.js +2 -0
- package/lib/cjs/routes/free-ride/option-labels.js +141 -0
- package/lib/cjs/routes/free-ride/service.js +217 -117
- package/lib/cjs/settings/display/ride/service.js +22 -4
- package/lib/esm/apps/googleMaps/consts.js +7 -0
- package/lib/esm/apps/googleMaps/index.js +1 -0
- package/lib/esm/apps/googleMaps/service.js +46 -1
- package/lib/esm/maps/MapArea/options.js +2 -3
- package/lib/esm/ride/display/service.js +95 -0
- package/lib/esm/ride/index.js +1 -0
- package/lib/esm/ride/page/service.js +69 -1
- package/lib/esm/ride/route/FreeRideDisplayService.js +36 -5
- package/lib/esm/ride/route/GpxDisplayService.js +46 -1
- package/lib/esm/ride/view-restriction/index.js +2 -0
- package/lib/esm/ride/view-restriction/service.js +217 -0
- package/lib/esm/ride/view-restriction/types.js +1 -0
- package/lib/esm/routes/free-ride/service.js +217 -117
- package/lib/esm/settings/display/ride/service.js +20 -2
- package/lib/types/apps/googleMaps/consts.d.ts +7 -0
- package/lib/types/apps/googleMaps/index.d.ts +1 -0
- package/lib/types/apps/googleMaps/service.d.ts +8 -0
- package/lib/types/maps/MapArea/types.d.ts +1 -0
- package/lib/types/ride/base/types.d.ts +5 -1
- package/lib/types/ride/display/service.d.ts +15 -0
- package/lib/types/ride/index.d.ts +1 -0
- package/lib/types/ride/page/service.d.ts +10 -0
- package/lib/types/ride/page/types.d.ts +10 -0
- package/lib/types/ride/route/FreeRideDisplayService.d.ts +4 -1
- package/lib/types/ride/route/GpxDisplayService.d.ts +5 -0
- package/lib/types/ride/view-restriction/index.d.ts +2 -0
- package/lib/types/ride/view-restriction/service.d.ts +30 -0
- package/lib/types/ride/view-restriction/types.d.ts +57 -0
- package/lib/types/routes/free-ride/service.d.ts +18 -2
- package/lib/types/routes/list/types.d.ts +11 -0
- package/lib/types/settings/display/ride/service.d.ts +1 -0
- package/lib/types/settings/display/ride/types.d.ts +4 -0
- package/package.json +3 -3
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
2
|
+
var useValue = arguments.length > 2;
|
|
3
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
4
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
5
|
+
}
|
|
6
|
+
return useValue ? value : void 0;
|
|
7
|
+
};
|
|
8
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
9
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
10
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
11
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
12
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
13
|
+
var _, done = false;
|
|
14
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
15
|
+
var context = {};
|
|
16
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
17
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
18
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
19
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
20
|
+
if (kind === "accessor") {
|
|
21
|
+
if (result === void 0) continue;
|
|
22
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
23
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
24
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
25
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
26
|
+
}
|
|
27
|
+
else if (_ = accept(result)) {
|
|
28
|
+
if (kind === "field") initializers.unshift(_);
|
|
29
|
+
else descriptor[key] = _;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
33
|
+
done = true;
|
|
34
|
+
};
|
|
35
|
+
import { getBindings } from '../../api';
|
|
36
|
+
import { MAPS_KEY_HELP_URL, MAPS_KEY_TEXTS } from '../../apps/googleMaps/consts';
|
|
37
|
+
import { useGoogleMaps } from '../../apps/googleMaps/service';
|
|
38
|
+
import { Injectable } from '../../base/decorators';
|
|
39
|
+
import { IncyclistService } from '../../base/service';
|
|
40
|
+
import { Singleton } from '../../base/types';
|
|
41
|
+
import { useAppState } from '../../appstate/service';
|
|
42
|
+
const NOTICE_OFF_STATE_KEY = 'simulatedRideViewNoticeOff';
|
|
43
|
+
const DIALOG_TITLE = 'Street View in simulated rides';
|
|
44
|
+
const DIALOG_BODY = 'Street View and Satellite View use Google Maps, and Google charges Incyclist for every ride that uses them. To keep Incyclist free, these views come with rides on a connected device. A simulated ride shows the Map instead.';
|
|
45
|
+
const DEVICE_TEXT = 'Connect your smart trainer, power meter or speed sensor before you start. Street View then works as usual.';
|
|
46
|
+
const DEVICE_TEXT_MOBILE = 'To get Street View: connect your smart trainer, power meter or speed sensor before you start.';
|
|
47
|
+
const OWN_KEY_TEXT = `With your own key, Street View and Satellite View also work in simulated rides. ${MAPS_KEY_TEXTS.billing}`;
|
|
48
|
+
const VIEW_NAMES = { sv: 'Street View', sat: 'Satellite View' };
|
|
49
|
+
let RideViewRestrictionService = (() => {
|
|
50
|
+
let _classDecorators = [Singleton];
|
|
51
|
+
let _classDescriptor;
|
|
52
|
+
let _classExtraInitializers = [];
|
|
53
|
+
let _classThis;
|
|
54
|
+
let _classSuper = IncyclistService;
|
|
55
|
+
let _instanceExtraInitializers = [];
|
|
56
|
+
let _getAppState_decorators;
|
|
57
|
+
let _getGoogleMaps_decorators;
|
|
58
|
+
let _getBindings_decorators;
|
|
59
|
+
var RideViewRestrictionService = class extends _classSuper {
|
|
60
|
+
static { _classThis = this; }
|
|
61
|
+
static {
|
|
62
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
|
|
63
|
+
_getAppState_decorators = [Injectable];
|
|
64
|
+
_getGoogleMaps_decorators = [Injectable];
|
|
65
|
+
_getBindings_decorators = [Injectable];
|
|
66
|
+
__esDecorate(this, null, _getAppState_decorators, { kind: "method", name: "getAppState", static: false, private: false, access: { has: obj => "getAppState" in obj, get: obj => obj.getAppState }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
67
|
+
__esDecorate(this, null, _getGoogleMaps_decorators, { kind: "method", name: "getGoogleMaps", static: false, private: false, access: { has: obj => "getGoogleMaps" in obj, get: obj => obj.getGoogleMaps }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
68
|
+
__esDecorate(this, null, _getBindings_decorators, { kind: "method", name: "getBindings", static: false, private: false, access: { has: obj => "getBindings" in obj, get: obj => obj.getBindings }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
69
|
+
__esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
|
|
70
|
+
RideViewRestrictionService = _classThis = _classDescriptor.value;
|
|
71
|
+
if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
72
|
+
__runInitializers(_classThis, _classExtraInitializers);
|
|
73
|
+
}
|
|
74
|
+
restriction = __runInitializers(this, _instanceExtraInitializers);
|
|
75
|
+
noticeState = 'inactive';
|
|
76
|
+
noticeId = 0;
|
|
77
|
+
constructor() {
|
|
78
|
+
super('RideViewRestriction');
|
|
79
|
+
}
|
|
80
|
+
beginRide(props) {
|
|
81
|
+
try {
|
|
82
|
+
this.restriction = undefined;
|
|
83
|
+
this.noticeState = 'inactive';
|
|
84
|
+
this.noticeId++;
|
|
85
|
+
if (props.simulated && !this.getGoogleMaps().hasActivePersonalApiKey()) {
|
|
86
|
+
this.restriction = { cause: 'simulation', preferredView: props.preferredView };
|
|
87
|
+
if (this.isNoticeWanted(this.restriction))
|
|
88
|
+
this.noticeState = 'armed';
|
|
89
|
+
}
|
|
90
|
+
this.logEvent({ message: 'ride view restriction', restricted: this.restriction !== undefined, noticeState: this.noticeState });
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
this.logError(err, 'beginRide');
|
|
94
|
+
}
|
|
95
|
+
this.emit('changed');
|
|
96
|
+
}
|
|
97
|
+
onRideStarted() {
|
|
98
|
+
if (this.noticeState !== 'armed')
|
|
99
|
+
return;
|
|
100
|
+
this.noticeState = 'due';
|
|
101
|
+
this.emit('changed');
|
|
102
|
+
}
|
|
103
|
+
endRide() {
|
|
104
|
+
this.restriction = undefined;
|
|
105
|
+
this.noticeState = 'inactive';
|
|
106
|
+
this.emit('changed');
|
|
107
|
+
}
|
|
108
|
+
getActiveRestriction() {
|
|
109
|
+
return this.restriction;
|
|
110
|
+
}
|
|
111
|
+
getNotice() {
|
|
112
|
+
const id = this.noticeId;
|
|
113
|
+
if (this.noticeState === 'due' && this.restriction) {
|
|
114
|
+
const view = VIEW_NAMES[this.restriction.preferredView];
|
|
115
|
+
return {
|
|
116
|
+
id, state: 'message',
|
|
117
|
+
text: `${view} isn't available in simulated rides. Showing the Map instead.`,
|
|
118
|
+
actions: [
|
|
119
|
+
{ id: 'how-to', label: `How to get ${view}` },
|
|
120
|
+
{ id: 'dont-show-again', label: "Don't show this again" },
|
|
121
|
+
]
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
if (this.noticeState === 'acknowledged') {
|
|
125
|
+
return {
|
|
126
|
+
id, state: 'acknowledged',
|
|
127
|
+
actions: [{ id: 'change-this', label: "We won't show this again. Change this" }]
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
onNoticeAction(id) {
|
|
133
|
+
if (id === 'dont-show-again') {
|
|
134
|
+
this.setReminderEnabled(false);
|
|
135
|
+
if (this.noticeState === 'due')
|
|
136
|
+
this.noticeState = 'acknowledged';
|
|
137
|
+
}
|
|
138
|
+
else if (this.noticeState === 'due' || this.noticeState === 'acknowledged') {
|
|
139
|
+
this.noticeState = 'closed';
|
|
140
|
+
}
|
|
141
|
+
this.emit('changed');
|
|
142
|
+
}
|
|
143
|
+
onNoticeClosed() {
|
|
144
|
+
if (this.noticeState !== 'due' && this.noticeState !== 'acknowledged')
|
|
145
|
+
return;
|
|
146
|
+
this.noticeState = 'closed';
|
|
147
|
+
this.emit('changed');
|
|
148
|
+
}
|
|
149
|
+
isReminderEnabled() {
|
|
150
|
+
return this.getAppState().getPersistedState(NOTICE_OFF_STATE_KEY) !== true;
|
|
151
|
+
}
|
|
152
|
+
setReminderEnabled(enabled) {
|
|
153
|
+
try {
|
|
154
|
+
this.getAppState().setPersistedState(NOTICE_OFF_STATE_KEY, !enabled);
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
this.logError(err, 'setReminderEnabled');
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
getDialogProps(props = {}) {
|
|
161
|
+
const options = [this.getDeviceOption(props.inRide === true)];
|
|
162
|
+
if (!this.isMobile())
|
|
163
|
+
options.push(this.getOwnKeyOption());
|
|
164
|
+
const dialog = { title: DIALOG_TITLE, body: DIALOG_BODY, options };
|
|
165
|
+
if (this.restriction)
|
|
166
|
+
dialog.reminder = { label: 'Remind me in simulated rides', checked: this.isReminderEnabled() };
|
|
167
|
+
return dialog;
|
|
168
|
+
}
|
|
169
|
+
isNoticeWanted(restriction) {
|
|
170
|
+
return (restriction.preferredView === 'sv' || restriction.preferredView === 'sat') && this.isReminderEnabled();
|
|
171
|
+
}
|
|
172
|
+
getDeviceOption(inRide) {
|
|
173
|
+
const mobile = this.isMobile();
|
|
174
|
+
const option = {
|
|
175
|
+
id: 'device',
|
|
176
|
+
text: mobile ? DEVICE_TEXT_MOBILE : DEVICE_TEXT,
|
|
177
|
+
};
|
|
178
|
+
if (!mobile)
|
|
179
|
+
option.heading = 'Ride with a device';
|
|
180
|
+
if (inRide) {
|
|
181
|
+
option.discard = {
|
|
182
|
+
label: 'Discard ride and connect a device',
|
|
183
|
+
confirm: { question: 'Discard this simulated ride?', confirmLabel: 'Discard and connect', cancelLabel: 'Keep riding' }
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
return option;
|
|
187
|
+
}
|
|
188
|
+
getOwnKeyOption() {
|
|
189
|
+
const option = {
|
|
190
|
+
id: 'own-key',
|
|
191
|
+
heading: 'Or use your own Google Maps API key',
|
|
192
|
+
text: OWN_KEY_TEXT,
|
|
193
|
+
helpLink: { label: MAPS_KEY_TEXTS.helpLabel, url: MAPS_KEY_HELP_URL },
|
|
194
|
+
};
|
|
195
|
+
if (this.getGoogleMaps().isPersonalApiKeyPendingRestart())
|
|
196
|
+
option.pendingRestart = { text: MAPS_KEY_TEXTS.pendingRestart };
|
|
197
|
+
else
|
|
198
|
+
option.addKey = { label: 'Add my key' };
|
|
199
|
+
return option;
|
|
200
|
+
}
|
|
201
|
+
isMobile() {
|
|
202
|
+
return this.getBindings()?.appInfo?.getChannel() === 'mobile';
|
|
203
|
+
}
|
|
204
|
+
getAppState() {
|
|
205
|
+
return useAppState();
|
|
206
|
+
}
|
|
207
|
+
getGoogleMaps() {
|
|
208
|
+
return useGoogleMaps();
|
|
209
|
+
}
|
|
210
|
+
getBindings() {
|
|
211
|
+
return getBindings();
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
return RideViewRestrictionService = _classThis;
|
|
215
|
+
})();
|
|
216
|
+
export { RideViewRestrictionService };
|
|
217
|
+
export const useRideViewRestriction = () => new RideViewRestrictionService();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|