incyclist-services 1.9.12 → 1.9.14

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 (51) hide show
  1. package/lib/cjs/activities/active-rides/service.js +65 -45
  2. package/lib/cjs/activities/list/service.js +15 -5
  3. package/lib/cjs/apps/googleMaps/consts.js +10 -0
  4. package/lib/cjs/apps/googleMaps/index.js +1 -0
  5. package/lib/cjs/apps/googleMaps/service.js +46 -1
  6. package/lib/cjs/devices/ride/service.js +25 -9
  7. package/lib/cjs/i18n/countries/service.js +17 -9
  8. package/lib/cjs/ride/display/service.js +95 -0
  9. package/lib/cjs/ride/index.js +1 -0
  10. package/lib/cjs/ride/page/service.js +69 -1
  11. package/lib/cjs/ride/route/GpxDisplayService.js +46 -1
  12. package/lib/cjs/ride/view-restriction/index.js +18 -0
  13. package/lib/cjs/ride/view-restriction/service.js +221 -0
  14. package/lib/cjs/ride/view-restriction/types.js +2 -0
  15. package/lib/cjs/routes/base/api/api.js +9 -0
  16. package/lib/cjs/settings/display/ride/service.js +22 -4
  17. package/lib/esm/activities/active-rides/service.js +65 -45
  18. package/lib/esm/activities/list/service.js +15 -5
  19. package/lib/esm/apps/googleMaps/consts.js +7 -0
  20. package/lib/esm/apps/googleMaps/index.js +1 -0
  21. package/lib/esm/apps/googleMaps/service.js +46 -1
  22. package/lib/esm/devices/ride/service.js +25 -9
  23. package/lib/esm/i18n/countries/service.js +17 -9
  24. package/lib/esm/ride/display/service.js +95 -0
  25. package/lib/esm/ride/index.js +1 -0
  26. package/lib/esm/ride/page/service.js +69 -1
  27. package/lib/esm/ride/route/GpxDisplayService.js +46 -1
  28. package/lib/esm/ride/view-restriction/index.js +2 -0
  29. package/lib/esm/ride/view-restriction/service.js +217 -0
  30. package/lib/esm/ride/view-restriction/types.js +1 -0
  31. package/lib/esm/routes/base/api/api.js +9 -0
  32. package/lib/esm/settings/display/ride/service.js +20 -2
  33. package/lib/types/activities/active-rides/service.d.ts +11 -0
  34. package/lib/types/activities/list/service.d.ts +1 -0
  35. package/lib/types/apps/googleMaps/consts.d.ts +7 -0
  36. package/lib/types/apps/googleMaps/index.d.ts +1 -0
  37. package/lib/types/apps/googleMaps/service.d.ts +8 -0
  38. package/lib/types/devices/ride/service.d.ts +2 -0
  39. package/lib/types/i18n/countries/service.d.ts +1 -0
  40. package/lib/types/ride/base/types.d.ts +3 -0
  41. package/lib/types/ride/display/service.d.ts +15 -0
  42. package/lib/types/ride/index.d.ts +1 -0
  43. package/lib/types/ride/page/service.d.ts +10 -0
  44. package/lib/types/ride/page/types.d.ts +10 -0
  45. package/lib/types/ride/route/GpxDisplayService.d.ts +5 -0
  46. package/lib/types/ride/view-restriction/index.d.ts +2 -0
  47. package/lib/types/ride/view-restriction/service.d.ts +30 -0
  48. package/lib/types/ride/view-restriction/types.d.ts +57 -0
  49. package/lib/types/settings/display/ride/service.d.ts +1 -0
  50. package/lib/types/settings/display/ride/types.d.ts +4 -0
  51. package/package.json +4 -4
@@ -48,6 +48,8 @@ const utils_1 = require("../../utils");
48
48
  const active_rides_1 = require("../base/api/active-rides");
49
49
  const ride_1 = require("../ride");
50
50
  const mq_1 = require("./mq");
51
+ const LOOKUP_BACKOFF_START = 30_000;
52
+ const LOOKUP_BACKOFF_MAX = 300_000;
51
53
  let ActiveRidesService = (() => {
52
54
  let _classDecorators = [types_1.Singleton];
53
55
  let _classDescriptor;
@@ -101,6 +103,8 @@ let ActiveRidesService = (() => {
101
103
  routesStats = [];
102
104
  routeListSessions = new Map();
103
105
  isSubscribedRouteListEvents = false;
106
+ lookupsInFlight = new Map();
107
+ lookupBackoff = new Map();
104
108
  activityEventHandlers = {
105
109
  update: this.onActivityUpdateEvent.bind(this),
106
110
  start: this.onActivityStartEvent.bind(this),
@@ -762,7 +766,8 @@ let ActiveRidesService = (() => {
762
766
  this.logEvent({ message: 'group ride user joined', active: this.others.length + 1, activityId: this.activity?.id, route: this.activity.route?.title, routeHash: this.getRouteHash(), remote });
763
767
  }
764
768
  if (!payload.user) {
765
- this.getRemoteActivityDetails(session).catch(err => { this.logError(err, 'onActivityStartEvent'); });
769
+ this.lookupRemoteRider(session).then(resolved => { if (resolved)
770
+ this.observer?.emit('update', this.getDisplayProps()); }).catch(err => { this.logError(err, 'onActivityStartEvent'); });
766
771
  }
767
772
  this.observer.emit('update', this.getDisplayProps());
768
773
  }
@@ -788,9 +793,6 @@ let ActiveRidesService = (() => {
788
793
  localItem.bike = item.bike;
789
794
  localItem.ride = item.ride;
790
795
  }
791
- else {
792
- this.addActiveRide(item);
793
- }
794
796
  return item;
795
797
  }
796
798
  publishUpdateEvent(payload) {
@@ -803,50 +805,64 @@ let ActiveRidesService = (() => {
803
805
  try {
804
806
  if (session === this.session)
805
807
  return;
806
- const others = this.others ?? [];
807
- const existing = others.find(ar => ar.sessionId === session);
808
808
  const prevActive = this.others?.length;
809
- if (existing?.user) {
810
- existing.currentPosition = payload.position;
811
- existing.currentDuration = payload.duration;
812
- existing.currentPower = payload.power;
813
- existing.currentRideDistance = payload.rideDistance;
814
- existing.currentSpeed = payload.speed;
815
- existing.currentLap = payload.lap;
816
- existing.tsLastUpdate = Date.now();
817
- }
818
- else {
819
- const item = await this.getRemoteActivityDetails(session);
820
- if (!item) {
821
- const entry = {
822
- id: Date.now().toString(),
823
- tsLastUpdate: Date.now(),
824
- sessionId: session,
825
- currentPosition: payload.position,
826
- currentDuration: payload.duration,
827
- currentPower: payload.power,
828
- currentRideDistance: payload.rideDistance,
829
- currentSpeed: payload.speed,
830
- currentLap: payload.lap
831
- };
832
- if (!existing) {
833
- this.addActiveRide(entry);
834
- }
835
- }
809
+ let existing = (this.others ?? []).find(ar => ar.sessionId === session);
810
+ const isNew = !existing;
811
+ if (!existing) {
812
+ existing = { id: Date.now().toString(), sessionId: session };
813
+ this.addActiveRide(existing);
836
814
  this.isStarted = true;
837
- const remote = (item === undefined || item === null) ? { session } : { uuid: item.user?.id, session: item.sessionId };
838
- if (prevActive === 0) {
839
- this.logEvent({ message: 'group ride started', active: this.others.length + 1, activityId: this.activity?.id, route: this.activity.route?.title, routeHash: this.getRouteHash(), remote });
840
- }
841
- else {
842
- this.logEvent({ message: 'group ride user joined', active: this.others.length + 1, activityId: this.activity?.id, route: this.activity.route?.title, routeHash: this.getRouteHash(), remote });
843
- }
844
815
  }
816
+ this.applyLiveData(existing, payload);
817
+ if (isNew)
818
+ this.logJoined(prevActive, { session });
845
819
  this.observer.emit('update', this.getDisplayProps());
820
+ if (!existing.user) {
821
+ const resolved = await this.lookupRemoteRider(session);
822
+ if (resolved)
823
+ this.observer.emit('update', this.getDisplayProps());
824
+ }
846
825
  }
847
826
  catch (err) {
848
- this.logError(err, 'onActivityStartEvent');
849
- }
827
+ this.logError(err, 'onActivityUpdateEvent');
828
+ }
829
+ }
830
+ applyLiveData(entry, payload) {
831
+ entry.currentPosition = payload.position;
832
+ entry.currentDuration = payload.duration;
833
+ entry.currentPower = payload.power;
834
+ entry.currentRideDistance = payload.rideDistance;
835
+ entry.currentSpeed = payload.speed;
836
+ entry.currentLap = payload.lap;
837
+ entry.tsLastUpdate = Date.now();
838
+ }
839
+ logJoined(prevActive, remote) {
840
+ const message = prevActive === 0 ? 'group ride started' : 'group ride user joined';
841
+ this.logEvent({ message, active: this.others.length + 1, activityId: this.activity?.id, route: this.activity?.route?.title, routeHash: this.getRouteHash(), remote });
842
+ }
843
+ async lookupRemoteRider(session) {
844
+ const inFlight = this.lookupsInFlight.get(session);
845
+ if (inFlight !== undefined)
846
+ return inFlight;
847
+ const backoff = this.lookupBackoff.get(session);
848
+ if (backoff && Date.now() < backoff.until)
849
+ return false;
850
+ const promise = this.getRemoteActivityDetails(session)
851
+ .then(item => item?.user !== undefined && item?.user !== null)
852
+ .catch(err => { this.logError(err, 'lookupRemoteRider'); return false; })
853
+ .then(resolved => {
854
+ if (resolved) {
855
+ this.lookupBackoff.delete(session);
856
+ }
857
+ else {
858
+ const delay = Math.min((backoff?.delay ?? LOOKUP_BACKOFF_START / 2) * 2, LOOKUP_BACKOFF_MAX);
859
+ this.lookupBackoff.set(session, { delay, until: Date.now() + delay });
860
+ }
861
+ return resolved;
862
+ })
863
+ .finally(() => { this.lookupsInFlight.delete(session); });
864
+ this.lookupsInFlight.set(session, promise);
865
+ return promise;
850
866
  }
851
867
  addActiveRide(ride) {
852
868
  if (!this.others)
@@ -864,10 +880,11 @@ let ActiveRidesService = (() => {
864
880
  return;
865
881
  if (!this.others?.length)
866
882
  return;
867
- const idx = this.others.findIndex(ar => ar.sessionId === session);
868
- if (idx === -1)
883
+ const remaining = this.others.filter(ar => ar.sessionId !== session);
884
+ if (remaining.length === this.others.length)
869
885
  return;
870
- this.others.splice(idx, 1);
886
+ this.others = remaining;
887
+ this.lookupBackoff.delete(session);
871
888
  this.observer.emit('update', this.getDisplayProps());
872
889
  if (!this.isStarted)
873
890
  return;
@@ -909,6 +926,9 @@ let ActiveRidesService = (() => {
909
926
  this.isStarted = false;
910
927
  this.getMessageQueue().unsubscribeAll();
911
928
  this.isSubscribed = false;
929
+ this.isSubscribedRouteListEvents = false;
930
+ this.lookupsInFlight.clear();
931
+ this.lookupBackoff.clear();
912
932
  this.observer.stop();
913
933
  }
914
934
  getOnlineStatusMonitoring() {
@@ -262,8 +262,7 @@ let ActivityListService = (() => {
262
262
  await activity.load();
263
263
  return new Promise(done => {
264
264
  const emitUpdate = async (update) => {
265
- this.exports = await this.selected.getExports();
266
- this.emitSelected('updated');
265
+ await this.refreshExports();
267
266
  if (update.status === 'done')
268
267
  done(update.success);
269
268
  };
@@ -287,9 +286,8 @@ let ActivityListService = (() => {
287
286
  }
288
287
  }
289
288
  };
290
- const emitExportUpdate = async (update) => {
291
- this.exports = await this.selected.getExports();
292
- this.emitSelected('updated');
289
+ const emitExportUpdate = async () => {
290
+ await this.refreshExports();
293
291
  };
294
292
  const observer = new observer_1.Observer();
295
293
  observer.on('upload', emitUploadUpdate);
@@ -431,7 +429,19 @@ let ActivityListService = (() => {
431
429
  };
432
430
  return props;
433
431
  }
432
+ async refreshExports() {
433
+ const selected = this.selected;
434
+ if (!selected)
435
+ return;
436
+ const exports = await selected.getExports();
437
+ if (!this.selected)
438
+ return;
439
+ this.exports = exports;
440
+ this.emitSelected('updated');
441
+ }
434
442
  emitSelected(event) {
443
+ if (!this.selected)
444
+ return;
435
445
  const displayProps = this.getSelectedActivityDisplayProps();
436
446
  this.getObserver()?.emit(event, displayProps);
437
447
  }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MAPS_KEY_TEXTS = exports.MAPS_KEY_HELP_URL = void 0;
4
+ exports.MAPS_KEY_HELP_URL = 'https://incyclist.com/maps-api-key/';
5
+ exports.MAPS_KEY_TEXTS = {
6
+ ownKey: 'your own Google Maps API key',
7
+ billing: 'Google then bills each ride that uses them to your own Google account.',
8
+ pendingRestart: 'Saved. Restart Incyclist to use it.',
9
+ helpLabel: 'How to create a key',
10
+ };
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./service"), exports);
18
+ __exportStar(require("./consts"), exports);
@@ -50,20 +50,24 @@ let GoogleMapsService = (() => {
50
50
  let _instanceExtraInitializers = [];
51
51
  let _getSecretBindings_decorators;
52
52
  let _getUserSettings_decorators;
53
+ let _getBindings_decorators;
53
54
  var GoogleMapsService = class extends _classSuper {
54
55
  static { _classThis = this; }
55
56
  static {
56
57
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
57
58
  _getSecretBindings_decorators = [decorators_1.Injectable];
58
59
  _getUserSettings_decorators = [decorators_1.Injectable];
60
+ _getBindings_decorators = [decorators_1.Injectable];
59
61
  __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);
60
62
  __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
+ __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);
61
64
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
62
65
  GoogleMapsService = _classThis = _classDescriptor.value;
63
66
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
64
67
  __runInitializers(_classThis, _classExtraInitializers);
65
68
  }
66
69
  api = __runInitializers(this, _instanceExtraInitializers);
70
+ latchedKey;
67
71
  constructor() {
68
72
  super('GoogleMaps');
69
73
  const observer = this.getUserSettings().requestNotifyOnChange?.('maps', 'GOOGLE_MAPS_API_KEY');
@@ -84,6 +88,7 @@ let GoogleMapsService = (() => {
84
88
  const settings = this.getUserSettings();
85
89
  const personalKey = settings.getValue('GOOGLE_MAPS_API_KEY', undefined);
86
90
  const developmentMode = settings.get('mode', 'production') === 'development';
91
+ this.latchPersonalKey(personalKey);
87
92
  if (developmentMode)
88
93
  return personalKey ?? 'development';
89
94
  return personalKey;
@@ -93,8 +98,33 @@ let GoogleMapsService = (() => {
93
98
  const personalKey = settings.get('GOOGLE_MAPS_API_KEY', undefined);
94
99
  return personalKey !== undefined;
95
100
  }
101
+ hasActivePersonalApiKey() {
102
+ try {
103
+ if (this.isMobile())
104
+ return false;
105
+ this.latchPersonalKey(this.readPersonalKey());
106
+ return this.latchedKey !== '';
107
+ }
108
+ catch (err) {
109
+ this.logError(err, 'hasActivePersonalApiKey');
110
+ return false;
111
+ }
112
+ }
113
+ isPersonalApiKeyPendingRestart() {
114
+ try {
115
+ if (this.isMobile())
116
+ return false;
117
+ this.latchPersonalKey(this.readPersonalKey());
118
+ const current = this.normalizeKey(this.readPersonalKey());
119
+ return current !== '' && current !== this.latchedKey;
120
+ }
121
+ catch (err) {
122
+ this.logError(err, 'isPersonalApiKeyPendingRestart');
123
+ return false;
124
+ }
125
+ }
96
126
  onPersonalApiKeySet() {
97
- this.emit('reload');
127
+ this.reload();
98
128
  }
99
129
  hasDevelopmentApiKey() {
100
130
  const settings = this.getUserSettings();
@@ -110,6 +140,18 @@ let GoogleMapsService = (() => {
110
140
  this.emit('reload');
111
141
  }
112
142
  }
143
+ readPersonalKey() {
144
+ return this.getUserSettings().getValue('GOOGLE_MAPS_API_KEY', undefined);
145
+ }
146
+ normalizeKey(key) {
147
+ return typeof key === 'string' ? key.trim() : '';
148
+ }
149
+ latchPersonalKey(key) {
150
+ this.latchedKey ??= this.normalizeKey(key);
151
+ }
152
+ isMobile() {
153
+ return this.getBindings()?.appInfo?.getChannel() === 'mobile';
154
+ }
113
155
  getSecret(key) {
114
156
  return this.getSecretBindings()?.getSecret(key);
115
157
  }
@@ -119,6 +161,9 @@ let GoogleMapsService = (() => {
119
161
  getUserSettings() {
120
162
  return (0, settings_1.useUserSettings)();
121
163
  }
164
+ getBindings() {
165
+ return (0, api_1.getBindings)();
166
+ }
122
167
  };
123
168
  return GoogleMapsService = _classThis;
124
169
  })();
@@ -82,6 +82,7 @@ let DeviceRideService = (() => {
82
82
  initizialized = __runInitializers(this, _instanceExtraInitializers);
83
83
  adapters;
84
84
  rideAdapters;
85
+ healthChecks = new Set();
85
86
  startPromises;
86
87
  data = {};
87
88
  simulatorEnforced;
@@ -702,7 +703,7 @@ let DeviceRideService = (() => {
702
703
  ai.dataStatus = 'amber';
703
704
  if (isRed)
704
705
  ai.dataStatus = 'red';
705
- if (ai.isHealthy && (isAmber || isRed)) {
706
+ if (ai.isHealthy && (isAmber || isRed) && !ai.adapter.isReconnecting?.()) {
706
707
  ai.isHealthy = false;
707
708
  this.logEvent({ message: 'device unhealthy', device: ai.adapter.getUniqueName(), udid: ai.udid, noDataSince: (tsNow - tsLastData), tsLastData: new Date(tsLastData).toISOString() });
708
709
  this.prepareReconnect(ai).catch(err => { this.logError(err, 'startHealthCheck'); });
@@ -723,6 +724,7 @@ let DeviceRideService = (() => {
723
724
  if (ai.adapter.getInterface() === 'simulator')
724
725
  return;
725
726
  ai.ivToCheck = setInterval(() => { check(); }, 1000);
727
+ this.healthChecks.add(ai);
726
728
  ai.isHealthy = true;
727
729
  ai.isRestarting = false;
728
730
  if (ai.dataStatus !== undefined && ai.dataStatus !== 'green') {
@@ -747,6 +749,7 @@ let DeviceRideService = (() => {
747
749
  clearInterval(ai.ivToCheck);
748
750
  delete ai.ivToCheck;
749
751
  delete ai.isHealthy;
752
+ this.healthChecks.delete(ai);
750
753
  this.removeOnDatahandler(ai);
751
754
  this.lastDataInfo = {};
752
755
  }
@@ -760,16 +763,20 @@ let DeviceRideService = (() => {
760
763
  this.logEvent({ message: 'skipped reconnect - device already restarting', device: unhealthy.adapter.getUniqueName(), udid: unhealthy.udid, noDataSince: (tsNow - tsLastData), tsLastData: tsLastDataStr });
761
764
  return;
762
765
  }
766
+ if (unhealthy.adapter.isReconnecting?.()) {
767
+ this.logEvent({ message: 'skipped reconnect - device is reconnecting', device: unhealthy.adapter.getUniqueName(), udid: unhealthy.udid, noDataSince: (tsNow - tsLastData), tsLastData: tsLastDataStr });
768
+ return;
769
+ }
763
770
  unhealthy.isRestarting = true;
764
771
  unhealthy.isHealthy = false;
765
- const ifName = unhealthy.adapter.getInterface();
766
- const adapters = this.rideAdapters?.filter(ai => ai.adapter.getInterface() === ifName);
767
- const stillHealthy = adapters.filter(ai => ai.isHealthy === undefined || ai.isHealthy === true);
768
- this.logEvent({ message: 'reconnect confirmed', device: unhealthy.adapter.getUniqueName(), udid: unhealthy.udid,
769
- noDataSince: (tsNow - tsLastData),
770
- tsLastData: tsLastDataStr, stillHealthy: stillHealthy?.length, onSameInterface: adapters.length });
771
772
  try {
772
- if (!stillHealthy?.length && adapters.length > 1 && ifName !== 'ble') {
773
+ const ifName = unhealthy.adapter.getInterface();
774
+ const adapters = (this.rideAdapters ?? [unhealthy]).filter(ai => ai.adapter.getInterface() === ifName);
775
+ const stillHealthy = adapters.filter(ai => ai.isHealthy === undefined || ai.isHealthy === true);
776
+ this.logEvent({ message: 'reconnect confirmed', device: unhealthy.adapter.getUniqueName(), udid: unhealthy.udid,
777
+ noDataSince: (tsNow - tsLastData),
778
+ tsLastData: tsLastDataStr, stillHealthy: stillHealthy.length, onSameInterface: adapters.length });
779
+ if (!stillHealthy.length && adapters.length > 1 && ifName !== 'ble') {
773
780
  await this.reconnectInterface(ifName, adapters);
774
781
  }
775
782
  else {
@@ -779,7 +786,9 @@ let DeviceRideService = (() => {
779
786
  catch (err) {
780
787
  this.logError(err, 'prepareReconnect');
781
788
  }
782
- unhealthy.isRestarting = false;
789
+ finally {
790
+ unhealthy.isRestarting = false;
791
+ }
783
792
  }
784
793
  async reconnectInterface(ifName, adapters) {
785
794
  if (this.reconnectBusy) {
@@ -1003,6 +1012,7 @@ let DeviceRideService = (() => {
1003
1012
  this.logEvent({ message: 'stop device', udid });
1004
1013
  const adapters = this.rideAdapters;
1005
1014
  this.emit('stop-ride');
1015
+ this.stopHealthChecks(udid);
1006
1016
  const promises = adapters?.filter(ai => udid ? ai.udid === udid : true)
1007
1017
  .map(ai => {
1008
1018
  this.stopHealthCheck(ai);
@@ -1015,6 +1025,12 @@ let DeviceRideService = (() => {
1015
1025
  this.simulatorEnforced = false;
1016
1026
  return true;
1017
1027
  }
1028
+ stopHealthChecks(udid) {
1029
+ for (const ai of this.healthChecks) {
1030
+ if (!udid || ai.udid === udid)
1031
+ this.stopHealthCheck(ai);
1032
+ }
1033
+ }
1018
1034
  async resetLimits() {
1019
1035
  try {
1020
1036
  const mode = this.getCyclingMode();
@@ -1,4 +1,11 @@
1
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
+ };
2
9
  var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
3
10
  function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
4
11
  var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
@@ -26,13 +33,6 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
26
33
  if (target) Object.defineProperty(target, contextIn.name, descriptor);
27
34
  done = true;
28
35
  };
29
- var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
30
- var useValue = arguments.length > 2;
31
- for (var i = 0; i < initializers.length; i++) {
32
- value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
33
- }
34
- return useValue ? value : void 0;
35
- };
36
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
@@ -40,6 +40,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
40
40
  exports.getCountries = exports.Countries = void 0;
41
41
  const service_1 = require("../../base/service");
42
42
  const types_1 = require("../../base/types");
43
+ const decorators_1 = require("../../base/decorators");
43
44
  const countries_json_1 = __importDefault(require("./countries.json"));
44
45
  const factory_1 = require("../../routes/base/api/factory");
45
46
  let Countries = (() => {
@@ -48,16 +49,20 @@ let Countries = (() => {
48
49
  let _classExtraInitializers = [];
49
50
  let _classThis;
50
51
  let _classSuper = service_1.IncyclistService;
52
+ let _instanceExtraInitializers = [];
53
+ let _getIncyclistRoutesApi_decorators;
51
54
  var Countries = class extends _classSuper {
52
55
  static { _classThis = this; }
53
56
  static {
54
57
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
58
+ _getIncyclistRoutesApi_decorators = [decorators_1.Injectable];
59
+ __esDecorate(this, null, _getIncyclistRoutesApi_decorators, { kind: "method", name: "getIncyclistRoutesApi", static: false, private: false, access: { has: obj => "getIncyclistRoutesApi" in obj, get: obj => obj.getIncyclistRoutesApi }, metadata: _metadata }, null, _instanceExtraInitializers);
55
60
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
56
61
  Countries = _classThis = _classDescriptor.value;
57
62
  if (_metadata) Object.defineProperty(_classThis, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
58
63
  __runInitializers(_classThis, _classExtraInitializers);
59
64
  }
60
- language;
65
+ language = __runInitializers(this, _instanceExtraInitializers);
61
66
  countryLists;
62
67
  constructor() {
63
68
  super('Countries');
@@ -91,9 +96,12 @@ let Countries = (() => {
91
96
  return countries.map(c => this.getIsoFromCountry(c, locale));
92
97
  }
93
98
  async getIsoFromLatLng(point) {
94
- const api = (0, factory_1.useIncyclistRoutesApi)().create();
99
+ const api = this.getIncyclistRoutesApi().create();
95
100
  return api.getCountry(point);
96
101
  }
102
+ getIncyclistRoutesApi() {
103
+ return (0, factory_1.useIncyclistRoutesApi)();
104
+ }
97
105
  };
98
106
  return Countries = _classThis;
99
107
  })();
@@ -54,6 +54,7 @@ const WorkoutDisplayService_1 = require("../workout/WorkoutDisplayService");
54
54
  const api_1 = require("../../api");
55
55
  const RLVDisplayService_1 = require("../route/RLVDisplayService");
56
56
  const coaches_1 = require("../../coaches");
57
+ const service_3 = require("../view-restriction/service");
57
58
  let RideDisplayService = (() => {
58
59
  let _classDecorators = [types_1.Singleton];
59
60
  let _classDescriptor;
@@ -70,6 +71,7 @@ let RideDisplayService = (() => {
70
71
  let _getDeviceConfiguration_decorators;
71
72
  let _getUIBinding_decorators;
72
73
  let _getCoaches_decorators;
74
+ let _getRideViewRestriction_decorators;
73
75
  let _getPairingVisitTracker_decorators;
74
76
  var RideDisplayService = class extends _classSuper {
75
77
  static { _classThis = this; }
@@ -84,6 +86,7 @@ let RideDisplayService = (() => {
84
86
  _getDeviceConfiguration_decorators = [decorators_1.Injectable];
85
87
  _getUIBinding_decorators = [decorators_1.Injectable];
86
88
  _getCoaches_decorators = [decorators_1.Injectable];
89
+ _getRideViewRestriction_decorators = [decorators_1.Injectable];
87
90
  _getPairingVisitTracker_decorators = [decorators_1.Injectable];
88
91
  __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);
89
92
  __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);
@@ -94,6 +97,7 @@ let RideDisplayService = (() => {
94
97
  __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);
95
98
  __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);
96
99
  __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);
100
+ __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);
97
101
  __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);
98
102
  __esDecorate(null, _classDescriptor = { value: _classThis }, _classDecorators, { kind: "class", name: _classThis.name, metadata: _metadata }, null, _classExtraInitializers);
99
103
  RideDisplayService = _classThis = _classDescriptor.value;
@@ -115,6 +119,7 @@ let RideDisplayService = (() => {
115
119
  startDeviceHandlers;
116
120
  isResuming;
117
121
  stateUpdateHandler = this.onStateUpdate.bind(this);
122
+ discarding = false;
118
123
  controlDevicesReadyNotified = false;
119
124
  constructor() {
120
125
  super('RideDisplay');
@@ -295,6 +300,60 @@ let RideDisplayService = (() => {
295
300
  this.getActivityRide().cleanup().catch(err => { this.logError(err, 'stop'); });
296
301
  this.getCoaches().stopRide().catch(err => { this.logError(err, 'stop'); });
297
302
  }
303
+ async discardSimulatedRide() {
304
+ if (this.discarding)
305
+ return false;
306
+ try {
307
+ if (!this.isSimulated()) {
308
+ this.logError(new Error('not a simulated ride'), 'discardSimulatedRide');
309
+ return false;
310
+ }
311
+ this.discarding = true;
312
+ const selection = this.getRideSelection();
313
+ await this.deleteActivityOnDiscard();
314
+ await this.stop();
315
+ const restored = this.restoreRideSelection(selection);
316
+ this.logEvent({ message: 'simulated ride discarded', restored });
317
+ return restored;
318
+ }
319
+ catch (err) {
320
+ this.logError(err, 'discardSimulatedRide');
321
+ return false;
322
+ }
323
+ finally {
324
+ this.discarding = false;
325
+ }
326
+ }
327
+ onRideViewNoticeAction(id) {
328
+ try {
329
+ this.getRideViewRestriction().onNoticeAction(id);
330
+ this.observer?.emit('overlay-update', this.getDisplayProperties());
331
+ }
332
+ catch (err) {
333
+ this.logError(err, 'onRideViewNoticeAction');
334
+ }
335
+ }
336
+ onRideViewNoticeClosed() {
337
+ try {
338
+ this.getRideViewRestriction().onNoticeClosed();
339
+ this.observer?.emit('overlay-update', this.getDisplayProperties());
340
+ }
341
+ catch (err) {
342
+ this.logError(err, 'onRideViewNoticeClosed');
343
+ }
344
+ }
345
+ setRideViewReminder(enabled) {
346
+ try {
347
+ this.getRideViewRestriction().setReminderEnabled(enabled);
348
+ }
349
+ catch (err) {
350
+ this.logError(err, 'setRideViewReminder');
351
+ }
352
+ }
353
+ getRideViewRestrictionDialogProps() {
354
+ const inRide = this.isSimulated() && (this.state === 'Started' || this.state === 'Active' || this.state === 'Paused');
355
+ return this.getRideViewRestriction().getDialogProps({ inRide });
356
+ }
298
357
  toggleCyclingMode() {
299
358
  try {
300
359
  if (!this.actualWorkout) {
@@ -523,6 +582,39 @@ let RideDisplayService = (() => {
523
582
  this.logError(err, 'init');
524
583
  }
525
584
  }
585
+ getRideSelection() {
586
+ const routeList = this.getRouteList();
587
+ return {
588
+ route: routeList.getSelected(),
589
+ startSettings: routeList.getStartSettings(),
590
+ workout: this.getWorkoutList().getSelected()
591
+ };
592
+ }
593
+ async deleteActivityOnDiscard() {
594
+ try {
595
+ await this.getActivityRide().delete();
596
+ }
597
+ catch (err) {
598
+ this.logError(err, 'discardSimulatedRide');
599
+ }
600
+ }
601
+ restoreRideSelection(selection) {
602
+ try {
603
+ const { route, startSettings, workout } = selection;
604
+ const routeList = this.getRouteList();
605
+ if (route)
606
+ routeList.select(route);
607
+ if (startSettings)
608
+ routeList.setStartSettings(startSettings);
609
+ if (workout)
610
+ this.getWorkoutList().select(workout);
611
+ return true;
612
+ }
613
+ catch (err) {
614
+ this.logError(err, 'discardSimulatedRide');
615
+ return false;
616
+ }
617
+ }
526
618
  setState(state) {
527
619
  this.state = state;
528
620
  this.observer?.emit('state-update', this.state);
@@ -1192,6 +1284,9 @@ let RideDisplayService = (() => {
1192
1284
  getCoaches() {
1193
1285
  return (0, coaches_1.getCoachesService)();
1194
1286
  }
1287
+ getRideViewRestriction() {
1288
+ return (0, service_3.useRideViewRestriction)();
1289
+ }
1195
1290
  getPairingVisitTracker() {
1196
1291
  return (0, visit_log_factory_1.usePairingVisitTracker)();
1197
1292
  }
@@ -17,3 +17,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./base"), exports);
18
18
  __exportStar(require("./display"), exports);
19
19
  __exportStar(require("./page"), exports);
20
+ __exportStar(require("./view-restriction"), exports);