incyclist-services 1.5.67 → 1.5.69

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.
@@ -341,47 +341,39 @@ let ActivityRideService = (() => {
341
341
  }
342
342
  }
343
343
  canShowDonate() {
344
- var _a, _b, _c, _d;
345
- if (!((_b = (_a = this.activity) === null || _a === void 0 ? void 0 : _a.user) === null || _b === void 0 ? void 0 : _b.uuid))
346
- return false;
347
- if (this.isDonateShown || !((_d = (_c = this.activity) === null || _c === void 0 ? void 0 : _c.user) === null || _d === void 0 ? void 0 : _d.uuid))
348
- return true;
349
- let trialGroup;
350
- if (this.activity.user.uuid.startsWith('1') || this.activity.user.uuid.startsWith('a')) {
351
- trialGroup = 'A';
352
- }
353
- else if (this.activity.user.uuid.startsWith('2') || this.activity.user.uuid.startsWith('b')) {
354
- trialGroup = 'B';
355
- }
356
- if (!trialGroup) {
357
- if (this.saveObserver)
358
- this.logEvent({ message: 'donate check ', showDonate: false, reason: 'user not in trial' });
359
- return false;
360
- }
361
- if (this.saveObserver || this.isSaveDone || trialGroup === 'B') {
362
- const lastClicked = this.getUserSettings().getValue('state.donateClicked', 0);
363
- if (Date.now() - lastClicked < 1000 * 60 * 60 * 24 * 365) {
364
- if (this.saveObserver)
365
- this.logEvent({ message: 'donate check ', showDonate: false, lastClicked: new Date(lastClicked).toISOString() });
366
- return false;
344
+ try {
345
+ if (this.isDonateShown) {
346
+ return true;
367
347
  }
368
- const lastShown = this.getUserSettings().getValue('state.donateShown', 0);
369
- if (Date.now() - lastShown < 1000 * 60 * 60 * 24 * 14) {
348
+ let trialGroup = 'A';
349
+ if (this.saveObserver || this.isSaveDone || trialGroup === 'B') {
350
+ const lastClicked = this.getUserSettings().getValue('state.donateClicked', 0);
351
+ if (Date.now() - lastClicked < 1000 * 60 * 60 * 24 * 365) {
352
+ if (this.saveObserver)
353
+ this.logEvent({ message: 'donate check ', showDonate: false, lastClicked: new Date(lastClicked).toISOString() });
354
+ return false;
355
+ }
356
+ const lastShown = this.getUserSettings().getValue('state.donateShown', 0);
357
+ if (Date.now() - lastShown < 1000 * 60 * 60 * 24 * 14) {
358
+ if (this.saveObserver)
359
+ this.logEvent({ message: 'donate check ', showDonate: false, lastClicked: new Date(lastShown).toISOString() });
360
+ return false;
361
+ }
362
+ const activities = this.getRepo().getAll();
363
+ const lastYear = new Date();
364
+ lastYear.setFullYear(lastYear.getFullYear() - 1);
365
+ const activitiesLastYear = activities.filter(a => { var _a, _b; return ((_a = a.summary) === null || _a === void 0 ? void 0 : _a.startTime) > lastYear.getTime() && ((_b = a.summary) === null || _b === void 0 ? void 0 : _b.distance) > 2000; });
370
366
  if (this.saveObserver)
371
- this.logEvent({ message: 'donate check ', showDonate: false, lastClicked: new Date(lastShown).toISOString() });
372
- return false;
367
+ this.logEvent({ message: 'donate check ', trialGroup, showDonate: (activitiesLastYear === null || activitiesLastYear === void 0 ? void 0 : activitiesLastYear.length) >= 10, activities: activitiesLastYear === null || activitiesLastYear === void 0 ? void 0 : activitiesLastYear.length });
368
+ if (activitiesLastYear.length < 10)
369
+ return false;
370
+ this.getUserSettings().set('state.donateShown', Date.now());
371
+ this.isDonateShown = true;
372
+ return true;
373
373
  }
374
- const activities = this.getRepo().getAll();
375
- const lastYear = new Date();
376
- lastYear.setFullYear(lastYear.getFullYear() - 1);
377
- const activitiesLastYear = activities.filter(a => { var _a, _b; return ((_a = a.summary) === null || _a === void 0 ? void 0 : _a.startTime) > lastYear.getTime() && ((_b = a.summary) === null || _b === void 0 ? void 0 : _b.distance) > 2000; });
378
- if (this.saveObserver)
379
- this.logEvent({ message: 'donate check ', trialGroup, showDonate: (activitiesLastYear === null || activitiesLastYear === void 0 ? void 0 : activitiesLastYear.length) >= 10, activities: activitiesLastYear === null || activitiesLastYear === void 0 ? void 0 : activitiesLastYear.length });
380
- if (activitiesLastYear.length < 10)
381
- return false;
382
- this.getUserSettings().set('state.donateShown', Date.now());
383
- this.isDonateShown = true;
384
- return true;
374
+ }
375
+ catch (err) {
376
+ this.logError(err, 'canShowDonate');
385
377
  }
386
378
  return false;
387
379
  }
@@ -8,6 +8,7 @@ export declare class GoogleMapsService extends IncyclistService {
8
8
  hasPersonalApiKey(): boolean;
9
9
  onPersonalApiKeySet(): void;
10
10
  getMapsDownloadUrl(): string;
11
+ reload(): void;
11
12
  protected getSecret(key: string): string;
12
13
  protected getSecretBindings(): import("../../api/bindings/secret").ISecretBinding;
13
14
  protected getUserSettings(): import("../../settings").UserSettingsService;
@@ -96,6 +96,10 @@ let GoogleMapsService = (() => {
96
96
  getMapsDownloadUrl() {
97
97
  return MAPS_API_URL;
98
98
  }
99
+ reload() {
100
+ delete this.api;
101
+ this.emit('reload');
102
+ }
99
103
  getSecret(key) {
100
104
  var _a;
101
105
  return (_a = this.getSecretBindings()) === null || _a === void 0 ? void 0 : _a.getSecret(key);
@@ -23,6 +23,7 @@ export declare class RideDisplayService extends IncyclistService implements ICur
23
23
  protected readonly onChangeState: any;
24
24
  protected startDeviceHandlers: any;
25
25
  protected isResuming: boolean;
26
+ protected stateUpdateHandler: any;
26
27
  constructor();
27
28
  init(): Promise<Observer>;
28
29
  start(simulate?: boolean): void;
@@ -89,6 +90,7 @@ export declare class RideDisplayService extends IncyclistService implements ICur
89
90
  protected initWorkout(): void;
90
91
  protected onStartCompleted(): void;
91
92
  protected startRide(retry?: boolean): void;
93
+ protected onStateUpdate(): void;
92
94
  protected startDevices(retry?: boolean): void;
93
95
  protected stopDevices(exit?: boolean): void;
94
96
  protected initDeviceHandlers(): void;
@@ -86,6 +86,7 @@ let RideDisplayService = (() => {
86
86
  this.state = 'Idle';
87
87
  this.hideAll = false;
88
88
  this.onChangeState = this.setState.bind(this);
89
+ this.stateUpdateHandler = this.onStateUpdate.bind(this);
89
90
  this.getStartOverlayProps = () => {
90
91
  var _a, _b;
91
92
  const mode = this.getRideType();
@@ -778,6 +779,7 @@ let RideDisplayService = (() => {
778
779
  this.logEvent({ message: 'overlay closed', overlay: 'start overlay' });
779
780
  this.logEvent(Object.assign({ message: 'Start success' }, logProps));
780
781
  this.state = 'Started';
782
+ this.displayService.off('state-update', this.stateUpdateHandler);
781
783
  this.disableScreensaver();
782
784
  this.createActivity();
783
785
  this.initWorkout();
@@ -789,12 +791,14 @@ let RideDisplayService = (() => {
789
791
  }
790
792
  startRide(retry) {
791
793
  this.displayService.start(retry);
792
- this.displayService.on('state-update', () => {
793
- this.checkStartStatus();
794
- this.updateStartOverlay();
795
- })
794
+ this.displayService.on('state-update', this.stateUpdateHandler)
796
795
  .on('route-updated', this.onRouteUpdated.bind(this));
797
796
  }
797
+ onStateUpdate() {
798
+ console.log('# state update', this.state);
799
+ this.checkStartStatus();
800
+ this.updateStartOverlay();
801
+ }
798
802
  startDevices(retry) {
799
803
  var _a;
800
804
  const devices = this.getDeviceRide();
@@ -13,10 +13,13 @@ class FollowRouteDisplayService extends GpxDisplayService_1.GpxDisplayService {
13
13
  return props;
14
14
  }
15
15
  savePosition(startPos) {
16
+ var _a, _b, _c;
16
17
  try {
17
- const { lapDistance } = this.position;
18
- const routeId = this.route.description.id;
19
- this.getUserSettings().set(`routeSelection.followRoute.prevSetting.${routeId}.startPos`, startPos !== null && startPos !== void 0 ? startPos : lapDistance);
18
+ const { lapDistance } = (_a = this.position) !== null && _a !== void 0 ? _a : {};
19
+ const routeId = (_c = (_b = this.route) === null || _b === void 0 ? void 0 : _b.description) === null || _c === void 0 ? void 0 : _c.id;
20
+ if (routeId && lapDistance !== undefined) {
21
+ this.getUserSettings().set(`routeSelection.followRoute.prevSetting.${routeId}.startPos`, startPos !== null && startPos !== void 0 ? startPos : lapDistance);
22
+ }
20
23
  }
21
24
  catch (err) {
22
25
  this.logEvent({ message: 'error', fn: 'savePosition()', position: this.position, error: err.message, stack: err.stack });
@@ -286,6 +286,9 @@ let FreeRideDisplayService = (() => {
286
286
  }
287
287
  }
288
288
  getOptionsId() {
289
+ var _b;
290
+ if (!((_b = this.currentOptions) === null || _b === void 0 ? void 0 : _b.length))
291
+ return 'none';
289
292
  return 'options:' + this.currentOptions.map(o => o.id).join('|');
290
293
  }
291
294
  getMapProps() {
@@ -1,3 +1,4 @@
1
+ import { GoogleMapsService } from "../../apps";
1
2
  import { Observer } from "../../base/types";
2
3
  import { UserSettingsService } from "../../settings";
3
4
  import { CurrentRideDisplayProps, GpxDisplayProps } from "../base";
@@ -51,4 +52,5 @@ export declare class GpxDisplayService extends RouteDisplayService {
51
52
  protected getBestCaseUpdateFrequency(): number;
52
53
  protected getNumSetting(key: string): number;
53
54
  protected getUserSettings(): UserSettingsService;
55
+ protected getGoogleMaps(): GoogleMapsService;
54
56
  }
@@ -35,6 +35,7 @@ var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn,
35
35
  };
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
37
  exports.GpxDisplayService = void 0;
38
+ const apps_1 = require("../../apps");
38
39
  const decorators_1 = require("../../base/decorators");
39
40
  const types_1 = require("../../base/types");
40
41
  const routes_1 = require("../../routes");
@@ -48,6 +49,7 @@ let GpxDisplayService = (() => {
48
49
  let _classSuper = RouteDisplayService_1.RouteDisplayService;
49
50
  let _instanceExtraInitializers = [];
50
51
  let _getUserSettings_decorators;
52
+ let _getGoogleMaps_decorators;
51
53
  return _a = class GpxDisplayService extends _classSuper {
52
54
  constructor() {
53
55
  super();
@@ -63,6 +65,10 @@ let GpxDisplayService = (() => {
63
65
  const bestFreq = this.getBestCaseUpdateFrequency();
64
66
  this.logEvent({ message: 'init streetview', updateFreq, minimalPause, bestFreq });
65
67
  }
68
+ if (!this.getGoogleMaps().getApi()) {
69
+ this.logEvent({ message: 'reload maps api' });
70
+ this.getGoogleMaps().reload();
71
+ }
66
72
  }
67
73
  catch (err) {
68
74
  this.logError(err, 'initView');
@@ -128,6 +134,7 @@ let GpxDisplayService = (() => {
128
134
  this.mapLoaded = true;
129
135
  }
130
136
  else if (state === 'Error') {
137
+ this.logEvent({ message: 'sat view error', error: this.mapError });
131
138
  this.mapError = error;
132
139
  }
133
140
  this.emit('state-update');
@@ -260,12 +267,17 @@ let GpxDisplayService = (() => {
260
267
  getUserSettings() {
261
268
  return (0, settings_1.useUserSettings)();
262
269
  }
270
+ getGoogleMaps() {
271
+ return (0, apps_1.useGoogleMaps)();
272
+ }
263
273
  },
264
274
  (() => {
265
275
  var _b;
266
276
  const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create((_b = _classSuper[Symbol.metadata]) !== null && _b !== void 0 ? _b : null) : void 0;
267
277
  _getUserSettings_decorators = [decorators_1.Injectable];
278
+ _getGoogleMaps_decorators = [decorators_1.Injectable];
268
279
  __esDecorate(_a, 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);
280
+ __esDecorate(_a, 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);
269
281
  if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
270
282
  })(),
271
283
  _a;
@@ -254,24 +254,33 @@ let RouteDisplayService = (() => {
254
254
  }
255
255
  }
256
256
  setInitialPosition() {
257
- var _b;
258
- const lapPoint = (0, routes_1.getNextPosition)(this.getCurrentRoute(), { routeDistance: (_b = this.startSettings.startPos) !== null && _b !== void 0 ? _b : 0 });
259
- return this.fromLapPoint(lapPoint);
257
+ var _b, _c, _d, _e, _f, _g;
258
+ try {
259
+ const lapPoint = (0, routes_1.getNextPosition)(this.getCurrentRoute(), { routeDistance: (_c = (_b = this.startSettings) === null || _b === void 0 ? void 0 : _b.startPos) !== null && _c !== void 0 ? _c : 0 });
260
+ return this.fromLapPoint(lapPoint);
261
+ }
262
+ catch (err) {
263
+ this.logError(err, 'setInitialPosition', { cntPoints: (_e = (_d = this.getCurrentRoute()) === null || _d === void 0 ? void 0 : _d.points) === null || _e === void 0 ? void 0 : _e.length, routeDistance: (_g = (_f = this.startSettings) === null || _f === void 0 ? void 0 : _f.startPos) !== null && _g !== void 0 ? _g : 0 });
264
+ }
260
265
  }
261
266
  updatePosition(activityPos) {
262
267
  var _b, _c, _d;
268
+ let currentRouteDistance;
269
+ let newRouteDistance;
270
+ let props;
263
271
  try {
264
- const currentRouteDistance = (_c = (_b = this.position) === null || _b === void 0 ? void 0 : _b.routeDistance) !== null && _c !== void 0 ? _c : 0;
265
- const newRouteDistance = (_d = activityPos === null || activityPos === void 0 ? void 0 : activityPos.routeDistance) !== null && _d !== void 0 ? _d : 0;
272
+ currentRouteDistance = (_c = (_b = this.position) === null || _b === void 0 ? void 0 : _b.routeDistance) !== null && _c !== void 0 ? _c : 0;
273
+ newRouteDistance = (_d = activityPos === null || activityPos === void 0 ? void 0 : activityPos.routeDistance) !== null && _d !== void 0 ? _d : 0;
266
274
  if (newRouteDistance !== currentRouteDistance) {
267
275
  const current = this.toLapPoint(this.position);
268
- const next = (0, routes_1.getNextPosition)(this.getCurrentRoute(), { routeDistance: activityPos === null || activityPos === void 0 ? void 0 : activityPos.routeDistance, prev: current });
276
+ props = { routeDistance: activityPos === null || activityPos === void 0 ? void 0 : activityPos.routeDistance, prev: current };
277
+ const next = (0, routes_1.getNextPosition)(this.getCurrentRoute(), props);
269
278
  return this.fromLapPoint(next);
270
279
  }
271
280
  return this.position;
272
281
  }
273
282
  catch (err) {
274
- this.logError(err, 'updatePosition');
283
+ this.logError(err, 'updatePosition', { currentRouteDistance, newRouteDistance, getNextPositionProps: props });
275
284
  }
276
285
  }
277
286
  toLapPoint(position) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.5.67",
3
+ "version": "1.5.69",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.26"
6
6
  },
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "axios": "^1.8.2",
45
- "incyclist-devices": "^2.4.5",
45
+ "incyclist-devices": "^2.4.6-beta.3",
46
46
  "promise.any": "^2.0.6",
47
47
  "semver": "^7.6.3",
48
48
  "tcx-builder": "^1.1.1",