incyclist-services 1.9.36 → 1.9.38

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.
@@ -1079,7 +1079,7 @@ let DeviceRideService = (() => {
1079
1079
  return;
1080
1080
  return this.startAdapters(adapters, 'start', props);
1081
1081
  }
1082
- async retryStartDevice(udid, props) {
1082
+ async retryStartDevice(udid, props, options) {
1083
1083
  await this.lazyInit();
1084
1084
  const ai = this.getRideAdapters()?.find(a => a.udid === udid);
1085
1085
  if (!ai) {
@@ -1090,7 +1090,7 @@ let DeviceRideService = (() => {
1090
1090
  const retryAttempt = (this.retryCounts.get(udid) ?? 0) + 1;
1091
1091
  this.retryCounts.set(udid, retryAttempt);
1092
1092
  const token = this.beginStartAttempt(udid);
1093
- const promise = this.runDeviceRetry(ai, props, token);
1093
+ const promise = this.runDeviceRetry(ai, props, token, options);
1094
1094
  this.retryPromises.set(udid, promise);
1095
1095
  let retryResult;
1096
1096
  try {
@@ -1106,18 +1106,23 @@ let DeviceRideService = (() => {
1106
1106
  deviceRole: ai.isControl ? 'trainer' : 'sensor',
1107
1107
  retryResult,
1108
1108
  retryDurationMs: Date.now() - tsStart,
1109
- retryAttempt
1109
+ retryAttempt,
1110
+ retryTrigger: options?.trigger ?? 'user'
1110
1111
  });
1111
1112
  return retryResult === 'started';
1112
1113
  }
1113
- async runDeviceRetry(ai, props, token) {
1114
+ isDeviceReconnecting(udid) {
1115
+ const ai = this.rideAdapters?.find(a => a.udid === udid);
1116
+ return ai?.isRestarting === true || ai?.adapter?.isReconnecting?.() === true;
1117
+ }
1118
+ async runDeviceRetry(ai, props, token, options) {
1114
1119
  const udid = ai.udid;
1115
1120
  try {
1116
1121
  if (ai.adapter.isStarted()) {
1117
1122
  this.emit('start-success', this.getAdapterStateInfo(ai));
1118
1123
  return 'started';
1119
1124
  }
1120
- if (this.inFlightStarts.has(udid)) {
1125
+ if (this.inFlightStarts.has(udid) || options?.stopFirst) {
1121
1126
  const stopped = await this.stopWithTimeout(ai, timeouts_1.DEVICE_RETRY_STOP_TIMEOUT_MS);
1122
1127
  if (this.startAttempts.get(udid) !== token)
1123
1128
  return 'cancelled';
@@ -143,6 +143,8 @@ let RideDisplayService = (() => {
143
143
  deviceAttempts = new Map();
144
144
  ignoredDevices = new Map();
145
145
  deviceRetries = 0;
146
+ autoRetried = new Set();
147
+ reconnecting = new Set();
146
148
  startTrigger = 'auto';
147
149
  fullRetryPending = false;
148
150
  constructor() {
@@ -286,6 +288,7 @@ let RideDisplayService = (() => {
286
288
  return;
287
289
  this.logDeviceButton('Retry device', device);
288
290
  this.ignoredDevices.delete(udid);
291
+ this.reconnecting.delete(udid);
289
292
  this.deviceRetries++;
290
293
  device.status = 'Starting';
291
294
  delete device.stateText;
@@ -324,7 +327,9 @@ let RideDisplayService = (() => {
324
327
  startPhase: props.startPhase ?? this.derivePhase(),
325
328
  startElapsedMs: this.getStartElapsed(),
326
329
  slowShown: this.slowShown,
327
- deviceRetries: this.deviceRetries
330
+ deviceRetries: this.deviceRetries,
331
+ deviceAutoRetries: this.autoRetried.size,
332
+ controlStartState: this.getControlStartState()
328
333
  });
329
334
  await this.cancelDeviceRetries();
330
335
  await this.stopRide({ noStateUpdates: true });
@@ -1209,6 +1214,7 @@ let RideDisplayService = (() => {
1209
1214
  this.observer?.emit('state-update', this.state);
1210
1215
  }
1211
1216
  async onDeviceStartOK(device) {
1217
+ this.reconnecting.delete(device.udid);
1212
1218
  this.onIgnoredDeviceStarted(device.udid);
1213
1219
  if (this.state !== 'Starting')
1214
1220
  return;
@@ -1268,12 +1274,15 @@ let RideDisplayService = (() => {
1268
1274
  this.logError(err, 'enableScreensaver');
1269
1275
  }
1270
1276
  }
1271
- onDeviceStartError(device) {
1277
+ onDeviceStartError(device, err) {
1272
1278
  if (this.state !== 'Starting')
1273
1279
  return;
1274
1280
  const startDevice = this.deviceInfo.find(d => d.udid === device.udid);
1275
1281
  if (!startDevice)
1276
1282
  return;
1283
+ if (this.tryAutoRetry(startDevice, err))
1284
+ return;
1285
+ this.reconnecting.delete(startDevice.udid);
1277
1286
  if (startDevice.status !== 'Error') {
1278
1287
  const key = startDevice.isControl ? 'Device' : 'Sensor';
1279
1288
  this.logEvent({ message: `${key} start error shown`, overlay: 'start overlay', device: startDevice.name, });
@@ -1282,6 +1291,50 @@ let RideDisplayService = (() => {
1282
1291
  startDevice.status = 'Error';
1283
1292
  this.checkStartStatus();
1284
1293
  }
1294
+ tryAutoRetry(startDevice, err) {
1295
+ if (!startDevice.isControl || startDevice.udid.startsWith('Simulator:') || this.isCancellingStart)
1296
+ return false;
1297
+ const skipReason = this.getAutoRetrySkipReason(startDevice);
1298
+ if (skipReason) {
1299
+ this.logEvent({ message: 'start auto-retry skipped', device: startDevice.name, reason: skipReason });
1300
+ return false;
1301
+ }
1302
+ this.startAutoRetry(startDevice, err);
1303
+ return true;
1304
+ }
1305
+ getAutoRetrySkipReason(startDevice) {
1306
+ if (this.autoRetried.has(startDevice.udid))
1307
+ return 'already retried';
1308
+ if (this.getDevicePairing()?.getActivity?.()?.pairing)
1309
+ return 'pairing attempt active';
1310
+ if (this.getDeviceRide().isDeviceReconnecting?.(startDevice.udid))
1311
+ return 'already reconnecting';
1312
+ return undefined;
1313
+ }
1314
+ startAutoRetry(startDevice, err) {
1315
+ const udid = startDevice.udid;
1316
+ this.logEvent({
1317
+ message: 'start auto-retry',
1318
+ device: startDevice.name,
1319
+ deviceRole: 'trainer',
1320
+ controlInterface: this.getBikeInterface(),
1321
+ reason: err?.message,
1322
+ startElapsedMs: this.getStartElapsed()
1323
+ });
1324
+ this.autoRetried.add(udid);
1325
+ this.reconnecting.add(udid);
1326
+ this.deviceRetries++;
1327
+ startDevice.status = 'Starting';
1328
+ delete startDevice.stateText;
1329
+ this.beginDeviceAttempt(udid);
1330
+ this.checkStartStatus();
1331
+ this.getDeviceRide().retryStartDevice(udid, this.getDeviceStartProps(), { stopFirst: true, trigger: 'auto' })
1332
+ .catch(retryErr => { this.logError(retryErr, 'startAutoRetry'); });
1333
+ }
1334
+ getControlStartState() {
1335
+ const control = this.deviceInfo?.find(d => d.isControl);
1336
+ return control ? this.getDeviceStartFields(control).startState : 'none';
1337
+ }
1285
1338
  onDeviceStartStatusUpdate(device, completed, total) {
1286
1339
  if (this.state !== 'Starting')
1287
1340
  return;
@@ -1385,6 +1438,7 @@ let RideDisplayService = (() => {
1385
1438
  const ignored = !d.isControl && this.ignoredDevices.has(d.udid);
1386
1439
  const starting = d.status === 'Starting';
1387
1440
  const slow = starting && !ignored && this.deviceAttempts.get(d.udid)?.slow === true;
1441
+ const reconnecting = starting && !d.stateText && this.reconnecting.has(d.udid);
1388
1442
  let startState = 'starting';
1389
1443
  if (d.status === 'Started')
1390
1444
  startState = 'started';
@@ -1392,10 +1446,12 @@ let RideDisplayService = (() => {
1392
1446
  startState = 'ignored';
1393
1447
  else if (d.stateText)
1394
1448
  startState = 'uploading';
1449
+ else if (reconnecting)
1450
+ startState = 'reconnecting';
1395
1451
  else if (d.status === 'Error')
1396
1452
  startState = d.isControl ? 'failed' : 'not-connected';
1397
1453
  if (d.isControl) {
1398
- return { startState, slow, canRetry: starting && slow && !d.stateText, canIgnore: false };
1454
+ return { startState, slow, canRetry: starting && slow && !d.stateText && !reconnecting, canIgnore: false };
1399
1455
  }
1400
1456
  const stuck = d.status === 'Error' || (starting && slow);
1401
1457
  return {
@@ -1453,12 +1509,15 @@ let RideDisplayService = (() => {
1453
1509
  this.deviceAttempts.clear();
1454
1510
  this.ignoredDevices.clear();
1455
1511
  this.deviceRetries = 0;
1512
+ this.autoRetried.clear();
1513
+ this.reconnecting.clear();
1456
1514
  this.startTrigger = 'auto';
1457
1515
  this.fullRetryPending = false;
1458
1516
  this.armStartTimer('devices-slow', this.getSlowThreshold(), () => { this.slowFlags.devices = true; });
1459
1517
  }
1460
1518
  restartDeviceTracking() {
1461
1519
  this.fullRetryPending = true;
1520
+ this.reconnecting.clear();
1462
1521
  this.slowFlags.devices = false;
1463
1522
  this.armStartTimer('devices-slow', this.getSlowThreshold(), () => { this.slowFlags.devices = true; });
1464
1523
  }
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUtf8Data = exports.fixIncorrectFileInfo = exports.parseInformations = exports.fileUrlToPath = exports.buildFileUrl = exports.safeEncode = exports.safeDecode = exports.buildVideoUrl = exports.getReferencedFileInfo = exports.BinaryReader = void 0;
3
+ exports.getUtf8Data = exports.fixIncorrectFileInfo = exports.parseInformations = exports.fileUrlToPath = exports.buildFileUrl = exports.safeEncode = exports.safeDecode = exports.normalizeFileUrl = exports.buildVideoUrl = exports.getReferencedFileInfo = exports.BinaryReader = void 0;
4
4
  const api_1 = require("../../../api");
5
+ const fileurl_1 = require("../../../utils/fileurl");
6
+ Object.defineProperty(exports, "normalizeFileUrl", { enumerable: true, get: function () { return fileurl_1.normalizeFileUrl; } });
5
7
  class BinaryReader {
6
8
  pos;
7
9
  buffer;
@@ -155,14 +157,16 @@ const buildFileUrl = (normalizedPath) => {
155
157
  return `file://${encodeURI(normalizedPath)}`;
156
158
  };
157
159
  exports.buildFileUrl = buildFileUrl;
158
- const fileUrlToPath = (url) => {
160
+ const fileUrlToPath = (url, decode = true) => {
161
+ url = (0, fileurl_1.normalizeFileUrl)(url);
159
162
  const scheme = ['file:///', 'video:///'].find(prefix => url?.startsWith(prefix));
160
163
  if (!scheme)
161
164
  return undefined;
162
165
  let path = url.slice(scheme.length - 1);
163
166
  while (path.startsWith('//'))
164
167
  path = path.slice(1);
165
- path = (0, exports.safeDecode)(path);
168
+ if (decode)
169
+ path = (0, exports.safeDecode)(path);
166
170
  return /^\/[A-Za-z]:[\\/]/.test(path) ? path.slice(1) : path;
167
171
  };
168
172
  exports.fileUrlToPath = fileUrlToPath;
@@ -188,7 +192,7 @@ const buildAbsolutePathTarget = (fileName, info, scheme) => {
188
192
  if (inputUrl.startsWith('incyclist:') || inputUrl.startsWith('file:')) {
189
193
  const parts = inputUrl.split('://');
190
194
  const targetPath = parts[1].replace(info.base, fileName);
191
- return `${scheme}://${targetPath}`;
195
+ return (0, fileurl_1.normalizeFileUrl)(`${scheme}://${targetPath}`);
192
196
  }
193
197
  };
194
198
  const buildRelativePathTarget = (fileName, info, scheme) => {
@@ -197,7 +201,7 @@ const buildRelativePathTarget = (fileName, info, scheme) => {
197
201
  fileName = path.join(info.dir, fileName);
198
202
  target.file = fileName;
199
203
  if (isAbsolutePath(fileName)) {
200
- target.url = `${scheme}://${fileName}`;
204
+ target.url = (0, fileurl_1.normalizeFileUrl)(`${scheme}://${fileName}`);
201
205
  }
202
206
  else {
203
207
  target.url = fileName;
@@ -172,7 +172,7 @@ let RouteCard = (() => {
172
172
  }
173
173
  async recoverDownloadState() {
174
174
  const descr = this.getRouteDescription();
175
- const localUrl = this.getRouteData()?.video?.url;
175
+ const localUrl = (0, utils_1.normalizeFileUrl)(this.getRouteData()?.video?.url);
176
176
  if (!descr?.hasVideo || descr.isLocal || descr.isDownloaded)
177
177
  return false;
178
178
  if (!localUrl || !(localUrl.startsWith('video:///') || localUrl.startsWith('file:///')))
@@ -197,19 +197,12 @@ let RouteCard = (() => {
197
197
  async urlExists(videoUrl) {
198
198
  if (!videoUrl)
199
199
  return true;
200
- const normalizedUrl = videoUrl.replace('video:////', 'video:///').replace('file:////', 'file:///');
201
- let path = undefined;
202
- if (normalizedUrl.startsWith('file:///'))
203
- path = normalizedUrl.replace('file://', '');
204
- if (normalizedUrl.startsWith('video:///'))
205
- path = normalizedUrl.replace('video://', '');
206
- if (path && /^\/[A-Za-z]:[\\/]/.test(path))
207
- path = path.slice(1);
208
- if (path) {
209
- const decoded = this.cleanupEncoding(path);
200
+ const decoded = (0, utils_1.fileUrlToPath)(videoUrl);
201
+ if (decoded) {
210
202
  if (await this.fileExists(decoded))
211
203
  return true;
212
- return decoded !== path ? await this.fileExists(path) : false;
204
+ const raw = (0, utils_1.fileUrlToPath)(videoUrl, false);
205
+ return raw !== decoded ? await this.fileExists(raw) : false;
213
206
  }
214
207
  return true;
215
208
  }
@@ -732,17 +725,18 @@ let RouteCard = (() => {
732
725
  if (ext !== 'mp4' && ext !== 'avi') {
733
726
  return 'Unsupported video format - Please select MP4 or AVI';
734
727
  }
735
- const path = dropped.url.replace('file:///', '');
728
+ const droppedUrl = (0, utils_1.normalizeFileUrl)(dropped.url);
729
+ const path = droppedUrl.replace('file:///', '');
736
730
  const exists = await this.fileExists(path);
737
731
  if (!exists) {
738
732
  return 'Could not open file';
739
733
  }
740
734
  const descr = this.getRouteDescription();
741
735
  const details = this.getRouteData();
742
- descr.videoUrl = dropped.url;
736
+ descr.videoUrl = droppedUrl;
743
737
  descr.videoFormat = ext;
744
738
  details.video.file = undefined;
745
- details.video.url = dropped.url;
739
+ details.video.url = droppedUrl;
746
740
  details.video.format = ext;
747
741
  this.save().catch(err => { this.logError(err, 'onVideoSelected'); });
748
742
  return null;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isWindows = exports.normalizeFileUrl = void 0;
4
+ const api_1 = require("../api");
5
+ const normalizeFileUrl = (url) => {
6
+ if (!(0, exports.isWindows)())
7
+ return url;
8
+ return url?.replace(/^(file|video):\/\/+(?=[A-Za-z]:(?:[\\/%]|$))/, '$1:///');
9
+ };
10
+ exports.normalizeFileUrl = normalizeFileUrl;
11
+ const isWindows = () => (0, api_1.getBindings)().appInfo?.getOS?.()?.platform === 'win32';
12
+ exports.isWindows = isWindows;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resolvePlaybackUrl = void 0;
4
+ const fileurl_1 = require("../utils/fileurl");
4
5
  const resolvePlaybackUrl = (url) => {
5
6
  if (!url)
6
7
  return undefined;
@@ -9,13 +10,20 @@ const resolvePlaybackUrl = (url) => {
9
10
  if (fileName.startsWith('incyclist:'))
10
11
  fileName = fileName.replace('incyclist:', 'file:');
11
12
  if (fileName.startsWith('video:') && !lc.endsWith('.avi'))
12
- return fileName.replace('video:', 'file:');
13
+ return restoreWindowsSeparators(fileName.replace('video:', 'file:'));
13
14
  if (fileName.startsWith('video:') && lc.endsWith('.avi'))
14
15
  return fileName;
15
- if (fileName.startsWith('file:') || fileName.startsWith('http:') || fileName.startsWith('https:') || fileName.startsWith('/'))
16
+ if (fileName.startsWith('file:'))
17
+ return restoreWindowsSeparators(fileName);
18
+ if (fileName.startsWith('http:') || fileName.startsWith('https:') || fileName.startsWith('/'))
16
19
  return fileName;
17
20
  if (fileName.startsWith('content:'))
18
21
  return fileName;
19
22
  return `./${fileName}`;
20
23
  };
21
24
  exports.resolvePlaybackUrl = resolvePlaybackUrl;
25
+ const restoreWindowsSeparators = (url) => {
26
+ if (!(0, fileurl_1.isWindows)() || !/^file:\/\/\/[A-Za-z]:/.test(url))
27
+ return url;
28
+ return url.replace(/%5C/gi, '\\');
29
+ };
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.dedupeCalendarEntries = exports.getContentKey = exports.SOURCE_PRIORITY = void 0;
4
+ exports.SOURCE_PRIORITY = ['trainingpeaks', 'trainerday', 'intervals'];
5
+ const getDuration = (step) => {
6
+ const duration = step.duration ?? ((step.end ?? 0) - (step.start ?? 0));
7
+ return Math.round(duration);
8
+ };
9
+ const flattenStep = (step) => {
10
+ if (step.steps) {
11
+ const inner = step.steps.flatMap(flattenStep);
12
+ const repeat = step.repeat && step.repeat > 0 ? step.repeat : 1;
13
+ return Array.from({ length: repeat }).flatMap(() => inner);
14
+ }
15
+ const { min, max, type } = step.power ?? {};
16
+ return [[getDuration(step), min === undefined ? undefined : Math.round(min), max === undefined ? undefined : Math.round(max), type]];
17
+ };
18
+ const getContentKey = (entry) => {
19
+ const steps = entry.workout?.steps;
20
+ if (!steps?.length)
21
+ return undefined;
22
+ const flat = flattenStep({ steps, repeat: 1 });
23
+ return flat.length > 0 ? JSON.stringify(flat) : undefined;
24
+ };
25
+ exports.getContentKey = getContentKey;
26
+ const getPriority = (entry) => {
27
+ const idx = exports.SOURCE_PRIORITY.indexOf(entry.source ?? '');
28
+ return idx === -1 ? exports.SOURCE_PRIORITY.length : idx;
29
+ };
30
+ const getDayKey = (entry) => {
31
+ const day = entry.day instanceof Date ? entry.day : new Date(entry.day);
32
+ return `${day.getFullYear()}-${day.getMonth()}-${day.getDate()}`;
33
+ };
34
+ const dedupeCalendarEntries = (entries) => {
35
+ const winners = new Map();
36
+ for (const entry of entries) {
37
+ const content = (0, exports.getContentKey)(entry);
38
+ if (content === undefined)
39
+ continue;
40
+ const key = `${getDayKey(entry)}|${content}`;
41
+ const current = winners.get(key);
42
+ if (!current || (current.source !== entry.source && getPriority(entry) < getPriority(current)))
43
+ winners.set(key, entry);
44
+ }
45
+ return entries.filter(entry => {
46
+ const content = (0, exports.getContentKey)(entry);
47
+ if (content === undefined)
48
+ return true;
49
+ const winner = winners.get(`${getDayKey(entry)}|${content}`);
50
+ return winner === entry || winner?.source === entry.source;
51
+ });
52
+ };
53
+ exports.dedupeCalendarEntries = dedupeCalendarEntries;
@@ -43,6 +43,7 @@ const types_1 = require("../../base/types");
43
43
  const monitoring_1 = require("../../monitoring");
44
44
  const settings_1 = require("../../settings");
45
45
  const utils_1 = require("../../utils");
46
+ const dedupe_1 = require("./dedupe");
46
47
  const sync_1 = require("./sync");
47
48
  const SYNC_INTERVAL = 5 * 60 * 1000;
48
49
  const DB_NAME = 'calendar';
@@ -126,7 +127,7 @@ let WorkoutCalendarService = (() => {
126
127
  const from = (0, utils_1.getFirstDayOfCurrentWeek)();
127
128
  const to = (0, utils_1.addDays)(today, 7);
128
129
  if (this.workouts) {
129
- const workouts = this.workouts.filter(w => w.day?.valueOf() >= from.valueOf() && w.day.valueOf() <= to.valueOf());
130
+ const workouts = this.getVisibleWorkouts().filter(w => w.day?.valueOf() >= from.valueOf() && w.day.valueOf() <= to.valueOf());
130
131
  workouts.sort((a, b) => a.day.valueOf() - b.day.valueOf());
131
132
  return workouts.map(w => this.getScheduledWorkout(w));
132
133
  }
@@ -142,7 +143,7 @@ let WorkoutCalendarService = (() => {
142
143
  return undefined;
143
144
  const now = new Date();
144
145
  const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
145
- const entry = this.workouts.find(w => w.day?.toLocaleDateString() === today.toLocaleDateString());
146
+ const entry = this.getVisibleWorkouts().find(w => w.day?.toLocaleDateString() === today.toLocaleDateString());
146
147
  return entry ? this.getScheduledWorkout(entry) : undefined;
147
148
  }
148
149
  catch (err) {
@@ -214,6 +215,9 @@ let WorkoutCalendarService = (() => {
214
215
  catch {
215
216
  }
216
217
  }
218
+ getVisibleWorkouts() {
219
+ return (0, dedupe_1.dedupeCalendarEntries)(this.workouts ?? []);
220
+ }
217
221
  getScheduledWorkout(w) {
218
222
  return { type: 'scheduled', name: w.workout.name, id: `${w.source ?? ''}:${w.workoutId}`, ...w };
219
223
  }
@@ -257,6 +261,7 @@ let WorkoutCalendarService = (() => {
257
261
  const observer = this.getWorkoutSyncFactory().sync(service);
258
262
  if (!observer) {
259
263
  done();
264
+ return;
260
265
  }
261
266
  this.syncInfo.observer = observer;
262
267
  this.syncInfo.listChanged = false;
@@ -277,8 +282,9 @@ let WorkoutCalendarService = (() => {
277
282
  }
278
283
  done();
279
284
  };
280
- const onloaded = (workouts) => {
281
- this.workouts = workouts.map(w => ({ ...w, observer: new types_1.Observer() }));
285
+ const onloaded = (workouts, services) => {
286
+ const kept = services ? (this.workouts ?? []).filter(w => !services.includes(w.source)) : [];
287
+ this.workouts = [...kept, ...workouts.map(w => ({ ...w, observer: new types_1.Observer() }))];
282
288
  this.checkIfScheduledCurrentDay();
283
289
  this.syncInfo.listChanged = true;
284
290
  this.syncInfo.contentChanged = true;
@@ -293,8 +299,8 @@ let WorkoutCalendarService = (() => {
293
299
  return;
294
300
  const now = new Date();
295
301
  const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
296
- const workouts = this.workouts?.filter(w => w.day?.toLocaleDateString() === today.toLocaleDateString()) ?? [];
297
- if (workouts?.length > 0) {
302
+ const workouts = this.getVisibleWorkouts().filter(w => w.day?.toLocaleDateString() === today.toLocaleDateString());
303
+ if (workouts.length > 0) {
298
304
  this.emit('scheduled', workouts[0]);
299
305
  }
300
306
  }
@@ -79,20 +79,22 @@ let WorkoutSyncFactory = (() => {
79
79
  (0, utils_1.waitNextTick)().then(() => { observer.stop(); }).catch(() => { });
80
80
  return null;
81
81
  }
82
+ const workouts = [];
83
+ const loadedServices = [];
82
84
  target.forEach(sp => {
83
- const workouts = [];
84
85
  const { service, syncProvider } = sp;
85
86
  const so = syncProvider.sync();
86
87
  const onDone = (event, entries, service) => {
87
88
  if (event === 'loaded') {
89
+ loadedServices.push(service);
88
90
  entries.forEach(w => {
89
91
  workouts.push({ ...w, source: service });
90
92
  });
91
93
  }
92
94
  delete syncs[service];
93
95
  if (Object.keys(syncs).length === 0) {
94
- if (event === 'loaded') {
95
- observer.emit('loaded', workouts);
96
+ if (loadedServices.length > 0) {
97
+ observer.emit('loaded', workouts, loadedServices);
96
98
  }
97
99
  else {
98
100
  observer.emit('done');
@@ -1073,7 +1073,7 @@ let DeviceRideService = (() => {
1073
1073
  return;
1074
1074
  return this.startAdapters(adapters, 'start', props);
1075
1075
  }
1076
- async retryStartDevice(udid, props) {
1076
+ async retryStartDevice(udid, props, options) {
1077
1077
  await this.lazyInit();
1078
1078
  const ai = this.getRideAdapters()?.find(a => a.udid === udid);
1079
1079
  if (!ai) {
@@ -1084,7 +1084,7 @@ let DeviceRideService = (() => {
1084
1084
  const retryAttempt = (this.retryCounts.get(udid) ?? 0) + 1;
1085
1085
  this.retryCounts.set(udid, retryAttempt);
1086
1086
  const token = this.beginStartAttempt(udid);
1087
- const promise = this.runDeviceRetry(ai, props, token);
1087
+ const promise = this.runDeviceRetry(ai, props, token, options);
1088
1088
  this.retryPromises.set(udid, promise);
1089
1089
  let retryResult;
1090
1090
  try {
@@ -1100,18 +1100,23 @@ let DeviceRideService = (() => {
1100
1100
  deviceRole: ai.isControl ? 'trainer' : 'sensor',
1101
1101
  retryResult,
1102
1102
  retryDurationMs: Date.now() - tsStart,
1103
- retryAttempt
1103
+ retryAttempt,
1104
+ retryTrigger: options?.trigger ?? 'user'
1104
1105
  });
1105
1106
  return retryResult === 'started';
1106
1107
  }
1107
- async runDeviceRetry(ai, props, token) {
1108
+ isDeviceReconnecting(udid) {
1109
+ const ai = this.rideAdapters?.find(a => a.udid === udid);
1110
+ return ai?.isRestarting === true || ai?.adapter?.isReconnecting?.() === true;
1111
+ }
1112
+ async runDeviceRetry(ai, props, token, options) {
1108
1113
  const udid = ai.udid;
1109
1114
  try {
1110
1115
  if (ai.adapter.isStarted()) {
1111
1116
  this.emit('start-success', this.getAdapterStateInfo(ai));
1112
1117
  return 'started';
1113
1118
  }
1114
- if (this.inFlightStarts.has(udid)) {
1119
+ if (this.inFlightStarts.has(udid) || options?.stopFirst) {
1115
1120
  const stopped = await this.stopWithTimeout(ai, DEVICE_RETRY_STOP_TIMEOUT_MS);
1116
1121
  if (this.startAttempts.get(udid) !== token)
1117
1122
  return 'cancelled';
@@ -140,6 +140,8 @@ let RideDisplayService = (() => {
140
140
  deviceAttempts = new Map();
141
141
  ignoredDevices = new Map();
142
142
  deviceRetries = 0;
143
+ autoRetried = new Set();
144
+ reconnecting = new Set();
143
145
  startTrigger = 'auto';
144
146
  fullRetryPending = false;
145
147
  constructor() {
@@ -283,6 +285,7 @@ let RideDisplayService = (() => {
283
285
  return;
284
286
  this.logDeviceButton('Retry device', device);
285
287
  this.ignoredDevices.delete(udid);
288
+ this.reconnecting.delete(udid);
286
289
  this.deviceRetries++;
287
290
  device.status = 'Starting';
288
291
  delete device.stateText;
@@ -321,7 +324,9 @@ let RideDisplayService = (() => {
321
324
  startPhase: props.startPhase ?? this.derivePhase(),
322
325
  startElapsedMs: this.getStartElapsed(),
323
326
  slowShown: this.slowShown,
324
- deviceRetries: this.deviceRetries
327
+ deviceRetries: this.deviceRetries,
328
+ deviceAutoRetries: this.autoRetried.size,
329
+ controlStartState: this.getControlStartState()
325
330
  });
326
331
  await this.cancelDeviceRetries();
327
332
  await this.stopRide({ noStateUpdates: true });
@@ -1206,6 +1211,7 @@ let RideDisplayService = (() => {
1206
1211
  this.observer?.emit('state-update', this.state);
1207
1212
  }
1208
1213
  async onDeviceStartOK(device) {
1214
+ this.reconnecting.delete(device.udid);
1209
1215
  this.onIgnoredDeviceStarted(device.udid);
1210
1216
  if (this.state !== 'Starting')
1211
1217
  return;
@@ -1265,12 +1271,15 @@ let RideDisplayService = (() => {
1265
1271
  this.logError(err, 'enableScreensaver');
1266
1272
  }
1267
1273
  }
1268
- onDeviceStartError(device) {
1274
+ onDeviceStartError(device, err) {
1269
1275
  if (this.state !== 'Starting')
1270
1276
  return;
1271
1277
  const startDevice = this.deviceInfo.find(d => d.udid === device.udid);
1272
1278
  if (!startDevice)
1273
1279
  return;
1280
+ if (this.tryAutoRetry(startDevice, err))
1281
+ return;
1282
+ this.reconnecting.delete(startDevice.udid);
1274
1283
  if (startDevice.status !== 'Error') {
1275
1284
  const key = startDevice.isControl ? 'Device' : 'Sensor';
1276
1285
  this.logEvent({ message: `${key} start error shown`, overlay: 'start overlay', device: startDevice.name, });
@@ -1279,6 +1288,50 @@ let RideDisplayService = (() => {
1279
1288
  startDevice.status = 'Error';
1280
1289
  this.checkStartStatus();
1281
1290
  }
1291
+ tryAutoRetry(startDevice, err) {
1292
+ if (!startDevice.isControl || startDevice.udid.startsWith('Simulator:') || this.isCancellingStart)
1293
+ return false;
1294
+ const skipReason = this.getAutoRetrySkipReason(startDevice);
1295
+ if (skipReason) {
1296
+ this.logEvent({ message: 'start auto-retry skipped', device: startDevice.name, reason: skipReason });
1297
+ return false;
1298
+ }
1299
+ this.startAutoRetry(startDevice, err);
1300
+ return true;
1301
+ }
1302
+ getAutoRetrySkipReason(startDevice) {
1303
+ if (this.autoRetried.has(startDevice.udid))
1304
+ return 'already retried';
1305
+ if (this.getDevicePairing()?.getActivity?.()?.pairing)
1306
+ return 'pairing attempt active';
1307
+ if (this.getDeviceRide().isDeviceReconnecting?.(startDevice.udid))
1308
+ return 'already reconnecting';
1309
+ return undefined;
1310
+ }
1311
+ startAutoRetry(startDevice, err) {
1312
+ const udid = startDevice.udid;
1313
+ this.logEvent({
1314
+ message: 'start auto-retry',
1315
+ device: startDevice.name,
1316
+ deviceRole: 'trainer',
1317
+ controlInterface: this.getBikeInterface(),
1318
+ reason: err?.message,
1319
+ startElapsedMs: this.getStartElapsed()
1320
+ });
1321
+ this.autoRetried.add(udid);
1322
+ this.reconnecting.add(udid);
1323
+ this.deviceRetries++;
1324
+ startDevice.status = 'Starting';
1325
+ delete startDevice.stateText;
1326
+ this.beginDeviceAttempt(udid);
1327
+ this.checkStartStatus();
1328
+ this.getDeviceRide().retryStartDevice(udid, this.getDeviceStartProps(), { stopFirst: true, trigger: 'auto' })
1329
+ .catch(retryErr => { this.logError(retryErr, 'startAutoRetry'); });
1330
+ }
1331
+ getControlStartState() {
1332
+ const control = this.deviceInfo?.find(d => d.isControl);
1333
+ return control ? this.getDeviceStartFields(control).startState : 'none';
1334
+ }
1282
1335
  onDeviceStartStatusUpdate(device, completed, total) {
1283
1336
  if (this.state !== 'Starting')
1284
1337
  return;
@@ -1382,6 +1435,7 @@ let RideDisplayService = (() => {
1382
1435
  const ignored = !d.isControl && this.ignoredDevices.has(d.udid);
1383
1436
  const starting = d.status === 'Starting';
1384
1437
  const slow = starting && !ignored && this.deviceAttempts.get(d.udid)?.slow === true;
1438
+ const reconnecting = starting && !d.stateText && this.reconnecting.has(d.udid);
1385
1439
  let startState = 'starting';
1386
1440
  if (d.status === 'Started')
1387
1441
  startState = 'started';
@@ -1389,10 +1443,12 @@ let RideDisplayService = (() => {
1389
1443
  startState = 'ignored';
1390
1444
  else if (d.stateText)
1391
1445
  startState = 'uploading';
1446
+ else if (reconnecting)
1447
+ startState = 'reconnecting';
1392
1448
  else if (d.status === 'Error')
1393
1449
  startState = d.isControl ? 'failed' : 'not-connected';
1394
1450
  if (d.isControl) {
1395
- return { startState, slow, canRetry: starting && slow && !d.stateText, canIgnore: false };
1451
+ return { startState, slow, canRetry: starting && slow && !d.stateText && !reconnecting, canIgnore: false };
1396
1452
  }
1397
1453
  const stuck = d.status === 'Error' || (starting && slow);
1398
1454
  return {
@@ -1450,12 +1506,15 @@ let RideDisplayService = (() => {
1450
1506
  this.deviceAttempts.clear();
1451
1507
  this.ignoredDevices.clear();
1452
1508
  this.deviceRetries = 0;
1509
+ this.autoRetried.clear();
1510
+ this.reconnecting.clear();
1453
1511
  this.startTrigger = 'auto';
1454
1512
  this.fullRetryPending = false;
1455
1513
  this.armStartTimer('devices-slow', this.getSlowThreshold(), () => { this.slowFlags.devices = true; });
1456
1514
  }
1457
1515
  restartDeviceTracking() {
1458
1516
  this.fullRetryPending = true;
1517
+ this.reconnecting.clear();
1459
1518
  this.slowFlags.devices = false;
1460
1519
  this.armStartTimer('devices-slow', this.getSlowThreshold(), () => { this.slowFlags.devices = true; });
1461
1520
  }
@@ -1,4 +1,5 @@
1
1
  import { getBindings } from "../../../api";
2
+ import { normalizeFileUrl } from '../../../utils/fileurl';
2
3
  export class BinaryReader {
3
4
  pos;
4
5
  buffer;
@@ -120,6 +121,7 @@ export const buildVideoUrl = (filePath) => {
120
121
  }
121
122
  return `video://${filePath}`;
122
123
  };
124
+ export { normalizeFileUrl };
123
125
  export const safeDecode = (path) => {
124
126
  try {
125
127
  return decodeURIComponent(path);
@@ -146,14 +148,16 @@ export const buildFileUrl = (normalizedPath) => {
146
148
  }
147
149
  return `file://${encodeURI(normalizedPath)}`;
148
150
  };
149
- export const fileUrlToPath = (url) => {
151
+ export const fileUrlToPath = (url, decode = true) => {
152
+ url = normalizeFileUrl(url);
150
153
  const scheme = ['file:///', 'video:///'].find(prefix => url?.startsWith(prefix));
151
154
  if (!scheme)
152
155
  return undefined;
153
156
  let path = url.slice(scheme.length - 1);
154
157
  while (path.startsWith('//'))
155
158
  path = path.slice(1);
156
- path = safeDecode(path);
159
+ if (decode)
160
+ path = safeDecode(path);
157
161
  return /^\/[A-Za-z]:[\\/]/.test(path) ? path.slice(1) : path;
158
162
  };
159
163
  const buildUrlFromFile = (info, referenced) => {
@@ -178,7 +182,7 @@ const buildAbsolutePathTarget = (fileName, info, scheme) => {
178
182
  if (inputUrl.startsWith('incyclist:') || inputUrl.startsWith('file:')) {
179
183
  const parts = inputUrl.split('://');
180
184
  const targetPath = parts[1].replace(info.base, fileName);
181
- return `${scheme}://${targetPath}`;
185
+ return normalizeFileUrl(`${scheme}://${targetPath}`);
182
186
  }
183
187
  };
184
188
  const buildRelativePathTarget = (fileName, info, scheme) => {
@@ -187,7 +191,7 @@ const buildRelativePathTarget = (fileName, info, scheme) => {
187
191
  fileName = path.join(info.dir, fileName);
188
192
  target.file = fileName;
189
193
  if (isAbsolutePath(fileName)) {
190
- target.url = `${scheme}://${fileName}`;
194
+ target.url = normalizeFileUrl(`${scheme}://${fileName}`);
191
195
  }
192
196
  else {
193
197
  target.url = fileName;
@@ -36,7 +36,7 @@ import { getBindings } from "../../../api";
36
36
  import { Observer, PromiseObserver } from "../../../base/types/observer";
37
37
  import { useUserSettings } from "../../../settings";
38
38
  import { sleep } from "../../../utils/sleep";
39
- import { fileUrlToPath } from "../../base/parsers/utils";
39
+ import { fileUrlToPath, normalizeFileUrl } from "../../base/parsers/utils";
40
40
  import { BaseCard } from "./base";
41
41
  import { getRouteList, useRouteList } from "../service";
42
42
  import { RoutesDbLoader } from "../loaders/db";
@@ -169,7 +169,7 @@ let RouteCard = (() => {
169
169
  }
170
170
  async recoverDownloadState() {
171
171
  const descr = this.getRouteDescription();
172
- const localUrl = this.getRouteData()?.video?.url;
172
+ const localUrl = normalizeFileUrl(this.getRouteData()?.video?.url);
173
173
  if (!descr?.hasVideo || descr.isLocal || descr.isDownloaded)
174
174
  return false;
175
175
  if (!localUrl || !(localUrl.startsWith('video:///') || localUrl.startsWith('file:///')))
@@ -194,19 +194,12 @@ let RouteCard = (() => {
194
194
  async urlExists(videoUrl) {
195
195
  if (!videoUrl)
196
196
  return true;
197
- const normalizedUrl = videoUrl.replace('video:////', 'video:///').replace('file:////', 'file:///');
198
- let path = undefined;
199
- if (normalizedUrl.startsWith('file:///'))
200
- path = normalizedUrl.replace('file://', '');
201
- if (normalizedUrl.startsWith('video:///'))
202
- path = normalizedUrl.replace('video://', '');
203
- if (path && /^\/[A-Za-z]:[\\/]/.test(path))
204
- path = path.slice(1);
205
- if (path) {
206
- const decoded = this.cleanupEncoding(path);
197
+ const decoded = fileUrlToPath(videoUrl);
198
+ if (decoded) {
207
199
  if (await this.fileExists(decoded))
208
200
  return true;
209
- return decoded !== path ? await this.fileExists(path) : false;
201
+ const raw = fileUrlToPath(videoUrl, false);
202
+ return raw !== decoded ? await this.fileExists(raw) : false;
210
203
  }
211
204
  return true;
212
205
  }
@@ -729,17 +722,18 @@ let RouteCard = (() => {
729
722
  if (ext !== 'mp4' && ext !== 'avi') {
730
723
  return 'Unsupported video format - Please select MP4 or AVI';
731
724
  }
732
- const path = dropped.url.replace('file:///', '');
725
+ const droppedUrl = normalizeFileUrl(dropped.url);
726
+ const path = droppedUrl.replace('file:///', '');
733
727
  const exists = await this.fileExists(path);
734
728
  if (!exists) {
735
729
  return 'Could not open file';
736
730
  }
737
731
  const descr = this.getRouteDescription();
738
732
  const details = this.getRouteData();
739
- descr.videoUrl = dropped.url;
733
+ descr.videoUrl = droppedUrl;
740
734
  descr.videoFormat = ext;
741
735
  details.video.file = undefined;
742
- details.video.url = dropped.url;
736
+ details.video.url = droppedUrl;
743
737
  details.video.format = ext;
744
738
  this.save().catch(err => { this.logError(err, 'onVideoSelected'); });
745
739
  return null;
@@ -0,0 +1,7 @@
1
+ import { getBindings } from "../api";
2
+ export const normalizeFileUrl = (url) => {
3
+ if (!isWindows())
4
+ return url;
5
+ return url?.replace(/^(file|video):\/\/+(?=[A-Za-z]:(?:[\\/%]|$))/, '$1:///');
6
+ };
7
+ export const isWindows = () => getBindings().appInfo?.getOS?.()?.platform === 'win32';
@@ -1,3 +1,4 @@
1
+ import { isWindows } from '../utils/fileurl';
1
2
  export const resolvePlaybackUrl = (url) => {
2
3
  if (!url)
3
4
  return undefined;
@@ -6,12 +7,19 @@ export const resolvePlaybackUrl = (url) => {
6
7
  if (fileName.startsWith('incyclist:'))
7
8
  fileName = fileName.replace('incyclist:', 'file:');
8
9
  if (fileName.startsWith('video:') && !lc.endsWith('.avi'))
9
- return fileName.replace('video:', 'file:');
10
+ return restoreWindowsSeparators(fileName.replace('video:', 'file:'));
10
11
  if (fileName.startsWith('video:') && lc.endsWith('.avi'))
11
12
  return fileName;
12
- if (fileName.startsWith('file:') || fileName.startsWith('http:') || fileName.startsWith('https:') || fileName.startsWith('/'))
13
+ if (fileName.startsWith('file:'))
14
+ return restoreWindowsSeparators(fileName);
15
+ if (fileName.startsWith('http:') || fileName.startsWith('https:') || fileName.startsWith('/'))
13
16
  return fileName;
14
17
  if (fileName.startsWith('content:'))
15
18
  return fileName;
16
19
  return `./${fileName}`;
17
20
  };
21
+ const restoreWindowsSeparators = (url) => {
22
+ if (!isWindows() || !/^file:\/\/\/[A-Za-z]:/.test(url))
23
+ return url;
24
+ return url.replace(/%5C/gi, '\\');
25
+ };
@@ -0,0 +1,48 @@
1
+ export const SOURCE_PRIORITY = ['trainingpeaks', 'trainerday', 'intervals'];
2
+ const getDuration = (step) => {
3
+ const duration = step.duration ?? ((step.end ?? 0) - (step.start ?? 0));
4
+ return Math.round(duration);
5
+ };
6
+ const flattenStep = (step) => {
7
+ if (step.steps) {
8
+ const inner = step.steps.flatMap(flattenStep);
9
+ const repeat = step.repeat && step.repeat > 0 ? step.repeat : 1;
10
+ return Array.from({ length: repeat }).flatMap(() => inner);
11
+ }
12
+ const { min, max, type } = step.power ?? {};
13
+ return [[getDuration(step), min === undefined ? undefined : Math.round(min), max === undefined ? undefined : Math.round(max), type]];
14
+ };
15
+ export const getContentKey = (entry) => {
16
+ const steps = entry.workout?.steps;
17
+ if (!steps?.length)
18
+ return undefined;
19
+ const flat = flattenStep({ steps, repeat: 1 });
20
+ return flat.length > 0 ? JSON.stringify(flat) : undefined;
21
+ };
22
+ const getPriority = (entry) => {
23
+ const idx = SOURCE_PRIORITY.indexOf(entry.source ?? '');
24
+ return idx === -1 ? SOURCE_PRIORITY.length : idx;
25
+ };
26
+ const getDayKey = (entry) => {
27
+ const day = entry.day instanceof Date ? entry.day : new Date(entry.day);
28
+ return `${day.getFullYear()}-${day.getMonth()}-${day.getDate()}`;
29
+ };
30
+ export const dedupeCalendarEntries = (entries) => {
31
+ const winners = new Map();
32
+ for (const entry of entries) {
33
+ const content = getContentKey(entry);
34
+ if (content === undefined)
35
+ continue;
36
+ const key = `${getDayKey(entry)}|${content}`;
37
+ const current = winners.get(key);
38
+ if (!current || (current.source !== entry.source && getPriority(entry) < getPriority(current)))
39
+ winners.set(key, entry);
40
+ }
41
+ return entries.filter(entry => {
42
+ const content = getContentKey(entry);
43
+ if (content === undefined)
44
+ return true;
45
+ const winner = winners.get(`${getDayKey(entry)}|${content}`);
46
+ return winner === entry || winner?.source === entry.source;
47
+ });
48
+ };
@@ -40,6 +40,7 @@ import { Observer, Singleton } from "../../base/types";
40
40
  import { useOnlineStatusMonitoring } from "../../monitoring";
41
41
  import { useUserSettings } from "../../settings";
42
42
  import { addDays, getFirstDayOfCurrentWeek } from "../../utils";
43
+ import { dedupeCalendarEntries } from "./dedupe";
43
44
  import { WorkoutSyncFactory } from "./sync";
44
45
  const SYNC_INTERVAL = 5 * 60 * 1000;
45
46
  const DB_NAME = 'calendar';
@@ -123,7 +124,7 @@ let WorkoutCalendarService = (() => {
123
124
  const from = getFirstDayOfCurrentWeek();
124
125
  const to = addDays(today, 7);
125
126
  if (this.workouts) {
126
- const workouts = this.workouts.filter(w => w.day?.valueOf() >= from.valueOf() && w.day.valueOf() <= to.valueOf());
127
+ const workouts = this.getVisibleWorkouts().filter(w => w.day?.valueOf() >= from.valueOf() && w.day.valueOf() <= to.valueOf());
127
128
  workouts.sort((a, b) => a.day.valueOf() - b.day.valueOf());
128
129
  return workouts.map(w => this.getScheduledWorkout(w));
129
130
  }
@@ -139,7 +140,7 @@ let WorkoutCalendarService = (() => {
139
140
  return undefined;
140
141
  const now = new Date();
141
142
  const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
142
- const entry = this.workouts.find(w => w.day?.toLocaleDateString() === today.toLocaleDateString());
143
+ const entry = this.getVisibleWorkouts().find(w => w.day?.toLocaleDateString() === today.toLocaleDateString());
143
144
  return entry ? this.getScheduledWorkout(entry) : undefined;
144
145
  }
145
146
  catch (err) {
@@ -211,6 +212,9 @@ let WorkoutCalendarService = (() => {
211
212
  catch {
212
213
  }
213
214
  }
215
+ getVisibleWorkouts() {
216
+ return dedupeCalendarEntries(this.workouts ?? []);
217
+ }
214
218
  getScheduledWorkout(w) {
215
219
  return { type: 'scheduled', name: w.workout.name, id: `${w.source ?? ''}:${w.workoutId}`, ...w };
216
220
  }
@@ -254,6 +258,7 @@ let WorkoutCalendarService = (() => {
254
258
  const observer = this.getWorkoutSyncFactory().sync(service);
255
259
  if (!observer) {
256
260
  done();
261
+ return;
257
262
  }
258
263
  this.syncInfo.observer = observer;
259
264
  this.syncInfo.listChanged = false;
@@ -274,8 +279,9 @@ let WorkoutCalendarService = (() => {
274
279
  }
275
280
  done();
276
281
  };
277
- const onloaded = (workouts) => {
278
- this.workouts = workouts.map(w => ({ ...w, observer: new Observer() }));
282
+ const onloaded = (workouts, services) => {
283
+ const kept = services ? (this.workouts ?? []).filter(w => !services.includes(w.source)) : [];
284
+ this.workouts = [...kept, ...workouts.map(w => ({ ...w, observer: new Observer() }))];
279
285
  this.checkIfScheduledCurrentDay();
280
286
  this.syncInfo.listChanged = true;
281
287
  this.syncInfo.contentChanged = true;
@@ -290,8 +296,8 @@ let WorkoutCalendarService = (() => {
290
296
  return;
291
297
  const now = new Date();
292
298
  const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
293
- const workouts = this.workouts?.filter(w => w.day?.toLocaleDateString() === today.toLocaleDateString()) ?? [];
294
- if (workouts?.length > 0) {
299
+ const workouts = this.getVisibleWorkouts().filter(w => w.day?.toLocaleDateString() === today.toLocaleDateString());
300
+ if (workouts.length > 0) {
295
301
  this.emit('scheduled', workouts[0]);
296
302
  }
297
303
  }
@@ -76,20 +76,22 @@ let WorkoutSyncFactory = (() => {
76
76
  waitNextTick().then(() => { observer.stop(); }).catch(() => { });
77
77
  return null;
78
78
  }
79
+ const workouts = [];
80
+ const loadedServices = [];
79
81
  target.forEach(sp => {
80
- const workouts = [];
81
82
  const { service, syncProvider } = sp;
82
83
  const so = syncProvider.sync();
83
84
  const onDone = (event, entries, service) => {
84
85
  if (event === 'loaded') {
86
+ loadedServices.push(service);
85
87
  entries.forEach(w => {
86
88
  workouts.push({ ...w, source: service });
87
89
  });
88
90
  }
89
91
  delete syncs[service];
90
92
  if (Object.keys(syncs).length === 0) {
91
- if (event === 'loaded') {
92
- observer.emit('loaded', workouts);
93
+ if (loadedServices.length > 0) {
94
+ observer.emit('loaded', workouts, loadedServices);
93
95
  }
94
96
  else {
95
97
  observer.emit('done');
@@ -1,5 +1,5 @@
1
1
  import { AdapterInfo, ExtendedIncyclistCapability, IncyclistDeviceSettings } from "../configuration";
2
- import { AdapterRideInfo, AdapterStateInfo, DeviceSnapshot, LegacyRoute, PreparedRoute, RideServiceCheckFilter, RideServiceDeviceProperties, RetryResult } from "./types";
2
+ import { AdapterRideInfo, AdapterStateInfo, DeviceRetryOptions, DeviceSnapshot, LegacyRoute, PreparedRoute, RideServiceCheckFilter, RideServiceDeviceProperties, RetryResult } from "./types";
3
3
  import { CyclingMode, DeviceData, DeviceSettings, ICyclingMode, IncyclistCapability, IncyclistDeviceAdapter, IncyclistInterface, ModeReplacedInfo, Sport, UpdateRequest } from "incyclist-devices";
4
4
  import { IncyclistService } from "../../base/service";
5
5
  import { Route } from "../../routes/base/model/route";
@@ -112,8 +112,9 @@ export declare class DeviceRideService extends IncyclistService {
112
112
  start(props: RideServiceDeviceProperties): Promise<boolean>;
113
113
  getSport(): Sport;
114
114
  startRetry(props: RideServiceDeviceProperties): Promise<boolean>;
115
- retryStartDevice(udid: string, props: RideServiceDeviceProperties): Promise<boolean>;
116
- protected runDeviceRetry(ai: AdapterRideInfo, props: RideServiceDeviceProperties, token: number): Promise<RetryResult>;
115
+ retryStartDevice(udid: string, props: RideServiceDeviceProperties, options?: DeviceRetryOptions): Promise<boolean>;
116
+ isDeviceReconnecting(udid: string): boolean;
117
+ protected runDeviceRetry(ai: AdapterRideInfo, props: RideServiceDeviceProperties, token: number, options?: DeviceRetryOptions): Promise<RetryResult>;
117
118
  protected stopWithTimeout(ai: AdapterRideInfo, timeout: number): Promise<boolean>;
118
119
  protected pauseScanForRide(udidCount: number): void;
119
120
  protected resumeScanAfterRide(exitPath: 'stop' | 'cancelStart' | 'dropPendingStart' | 'start'): void;
@@ -63,4 +63,8 @@ export interface PreparedRoute {
63
63
  sampleRate: number;
64
64
  points: Point[];
65
65
  }
66
+ export interface DeviceRetryOptions {
67
+ stopFirst?: boolean;
68
+ trigger?: 'user' | 'auto';
69
+ }
66
70
  export type RetryResult = 'started' | 'failed' | 'stop-timeout' | 'cancelled';
@@ -31,7 +31,7 @@ export type CurrentRideDeviceInfo = {
31
31
  canIgnore?: boolean;
32
32
  };
33
33
  export type StartPhase = 'devices' | 'content' | 'ready';
34
- export type StartDeviceState = 'starting' | 'uploading' | 'started' | 'not-connected' | 'failed' | 'ignored';
34
+ export type StartDeviceState = 'starting' | 'reconnecting' | 'uploading' | 'started' | 'not-connected' | 'failed' | 'ignored';
35
35
  export type StartContentInfo = {
36
36
  kind: 'video' | 'map' | 'satellite' | 'streetview';
37
37
  label: string;
@@ -51,6 +51,8 @@ export declare class RideDisplayService extends IncyclistService implements ICur
51
51
  }>;
52
52
  protected ignoredDevices: Map<string, number>;
53
53
  protected deviceRetries: number;
54
+ protected autoRetried: Set<string>;
55
+ protected reconnecting: Set<string>;
54
56
  protected startTrigger: 'auto' | 'start-button';
55
57
  protected fullRetryPending: boolean;
56
58
  constructor();
@@ -162,7 +164,11 @@ export declare class RideDisplayService extends IncyclistService implements ICur
162
164
  protected addScreenshot(fileName: string): void;
163
165
  protected disableScreensaver(): void;
164
166
  protected enableScreensaver(): void;
165
- protected onDeviceStartError(device: any): void;
167
+ protected onDeviceStartError(device: any, err?: Error): void;
168
+ protected tryAutoRetry(startDevice: CurrentRideDeviceInfo, err?: Error): boolean;
169
+ protected getAutoRetrySkipReason(startDevice: CurrentRideDeviceInfo): string | undefined;
170
+ protected startAutoRetry(startDevice: CurrentRideDeviceInfo, err?: Error): void;
171
+ protected getControlStartState(): string;
166
172
  protected onDeviceStartStatusUpdate(device: any, completed: any, total: any): void;
167
173
  protected onDeviceData(data: DeviceData, udid: string): void;
168
174
  onCyclingModeToggled(mode: 'SIM' | 'ERG', request: UpdateRequest): void;
@@ -1,4 +1,5 @@
1
1
  import { FileInfo } from "../../../api";
2
+ import { normalizeFileUrl } from '../../../utils/fileurl';
2
3
  import { RouteInfoText } from "../types";
3
4
  import { JSONObject } from "../../../utils/xml";
4
5
  export declare class BinaryReader {
@@ -22,10 +23,11 @@ export declare const getReferencedFileInfo: (info: FileInfo, referenced: {
22
23
  url?: string;
23
24
  }, scheme?: string) => string;
24
25
  export declare const buildVideoUrl: (filePath: string) => string;
26
+ export { normalizeFileUrl };
25
27
  export declare const safeDecode: (path: string) => string;
26
28
  export declare const safeEncode: (path: string) => string;
27
29
  export declare const buildFileUrl: (normalizedPath: string) => string;
28
- export declare const fileUrlToPath: (url?: string) => string | undefined;
30
+ export declare const fileUrlToPath: (url?: string, decode?: boolean) => string | undefined;
29
31
  export declare const parseInformations: (informations?: Array<JSONObject>) => Array<RouteInfoText>;
30
32
  export declare const fixIncorrectFileInfo: (file: Partial<FileInfo>) => void;
31
33
  export declare const getUtf8Data: (res: string | Buffer) => string;
@@ -0,0 +1,2 @@
1
+ export declare const normalizeFileUrl: (url?: string) => string | undefined;
2
+ export declare const isWindows: () => boolean;
@@ -0,0 +1,4 @@
1
+ import { WorkoutCalendarEntry } from "./types";
2
+ export declare const SOURCE_PRIORITY: string[];
3
+ export declare const getContentKey: (entry: WorkoutCalendarEntry) => string | undefined;
4
+ export declare const dedupeCalendarEntries: (entries: Array<WorkoutCalendarEntry>) => Array<WorkoutCalendarEntry>;
@@ -31,6 +31,7 @@ export declare class WorkoutCalendarService extends IncyclistService {
31
31
  onAppDisable(app: string, operation: string): void;
32
32
  protected loadFromRepo(): Promise<any[]>;
33
33
  protected saveToRepo(): Promise<void>;
34
+ protected getVisibleWorkouts(): Array<WorkoutCalendarEntry>;
34
35
  protected getScheduledWorkout(w: WorkoutCalendarEntry): ScheduledWorkout;
35
36
  protected startSync(initial?: boolean): void;
36
37
  protected stopSync(): void;
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.9.36",
3
+ "version": "1.9.38",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.27"
6
6
  },
7
7
  "dependencies": {
8
8
  "@garmin/fitsdk": "^21.222.0",
9
9
  "axios": "^1.21.1",
10
- "incyclist-devices": "^3.0.50",
10
+ "incyclist-devices": "^3.0.51",
11
11
  "promise.any": "^2.0.6",
12
12
  "semver": "^7.8.6",
13
13
  "tcx-builder": "^1.1.1",