incyclist-services 1.9.12 → 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.
Files changed (37) hide show
  1. package/lib/cjs/apps/googleMaps/consts.js +10 -0
  2. package/lib/cjs/apps/googleMaps/index.js +1 -0
  3. package/lib/cjs/apps/googleMaps/service.js +46 -1
  4. package/lib/cjs/ride/display/service.js +95 -0
  5. package/lib/cjs/ride/index.js +1 -0
  6. package/lib/cjs/ride/page/service.js +69 -1
  7. package/lib/cjs/ride/route/GpxDisplayService.js +46 -1
  8. package/lib/cjs/ride/view-restriction/index.js +18 -0
  9. package/lib/cjs/ride/view-restriction/service.js +221 -0
  10. package/lib/cjs/ride/view-restriction/types.js +2 -0
  11. package/lib/cjs/settings/display/ride/service.js +22 -4
  12. package/lib/esm/apps/googleMaps/consts.js +7 -0
  13. package/lib/esm/apps/googleMaps/index.js +1 -0
  14. package/lib/esm/apps/googleMaps/service.js +46 -1
  15. package/lib/esm/ride/display/service.js +95 -0
  16. package/lib/esm/ride/index.js +1 -0
  17. package/lib/esm/ride/page/service.js +69 -1
  18. package/lib/esm/ride/route/GpxDisplayService.js +46 -1
  19. package/lib/esm/ride/view-restriction/index.js +2 -0
  20. package/lib/esm/ride/view-restriction/service.js +217 -0
  21. package/lib/esm/ride/view-restriction/types.js +1 -0
  22. package/lib/esm/settings/display/ride/service.js +20 -2
  23. package/lib/types/apps/googleMaps/consts.d.ts +7 -0
  24. package/lib/types/apps/googleMaps/index.d.ts +1 -0
  25. package/lib/types/apps/googleMaps/service.d.ts +8 -0
  26. package/lib/types/ride/base/types.d.ts +3 -0
  27. package/lib/types/ride/display/service.d.ts +15 -0
  28. package/lib/types/ride/index.d.ts +1 -0
  29. package/lib/types/ride/page/service.d.ts +10 -0
  30. package/lib/types/ride/page/types.d.ts +10 -0
  31. package/lib/types/ride/route/GpxDisplayService.d.ts +5 -0
  32. package/lib/types/ride/view-restriction/index.d.ts +2 -0
  33. package/lib/types/ride/view-restriction/service.d.ts +30 -0
  34. package/lib/types/ride/view-restriction/types.d.ts +57 -0
  35. package/lib/types/settings/display/ride/service.d.ts +1 -0
  36. package/lib/types/settings/display/ride/types.d.ts +4 -0
  37. package/package.json +3 -3
@@ -0,0 +1,221 @@
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.useRideViewRestriction = exports.RideViewRestrictionService = void 0;
38
+ const api_1 = require("../../api");
39
+ const consts_1 = require("../../apps/googleMaps/consts");
40
+ const service_1 = require("../../apps/googleMaps/service");
41
+ const decorators_1 = require("../../base/decorators");
42
+ const service_2 = require("../../base/service");
43
+ const types_1 = require("../../base/types");
44
+ const service_3 = require("../../appstate/service");
45
+ const NOTICE_OFF_STATE_KEY = 'simulatedRideViewNoticeOff';
46
+ const DIALOG_TITLE = 'Street View in simulated rides';
47
+ 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.';
48
+ const DEVICE_TEXT = 'Connect your smart trainer, power meter or speed sensor before you start. Street View then works as usual.';
49
+ const DEVICE_TEXT_MOBILE = 'To get Street View: connect your smart trainer, power meter or speed sensor before you start.';
50
+ const OWN_KEY_TEXT = `With your own key, Street View and Satellite View also work in simulated rides. ${consts_1.MAPS_KEY_TEXTS.billing}`;
51
+ const VIEW_NAMES = { sv: 'Street View', sat: 'Satellite View' };
52
+ let RideViewRestrictionService = (() => {
53
+ let _classDecorators = [types_1.Singleton];
54
+ let _classDescriptor;
55
+ let _classExtraInitializers = [];
56
+ let _classThis;
57
+ let _classSuper = service_2.IncyclistService;
58
+ let _instanceExtraInitializers = [];
59
+ let _getAppState_decorators;
60
+ let _getGoogleMaps_decorators;
61
+ let _getBindings_decorators;
62
+ var RideViewRestrictionService = class extends _classSuper {
63
+ static { _classThis = this; }
64
+ static {
65
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
66
+ _getAppState_decorators = [decorators_1.Injectable];
67
+ _getGoogleMaps_decorators = [decorators_1.Injectable];
68
+ _getBindings_decorators = [decorators_1.Injectable];
69
+ __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);
70
+ __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);
71
+ __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);
72
+ __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
73
+ RideViewRestrictionService = _classThis = _classDescriptor.value;
74
+ if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
75
+ __runInitializers(_classThis, _classExtraInitializers);
76
+ }
77
+ restriction = __runInitializers(this, _instanceExtraInitializers);
78
+ noticeState = 'inactive';
79
+ noticeId = 0;
80
+ constructor() {
81
+ super('RideViewRestriction');
82
+ }
83
+ beginRide(props) {
84
+ try {
85
+ this.restriction = undefined;
86
+ this.noticeState = 'inactive';
87
+ this.noticeId++;
88
+ if (props.simulated && !this.getGoogleMaps().hasActivePersonalApiKey()) {
89
+ this.restriction = { cause: 'simulation', preferredView: props.preferredView };
90
+ if (this.isNoticeWanted(this.restriction))
91
+ this.noticeState = 'armed';
92
+ }
93
+ this.logEvent({ message: 'ride view restriction', restricted: this.restriction !== undefined, noticeState: this.noticeState });
94
+ }
95
+ catch (err) {
96
+ this.logError(err, 'beginRide');
97
+ }
98
+ this.emit('changed');
99
+ }
100
+ onRideStarted() {
101
+ if (this.noticeState !== 'armed')
102
+ return;
103
+ this.noticeState = 'due';
104
+ this.emit('changed');
105
+ }
106
+ endRide() {
107
+ this.restriction = undefined;
108
+ this.noticeState = 'inactive';
109
+ this.emit('changed');
110
+ }
111
+ getActiveRestriction() {
112
+ return this.restriction;
113
+ }
114
+ getNotice() {
115
+ const id = this.noticeId;
116
+ if (this.noticeState === 'due' && this.restriction) {
117
+ const view = VIEW_NAMES[this.restriction.preferredView];
118
+ return {
119
+ id, state: 'message',
120
+ text: `${view} isn't available in simulated rides. Showing the Map instead.`,
121
+ actions: [
122
+ { id: 'how-to', label: `How to get ${view}` },
123
+ { id: 'dont-show-again', label: "Don't show this again" },
124
+ ]
125
+ };
126
+ }
127
+ if (this.noticeState === 'acknowledged') {
128
+ return {
129
+ id, state: 'acknowledged',
130
+ actions: [{ id: 'change-this', label: "We won't show this again. Change this" }]
131
+ };
132
+ }
133
+ return undefined;
134
+ }
135
+ onNoticeAction(id) {
136
+ if (id === 'dont-show-again') {
137
+ this.setReminderEnabled(false);
138
+ if (this.noticeState === 'due')
139
+ this.noticeState = 'acknowledged';
140
+ }
141
+ else if (this.noticeState === 'due' || this.noticeState === 'acknowledged') {
142
+ this.noticeState = 'closed';
143
+ }
144
+ this.emit('changed');
145
+ }
146
+ onNoticeClosed() {
147
+ if (this.noticeState !== 'due' && this.noticeState !== 'acknowledged')
148
+ return;
149
+ this.noticeState = 'closed';
150
+ this.emit('changed');
151
+ }
152
+ isReminderEnabled() {
153
+ return this.getAppState().getPersistedState(NOTICE_OFF_STATE_KEY) !== true;
154
+ }
155
+ setReminderEnabled(enabled) {
156
+ try {
157
+ this.getAppState().setPersistedState(NOTICE_OFF_STATE_KEY, !enabled);
158
+ }
159
+ catch (err) {
160
+ this.logError(err, 'setReminderEnabled');
161
+ }
162
+ }
163
+ getDialogProps(props = {}) {
164
+ const options = [this.getDeviceOption(props.inRide === true)];
165
+ if (!this.isMobile())
166
+ options.push(this.getOwnKeyOption());
167
+ const dialog = { title: DIALOG_TITLE, body: DIALOG_BODY, options };
168
+ if (this.restriction)
169
+ dialog.reminder = { label: 'Remind me in simulated rides', checked: this.isReminderEnabled() };
170
+ return dialog;
171
+ }
172
+ isNoticeWanted(restriction) {
173
+ return (restriction.preferredView === 'sv' || restriction.preferredView === 'sat') && this.isReminderEnabled();
174
+ }
175
+ getDeviceOption(inRide) {
176
+ const mobile = this.isMobile();
177
+ const option = {
178
+ id: 'device',
179
+ text: mobile ? DEVICE_TEXT_MOBILE : DEVICE_TEXT,
180
+ };
181
+ if (!mobile)
182
+ option.heading = 'Ride with a device';
183
+ if (inRide) {
184
+ option.discard = {
185
+ label: 'Discard ride and connect a device',
186
+ confirm: { question: 'Discard this simulated ride?', confirmLabel: 'Discard and connect', cancelLabel: 'Keep riding' }
187
+ };
188
+ }
189
+ return option;
190
+ }
191
+ getOwnKeyOption() {
192
+ const option = {
193
+ id: 'own-key',
194
+ heading: 'Or use your own Google Maps API key',
195
+ text: OWN_KEY_TEXT,
196
+ helpLink: { label: consts_1.MAPS_KEY_TEXTS.helpLabel, url: consts_1.MAPS_KEY_HELP_URL },
197
+ };
198
+ if (this.getGoogleMaps().isPersonalApiKeyPendingRestart())
199
+ option.pendingRestart = { text: consts_1.MAPS_KEY_TEXTS.pendingRestart };
200
+ else
201
+ option.addKey = { label: 'Add my key' };
202
+ return option;
203
+ }
204
+ isMobile() {
205
+ return this.getBindings()?.appInfo?.getChannel() === 'mobile';
206
+ }
207
+ getAppState() {
208
+ return (0, service_3.useAppState)();
209
+ }
210
+ getGoogleMaps() {
211
+ return (0, service_1.useGoogleMaps)();
212
+ }
213
+ getBindings() {
214
+ return (0, api_1.getBindings)();
215
+ }
216
+ };
217
+ return RideViewRestrictionService = _classThis;
218
+ })();
219
+ exports.RideViewRestrictionService = RideViewRestrictionService;
220
+ const useRideViewRestriction = () => new RideViewRestrictionService();
221
+ exports.useRideViewRestriction = useRideViewRestriction;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -39,11 +39,13 @@ const api_1 = require("../../../api");
39
39
  const decorators_1 = require("../../../base/decorators");
40
40
  const service_1 = require("../../../base/service");
41
41
  const types_1 = require("../../../base/types");
42
- const service_2 = require("../../service");
42
+ const service_2 = require("../../../ride/view-restriction/service");
43
+ const service_3 = require("../../service");
43
44
  const UNAVAILABLE_MESSAGES = {
44
45
  'need.playservices': 'Install Google Play Services to use this view',
45
46
  };
46
47
  const DEFAULT_UNAVAILABLE_MESSAGE = 'This view is currently unavailable on your device';
48
+ const SIMULATION_MESSAGE = 'Not available in simulated rides';
47
49
  let RideSettingsDisplayService = (() => {
48
50
  let _classDecorators = [decorators_1.Singleton];
49
51
  let _classDescriptor;
@@ -51,14 +53,17 @@ let RideSettingsDisplayService = (() => {
51
53
  let _classThis;
52
54
  let _classSuper = service_1.IncyclistService;
53
55
  let _instanceExtraInitializers = [];
56
+ let _getRideViewRestriction_decorators;
54
57
  let _getUserSettings_decorators;
55
58
  let _getBindings_decorators;
56
59
  var RideSettingsDisplayService = class extends _classSuper {
57
60
  static { _classThis = this; }
58
61
  static {
59
62
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
63
+ _getRideViewRestriction_decorators = [decorators_1.Injectable];
60
64
  _getUserSettings_decorators = [decorators_1.Injectable];
61
65
  _getBindings_decorators = [decorators_1.Injectable];
66
+ __esDecorate(this, null, _getRideViewRestriction_decorators, { kind: "method", name: "getRideViewRestriction", static: false, private: false, access: { has: obj => "getRideViewRestriction" in obj, get: obj => obj.getRideViewRestriction }, metadata: _metadata }, null, _instanceExtraInitializers);
62
67
  __esDecorate(this, null, _getUserSettings_decorators, { kind: "method", name: "getUserSettings", static: false, private: false, access: { has: obj => "getUserSettings" in obj, get: obj => obj.getUserSettings }, metadata: _metadata }, null, _instanceExtraInitializers);
63
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);
64
69
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
@@ -84,11 +89,17 @@ let RideSettingsDisplayService = (() => {
84
89
  delete this.observer;
85
90
  }
86
91
  getDisplayProps() {
87
- return {
88
- rideView: this.getRideView(),
92
+ const restriction = this.getRideViewRestriction().getActiveRestriction();
93
+ const props = {
94
+ rideView: restriction ? 'map' : this.getRideView(),
89
95
  rideViewOptions: this.getRideViewOptions(),
90
96
  ...this.getVideoOptions()
91
97
  };
98
+ if (restriction) {
99
+ const view = restriction.preferredView === 'sat' ? 'Satellite View' : 'Street View';
100
+ props.rideViewHelp = { label: `How to get ${view}` };
101
+ }
102
+ return props;
92
103
  }
93
104
  setRideView(rideView) {
94
105
  try {
@@ -137,6 +148,10 @@ let RideSettingsDisplayService = (() => {
137
148
  map.set(key, { label, disabled: true, message });
138
149
  return;
139
150
  }
151
+ if (this.getRideViewRestriction().getActiveRestriction()) {
152
+ map.set(key, { label, disabled: true, message: SIMULATION_MESSAGE, reason: 'simulation' });
153
+ return;
154
+ }
140
155
  map.set(key, { label });
141
156
  }
142
157
  isMobile() {
@@ -148,8 +163,11 @@ let RideSettingsDisplayService = (() => {
148
163
  isIOS() {
149
164
  return this.getBindings().appInfo?.getOS()?.platform === 'ios';
150
165
  }
166
+ getRideViewRestriction() {
167
+ return (0, service_2.useRideViewRestriction)();
168
+ }
151
169
  getUserSettings() {
152
- return (0, service_2.useUserSettings)();
170
+ return (0, service_3.useUserSettings)();
153
171
  }
154
172
  getBindings() {
155
173
  return (0, api_1.getBindings)();
@@ -0,0 +1,7 @@
1
+ export const MAPS_KEY_HELP_URL = 'https://incyclist.com/maps-api-key/';
2
+ export const MAPS_KEY_TEXTS = {
3
+ ownKey: 'your own Google Maps API key',
4
+ billing: 'Google then bills each ride that uses them to your own Google account.',
5
+ pendingRestart: 'Saved. Restart Incyclist to use it.',
6
+ helpLabel: 'How to create a key',
7
+ };
@@ -1 +1,2 @@
1
1
  export * from './service';
2
+ export * from './consts';
@@ -47,20 +47,24 @@ let GoogleMapsService = (() => {
47
47
  let _instanceExtraInitializers = [];
48
48
  let _getSecretBindings_decorators;
49
49
  let _getUserSettings_decorators;
50
+ let _getBindings_decorators;
50
51
  var GoogleMapsService = class extends _classSuper {
51
52
  static { _classThis = this; }
52
53
  static {
53
54
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
54
55
  _getSecretBindings_decorators = [Injectable];
55
56
  _getUserSettings_decorators = [Injectable];
57
+ _getBindings_decorators = [Injectable];
56
58
  __esDecorate(this, null, _getSecretBindings_decorators, { kind: "method", name: "getSecretBindings", static: false, private: false, access: { has: obj => "getSecretBindings" in obj, get: obj => obj.getSecretBindings }, metadata: _metadata }, null, _instanceExtraInitializers);
57
59
  __esDecorate(this, null, _getUserSettings_decorators, { kind: "method", name: "getUserSettings", static: false, private: false, access: { has: obj => "getUserSettings" in obj, get: obj => obj.getUserSettings }, metadata: _metadata }, null, _instanceExtraInitializers);
60
+ __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);
58
61
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
59
62
  GoogleMapsService = _classThis = _classDescriptor.value;
60
63
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
61
64
  __runInitializers(_classThis, _classExtraInitializers);
62
65
  }
63
66
  api = __runInitializers(this, _instanceExtraInitializers);
67
+ latchedKey;
64
68
  constructor() {
65
69
  super('GoogleMaps');
66
70
  const observer = this.getUserSettings().requestNotifyOnChange?.('maps', 'GOOGLE_MAPS_API_KEY');
@@ -81,6 +85,7 @@ let GoogleMapsService = (() => {
81
85
  const settings = this.getUserSettings();
82
86
  const personalKey = settings.getValue('GOOGLE_MAPS_API_KEY', undefined);
83
87
  const developmentMode = settings.get('mode', 'production') === 'development';
88
+ this.latchPersonalKey(personalKey);
84
89
  if (developmentMode)
85
90
  return personalKey ?? 'development';
86
91
  return personalKey;
@@ -90,8 +95,33 @@ let GoogleMapsService = (() => {
90
95
  const personalKey = settings.get('GOOGLE_MAPS_API_KEY', undefined);
91
96
  return personalKey !== undefined;
92
97
  }
98
+ hasActivePersonalApiKey() {
99
+ try {
100
+ if (this.isMobile())
101
+ return false;
102
+ this.latchPersonalKey(this.readPersonalKey());
103
+ return this.latchedKey !== '';
104
+ }
105
+ catch (err) {
106
+ this.logError(err, 'hasActivePersonalApiKey');
107
+ return false;
108
+ }
109
+ }
110
+ isPersonalApiKeyPendingRestart() {
111
+ try {
112
+ if (this.isMobile())
113
+ return false;
114
+ this.latchPersonalKey(this.readPersonalKey());
115
+ const current = this.normalizeKey(this.readPersonalKey());
116
+ return current !== '' && current !== this.latchedKey;
117
+ }
118
+ catch (err) {
119
+ this.logError(err, 'isPersonalApiKeyPendingRestart');
120
+ return false;
121
+ }
122
+ }
93
123
  onPersonalApiKeySet() {
94
- this.emit('reload');
124
+ this.reload();
95
125
  }
96
126
  hasDevelopmentApiKey() {
97
127
  const settings = this.getUserSettings();
@@ -107,6 +137,18 @@ let GoogleMapsService = (() => {
107
137
  this.emit('reload');
108
138
  }
109
139
  }
140
+ readPersonalKey() {
141
+ return this.getUserSettings().getValue('GOOGLE_MAPS_API_KEY', undefined);
142
+ }
143
+ normalizeKey(key) {
144
+ return typeof key === 'string' ? key.trim() : '';
145
+ }
146
+ latchPersonalKey(key) {
147
+ this.latchedKey ??= this.normalizeKey(key);
148
+ }
149
+ isMobile() {
150
+ return this.getBindings()?.appInfo?.getChannel() === 'mobile';
151
+ }
110
152
  getSecret(key) {
111
153
  return this.getSecretBindings()?.getSecret(key);
112
154
  }
@@ -116,6 +158,9 @@ let GoogleMapsService = (() => {
116
158
  getUserSettings() {
117
159
  return useUserSettings();
118
160
  }
161
+ getBindings() {
162
+ return getBindings();
163
+ }
119
164
  };
120
165
  return GoogleMapsService = _classThis;
121
166
  })();
@@ -51,6 +51,7 @@ import { WorkoutDisplayService } from "../workout/WorkoutDisplayService";
51
51
  import { getBindings } from "../../api";
52
52
  import { RLVDisplayService } from "../route/RLVDisplayService";
53
53
  import { getCoachesService } from "../../coaches";
54
+ import { useRideViewRestriction } from "../view-restriction/service";
54
55
  let RideDisplayService = (() => {
55
56
  let _classDecorators = [Singleton];
56
57
  let _classDescriptor;
@@ -67,6 +68,7 @@ let RideDisplayService = (() => {
67
68
  let _getDeviceConfiguration_decorators;
68
69
  let _getUIBinding_decorators;
69
70
  let _getCoaches_decorators;
71
+ let _getRideViewRestriction_decorators;
70
72
  let _getPairingVisitTracker_decorators;
71
73
  var RideDisplayService = class extends _classSuper {
72
74
  static { _classThis = this; }
@@ -81,6 +83,7 @@ let RideDisplayService = (() => {
81
83
  _getDeviceConfiguration_decorators = [Injectable];
82
84
  _getUIBinding_decorators = [Injectable];
83
85
  _getCoaches_decorators = [Injectable];
86
+ _getRideViewRestriction_decorators = [Injectable];
84
87
  _getPairingVisitTracker_decorators = [Injectable];
85
88
  __esDecorate(this, null, _getActivityRide_decorators, { kind: "method", name: "getActivityRide", static: false, private: false, access: { has: obj => "getActivityRide" in obj, get: obj => obj.getActivityRide }, metadata: _metadata }, null, _instanceExtraInitializers);
86
89
  __esDecorate(this, null, _getWorkoutRide_decorators, { kind: "method", name: "getWorkoutRide", static: false, private: false, access: { has: obj => "getWorkoutRide" in obj, get: obj => obj.getWorkoutRide }, metadata: _metadata }, null, _instanceExtraInitializers);
@@ -91,6 +94,7 @@ let RideDisplayService = (() => {
91
94
  __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);
92
95
  __esDecorate(this, null, _getUIBinding_decorators, { kind: "method", name: "getUIBinding", static: false, private: false, access: { has: obj => "getUIBinding" in obj, get: obj => obj.getUIBinding }, metadata: _metadata }, null, _instanceExtraInitializers);
93
96
  __esDecorate(this, null, _getCoaches_decorators, { kind: "method", name: "getCoaches", static: false, private: false, access: { has: obj => "getCoaches" in obj, get: obj => obj.getCoaches }, metadata: _metadata }, null, _instanceExtraInitializers);
97
+ __esDecorate(this, null, _getRideViewRestriction_decorators, { kind: "method", name: "getRideViewRestriction", static: false, private: false, access: { has: obj => "getRideViewRestriction" in obj, get: obj => obj.getRideViewRestriction }, metadata: _metadata }, null, _instanceExtraInitializers);
94
98
  __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);
95
99
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
96
100
  RideDisplayService = _classThis = _classDescriptor.value;
@@ -112,6 +116,7 @@ let RideDisplayService = (() => {
112
116
  startDeviceHandlers;
113
117
  isResuming;
114
118
  stateUpdateHandler = this.onStateUpdate.bind(this);
119
+ discarding = false;
115
120
  controlDevicesReadyNotified = false;
116
121
  constructor() {
117
122
  super('RideDisplay');
@@ -292,6 +297,60 @@ let RideDisplayService = (() => {
292
297
  this.getActivityRide().cleanup().catch(err => { this.logError(err, 'stop'); });
293
298
  this.getCoaches().stopRide().catch(err => { this.logError(err, 'stop'); });
294
299
  }
300
+ async discardSimulatedRide() {
301
+ if (this.discarding)
302
+ return false;
303
+ try {
304
+ if (!this.isSimulated()) {
305
+ this.logError(new Error('not a simulated ride'), 'discardSimulatedRide');
306
+ return false;
307
+ }
308
+ this.discarding = true;
309
+ const selection = this.getRideSelection();
310
+ await this.deleteActivityOnDiscard();
311
+ await this.stop();
312
+ const restored = this.restoreRideSelection(selection);
313
+ this.logEvent({ message: 'simulated ride discarded', restored });
314
+ return restored;
315
+ }
316
+ catch (err) {
317
+ this.logError(err, 'discardSimulatedRide');
318
+ return false;
319
+ }
320
+ finally {
321
+ this.discarding = false;
322
+ }
323
+ }
324
+ onRideViewNoticeAction(id) {
325
+ try {
326
+ this.getRideViewRestriction().onNoticeAction(id);
327
+ this.observer?.emit('overlay-update', this.getDisplayProperties());
328
+ }
329
+ catch (err) {
330
+ this.logError(err, 'onRideViewNoticeAction');
331
+ }
332
+ }
333
+ onRideViewNoticeClosed() {
334
+ try {
335
+ this.getRideViewRestriction().onNoticeClosed();
336
+ this.observer?.emit('overlay-update', this.getDisplayProperties());
337
+ }
338
+ catch (err) {
339
+ this.logError(err, 'onRideViewNoticeClosed');
340
+ }
341
+ }
342
+ setRideViewReminder(enabled) {
343
+ try {
344
+ this.getRideViewRestriction().setReminderEnabled(enabled);
345
+ }
346
+ catch (err) {
347
+ this.logError(err, 'setRideViewReminder');
348
+ }
349
+ }
350
+ getRideViewRestrictionDialogProps() {
351
+ const inRide = this.isSimulated() && (this.state === 'Started' || this.state === 'Active' || this.state === 'Paused');
352
+ return this.getRideViewRestriction().getDialogProps({ inRide });
353
+ }
295
354
  toggleCyclingMode() {
296
355
  try {
297
356
  if (!this.actualWorkout) {
@@ -520,6 +579,39 @@ let RideDisplayService = (() => {
520
579
  this.logError(err, 'init');
521
580
  }
522
581
  }
582
+ getRideSelection() {
583
+ const routeList = this.getRouteList();
584
+ return {
585
+ route: routeList.getSelected(),
586
+ startSettings: routeList.getStartSettings(),
587
+ workout: this.getWorkoutList().getSelected()
588
+ };
589
+ }
590
+ async deleteActivityOnDiscard() {
591
+ try {
592
+ await this.getActivityRide().delete();
593
+ }
594
+ catch (err) {
595
+ this.logError(err, 'discardSimulatedRide');
596
+ }
597
+ }
598
+ restoreRideSelection(selection) {
599
+ try {
600
+ const { route, startSettings, workout } = selection;
601
+ const routeList = this.getRouteList();
602
+ if (route)
603
+ routeList.select(route);
604
+ if (startSettings)
605
+ routeList.setStartSettings(startSettings);
606
+ if (workout)
607
+ this.getWorkoutList().select(workout);
608
+ return true;
609
+ }
610
+ catch (err) {
611
+ this.logError(err, 'discardSimulatedRide');
612
+ return false;
613
+ }
614
+ }
523
615
  setState(state) {
524
616
  this.state = state;
525
617
  this.observer?.emit('state-update', this.state);
@@ -1189,6 +1281,9 @@ let RideDisplayService = (() => {
1189
1281
  getCoaches() {
1190
1282
  return getCoachesService();
1191
1283
  }
1284
+ getRideViewRestriction() {
1285
+ return useRideViewRestriction();
1286
+ }
1192
1287
  getPairingVisitTracker() {
1193
1288
  return usePairingVisitTracker();
1194
1289
  }
@@ -1,3 +1,4 @@
1
1
  export * from './base';
2
2
  export * from './display';
3
3
  export * from './page';
4
+ export * from './view-restriction';