incyclist-services 1.0.8 → 1.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/devices/access/model.d.ts +2 -2
- package/lib/devices/access/service.d.ts +1 -1
- package/lib/devices/access/service.js +15 -14
- package/lib/devices/configuration/model/app/index.d.ts +1 -1
- package/lib/devices/configuration/model/repository/index.d.ts +2 -2
- package/lib/devices/configuration/service.js +16 -5
- package/lib/devices/ride/service.js +5 -5
- package/lib/settings/user/bindings/json.js +5 -5
- package/lib/settings/user/service.js +6 -6
- package/package.json +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DeviceSettings, IncyclistCapability } from "incyclist-devices";
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export type InterfaceState = 'connected' | 'disconnected' | 'unknown' | 'connecting' | 'disconnecting' | 'unavailable';
|
|
3
|
+
export type ScanState = 'start-requested' | 'started' | 'stop-requested' | 'stopped' | 'idle';
|
|
4
4
|
export interface InterfaceInfo {
|
|
5
5
|
name: string;
|
|
6
6
|
enabled: boolean;
|
|
@@ -18,7 +18,7 @@ export declare class DeviceAccessService extends EventEmitter {
|
|
|
18
18
|
protected logEvent(event: any): void;
|
|
19
19
|
setDefaultInterfaceProperties(props: InterfaceAccessProps): void;
|
|
20
20
|
enableInterface(ifaceName: string, binding?: any, props?: InterfaceAccessProps): void;
|
|
21
|
-
disableInterface(ifaceName: string): void;
|
|
21
|
+
disableInterface(ifaceName: string, avalailable?: boolean): void;
|
|
22
22
|
setInterfaceProperties(ifaceName: string, props: InterfaceAccessProps): void;
|
|
23
23
|
getInterfaceInfo(ifaceName: string): InterfaceInfo;
|
|
24
24
|
protected getInterface(ifaceName: string): IncyclistInterface;
|
|
@@ -21,6 +21,11 @@ const merge_1 = require("../../utils/merge");
|
|
|
21
21
|
const sleep_1 = require("../../utils/sleep");
|
|
22
22
|
const configuration_1 = require("../configuration");
|
|
23
23
|
class DeviceAccessService extends events_1.default {
|
|
24
|
+
static getInstance() {
|
|
25
|
+
if (!DeviceAccessService._instance)
|
|
26
|
+
DeviceAccessService._instance = new DeviceAccessService();
|
|
27
|
+
return DeviceAccessService._instance;
|
|
28
|
+
}
|
|
24
29
|
constructor() {
|
|
25
30
|
super();
|
|
26
31
|
this.interfaces = {};
|
|
@@ -28,11 +33,6 @@ class DeviceAccessService extends events_1.default {
|
|
|
28
33
|
this.logger = new gd_eventlog_1.EventLogger('DeviceAccess');
|
|
29
34
|
this.defaultProps = {};
|
|
30
35
|
}
|
|
31
|
-
static getInstance() {
|
|
32
|
-
if (!DeviceAccessService._instance)
|
|
33
|
-
DeviceAccessService._instance = new DeviceAccessService();
|
|
34
|
-
return DeviceAccessService._instance;
|
|
35
|
-
}
|
|
36
36
|
logEvent(event) {
|
|
37
37
|
this.logger.logEvent(event);
|
|
38
38
|
const w = global.window;
|
|
@@ -69,7 +69,7 @@ class DeviceAccessService extends events_1.default {
|
|
|
69
69
|
this.emit('interface-changed', ifaceName, this.interfaces[ifaceName]);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
disableInterface(ifaceName) {
|
|
72
|
+
disableInterface(ifaceName, avalailable = true) {
|
|
73
73
|
const existing = this.interfaces[ifaceName];
|
|
74
74
|
if (!existing)
|
|
75
75
|
return;
|
|
@@ -84,6 +84,12 @@ class DeviceAccessService extends events_1.default {
|
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
86
|
existing.enabled = false;
|
|
87
|
+
if (!avalailable) {
|
|
88
|
+
existing.state = 'unavailable';
|
|
89
|
+
existing.unavailable = true;
|
|
90
|
+
this.emit('interface-changed', ifaceName, { name: ifaceName, state: 'unavailable', isScanning: false });
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
87
93
|
this.emit('interface-changed', ifaceName, this.interfaces[ifaceName]);
|
|
88
94
|
}
|
|
89
95
|
setInterfaceProperties(ifaceName, props) {
|
|
@@ -175,21 +181,17 @@ class DeviceAccessService extends events_1.default {
|
|
|
175
181
|
interfaces.forEach((i) => {
|
|
176
182
|
i.on('device', (deviceSettings) => __awaiter(this, void 0, void 0, function* () {
|
|
177
183
|
var _a, _b;
|
|
178
|
-
console.log('~~~ detected device:', deviceSettings);
|
|
179
184
|
if (adapters.find(a => a.isEqual(deviceSettings))) {
|
|
180
|
-
console.log('~~~ device already detected');
|
|
181
185
|
return;
|
|
182
186
|
}
|
|
183
187
|
if (filter.profile && deviceSettings.profile !== filter.profile) {
|
|
184
|
-
console.log('~~~ device does not match profile', filter.profile);
|
|
185
188
|
return;
|
|
186
189
|
}
|
|
187
190
|
if (filter.protocol && deviceSettings.protocol !== filter.protocol) {
|
|
188
|
-
console.log('~~~ device does not match protocol', filter.protocol);
|
|
189
191
|
return;
|
|
190
192
|
}
|
|
191
193
|
if (filter.protocols && !filter.protocols.includes(deviceSettings.protocol)) {
|
|
192
|
-
|
|
194
|
+
return;
|
|
193
195
|
}
|
|
194
196
|
const adapter = incyclist_devices_1.AdapterFactory.create(deviceSettings);
|
|
195
197
|
if (filter.capabilities) {
|
|
@@ -198,7 +200,6 @@ class DeviceAccessService extends events_1.default {
|
|
|
198
200
|
found = found || adapter.getCapabilities().includes(capability);
|
|
199
201
|
});
|
|
200
202
|
if (!found) {
|
|
201
|
-
console.log('~~~ device does not match capabilties', filter.capabilities);
|
|
202
203
|
return;
|
|
203
204
|
}
|
|
204
205
|
}
|
|
@@ -219,11 +220,11 @@ class DeviceAccessService extends events_1.default {
|
|
|
219
220
|
yield adapter.stop();
|
|
220
221
|
}
|
|
221
222
|
catch (err) {
|
|
222
|
-
|
|
223
|
+
this.logEvent({ message: 'could not start device', device: adapter === null || adapter === void 0 ? void 0 : adapter.getUniqueName(), reason: err.message });
|
|
223
224
|
}
|
|
224
225
|
}
|
|
225
226
|
catch (err) {
|
|
226
|
-
|
|
227
|
+
this.logEvent({ message: 'error', fn: 'scan#adapte', error: err.message, stack: err.stack });
|
|
227
228
|
}
|
|
228
229
|
}
|
|
229
230
|
}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IncyclistCapability } from 'incyclist-devices';
|
|
2
|
-
export
|
|
2
|
+
export type ExtendedIncyclistCapability = IncyclistCapability | 'bike';
|
|
3
3
|
export interface DeviceInformation {
|
|
4
4
|
udid: string;
|
|
5
5
|
name: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SerialDeviceSettings, AntDeviceSettings, BleDeviceSettings } from 'incyclist-devices';
|
|
2
2
|
import { ExtendedIncyclistCapability } from '../app';
|
|
3
|
-
export
|
|
3
|
+
export type IncyclistDeviceSettings = SerialDeviceSettings | AntDeviceSettings | BleDeviceSettings;
|
|
4
4
|
export * from './legacy';
|
|
5
5
|
export interface DeviceListEntry {
|
|
6
6
|
udid: string;
|
|
@@ -22,7 +22,7 @@ export interface ModeListEntry {
|
|
|
22
22
|
mode: string;
|
|
23
23
|
setting: any;
|
|
24
24
|
}
|
|
25
|
-
export
|
|
25
|
+
export type CapabilitySetting = {
|
|
26
26
|
selected: string | undefined;
|
|
27
27
|
capability: ExtendedIncyclistCapability;
|
|
28
28
|
disabled?: boolean;
|
|
@@ -20,17 +20,17 @@ const events_1 = __importDefault(require("events"));
|
|
|
20
20
|
const merge_1 = require("../../utils/merge");
|
|
21
21
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
22
22
|
class DeviceConfigurationService extends events_1.default {
|
|
23
|
+
static getInstance() {
|
|
24
|
+
if (!DeviceConfigurationService._instance)
|
|
25
|
+
DeviceConfigurationService._instance = new DeviceConfigurationService();
|
|
26
|
+
return DeviceConfigurationService._instance;
|
|
27
|
+
}
|
|
23
28
|
constructor() {
|
|
24
29
|
super();
|
|
25
30
|
this.adapters = {};
|
|
26
31
|
this.userSettings = (0, settings_1.useUserSettings)();
|
|
27
32
|
this.logger = new gd_eventlog_1.EventLogger('DeviceConfig');
|
|
28
33
|
}
|
|
29
|
-
static getInstance() {
|
|
30
|
-
if (!DeviceConfigurationService._instance)
|
|
31
|
-
DeviceConfigurationService._instance = new DeviceConfigurationService();
|
|
32
|
-
return DeviceConfigurationService._instance;
|
|
33
|
-
}
|
|
34
34
|
logEvent(e) {
|
|
35
35
|
var _a;
|
|
36
36
|
(_a = this.logger) === null || _a === void 0 ? void 0 : _a.logEvent(e);
|
|
@@ -48,6 +48,7 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
48
48
|
this.emitInitialized();
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
+
this.logEvent({ message: 'DeviceConfig.init' });
|
|
51
52
|
yield this.userSettings.init();
|
|
52
53
|
if (this.userSettings.get('devices', null) == null && (this.userSettings.get('gearSelection', null) !== null || this.userSettings.get('connections', null) !== null)) {
|
|
53
54
|
const settings = {};
|
|
@@ -90,6 +91,7 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
90
91
|
}
|
|
91
92
|
});
|
|
92
93
|
this.removeLegacySettings();
|
|
94
|
+
this.logEvent({ message: 'DeviceConfig.init done' });
|
|
93
95
|
this.emitInitialized();
|
|
94
96
|
});
|
|
95
97
|
}
|
|
@@ -287,6 +289,7 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
287
289
|
}
|
|
288
290
|
select(udid, capability, props) {
|
|
289
291
|
var _a, _b, _c;
|
|
292
|
+
this.logEvent({ message: 'select device', udid, capability, props });
|
|
290
293
|
const { noRecursive = false, legacy = false } = props || {};
|
|
291
294
|
const deviceSettings = (_b = (_a = this.settings.devices) === null || _a === void 0 ? void 0 : _a.find(d => d.udid === udid)) === null || _b === void 0 ? void 0 : _b.settings;
|
|
292
295
|
if (!deviceSettings)
|
|
@@ -335,6 +338,7 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
335
338
|
this.updateUserSettings();
|
|
336
339
|
}
|
|
337
340
|
unselect(capability) {
|
|
341
|
+
this.logEvent({ message: 'unselect device', capability });
|
|
338
342
|
if (!this.settings || !this.settings.capabilities)
|
|
339
343
|
return;
|
|
340
344
|
const settings = this.settings.capabilities.find(c => c.capability === capability);
|
|
@@ -347,6 +351,7 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
347
351
|
add(deviceSettings, legacyMode = false) {
|
|
348
352
|
var _a, _b;
|
|
349
353
|
let udid = this.getUdid(deviceSettings);
|
|
354
|
+
this.logEvent({ message: 'add device', udid, deviceSettings, legacyMode });
|
|
350
355
|
const deviceAlreadyExists = udid !== undefined;
|
|
351
356
|
let adapter;
|
|
352
357
|
if (deviceAlreadyExists) {
|
|
@@ -401,6 +406,7 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
401
406
|
}
|
|
402
407
|
delete(udid, capability, forceSingle = false) {
|
|
403
408
|
var _a;
|
|
409
|
+
this.logEvent({ message: 'delete device', udid, capability, forceSingle });
|
|
404
410
|
const deviceSettings = (_a = this.settings.devices.find(d => d.udid === udid)) === null || _a === void 0 ? void 0 : _a.settings;
|
|
405
411
|
if (!deviceSettings)
|
|
406
412
|
return;
|
|
@@ -545,6 +551,7 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
545
551
|
}
|
|
546
552
|
}
|
|
547
553
|
setMode(udid, mode) {
|
|
554
|
+
this.logEvent({ message: 'set device mode', udid, mode });
|
|
548
555
|
if (!this.isInitialized())
|
|
549
556
|
return;
|
|
550
557
|
const device = this.settings.devices.find(d => d.udid === udid);
|
|
@@ -558,6 +565,7 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
558
565
|
this.emitModeChanged(udid, mode, settings);
|
|
559
566
|
}
|
|
560
567
|
setModeSettings(udid, mode, settings) {
|
|
568
|
+
this.logEvent({ message: 'set device mode settings', udid, mode, settings });
|
|
561
569
|
if (!this.isInitialized())
|
|
562
570
|
return;
|
|
563
571
|
const device = this.settings.devices.find(d => d.udid === udid);
|
|
@@ -644,6 +652,7 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
644
652
|
return setting.enabled;
|
|
645
653
|
}
|
|
646
654
|
enableInterface(ifName) {
|
|
655
|
+
this.logEvent({ message: 'enable interface', ifName });
|
|
647
656
|
const setting = this.getInterfaceSettings(ifName);
|
|
648
657
|
if (setting)
|
|
649
658
|
setting.enabled = true;
|
|
@@ -653,6 +662,7 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
653
662
|
this.emitInterfaceChanged(ifName);
|
|
654
663
|
}
|
|
655
664
|
disableInterface(ifName) {
|
|
665
|
+
this.logEvent({ message: 'disable interface', ifName });
|
|
656
666
|
const setting = this.getInterfaceSettings(ifName);
|
|
657
667
|
if (setting)
|
|
658
668
|
setting.enabled = false;
|
|
@@ -662,6 +672,7 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
662
672
|
this.emitInterfaceChanged(ifName);
|
|
663
673
|
}
|
|
664
674
|
setInterfaceSettings(ifName, settings) {
|
|
675
|
+
this.logEvent({ message: 'set interface settings', ifName, settings });
|
|
665
676
|
if (settings.name && settings.name !== ifName)
|
|
666
677
|
return;
|
|
667
678
|
const idx = this.settings.interfaces.findIndex(i => i.name === ifName);
|
|
@@ -23,6 +23,11 @@ const settings_1 = require("../../settings");
|
|
|
23
23
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
24
24
|
const logging_1 = require("../../utils/logging");
|
|
25
25
|
class DeviceRideService extends events_1.default {
|
|
26
|
+
static getInstance() {
|
|
27
|
+
if (!DeviceRideService._instance)
|
|
28
|
+
DeviceRideService._instance = new DeviceRideService();
|
|
29
|
+
return DeviceRideService._instance;
|
|
30
|
+
}
|
|
26
31
|
constructor() {
|
|
27
32
|
super();
|
|
28
33
|
this.data = {};
|
|
@@ -32,11 +37,6 @@ class DeviceRideService extends events_1.default {
|
|
|
32
37
|
this.logger = new gd_eventlog_1.EventLogger('Ride');
|
|
33
38
|
this.debug = false;
|
|
34
39
|
}
|
|
35
|
-
static getInstance() {
|
|
36
|
-
if (!DeviceRideService._instance)
|
|
37
|
-
DeviceRideService._instance = new DeviceRideService();
|
|
38
|
-
return DeviceRideService._instance;
|
|
39
|
-
}
|
|
40
40
|
logEvent(event) {
|
|
41
41
|
this.logger.logEvent(event);
|
|
42
42
|
const w = global.window;
|
|
@@ -16,16 +16,16 @@ const types_1 = require("./types");
|
|
|
16
16
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
17
17
|
const DEFAULT_PATH = './settings.json';
|
|
18
18
|
class JSONFileBindig extends types_1.UserSettingsBinding {
|
|
19
|
-
constructor(path = DEFAULT_PATH) {
|
|
20
|
-
super();
|
|
21
|
-
this.path = path;
|
|
22
|
-
this.savePromise = null;
|
|
23
|
-
}
|
|
24
19
|
static getInstance(path) {
|
|
25
20
|
if (!JSONFileBindig._instance)
|
|
26
21
|
JSONFileBindig._instance = new JSONFileBindig(path);
|
|
27
22
|
return JSONFileBindig._instance;
|
|
28
23
|
}
|
|
24
|
+
constructor(path = DEFAULT_PATH) {
|
|
25
|
+
super();
|
|
26
|
+
this.path = path;
|
|
27
|
+
this.savePromise = null;
|
|
28
|
+
}
|
|
29
29
|
getAll() {
|
|
30
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
31
|
const settings = yield promises_1.default.readFile(this.path);
|
|
@@ -18,6 +18,12 @@ const clone_1 = __importDefault(require("../../utils/clone"));
|
|
|
18
18
|
const merge_1 = require("../../utils/merge");
|
|
19
19
|
const valid_1 = require("../../utils/valid");
|
|
20
20
|
class UserSettingsService {
|
|
21
|
+
static getInstance() {
|
|
22
|
+
if (!UserSettingsService._instance) {
|
|
23
|
+
UserSettingsService._instance = new UserSettingsService();
|
|
24
|
+
}
|
|
25
|
+
return UserSettingsService._instance;
|
|
26
|
+
}
|
|
21
27
|
constructor() {
|
|
22
28
|
this.settings = {};
|
|
23
29
|
this.logger = new gd_eventlog_1.EventLogger('UserSettings');
|
|
@@ -25,12 +31,6 @@ class UserSettingsService {
|
|
|
25
31
|
this.isDirty = false;
|
|
26
32
|
this.savePromise = null;
|
|
27
33
|
}
|
|
28
|
-
static getInstance() {
|
|
29
|
-
if (!UserSettingsService._instance) {
|
|
30
|
-
UserSettingsService._instance = new UserSettingsService();
|
|
31
|
-
}
|
|
32
|
-
return UserSettingsService._instance;
|
|
33
|
-
}
|
|
34
34
|
setBinding(binding) {
|
|
35
35
|
this.binding = binding;
|
|
36
36
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "incyclist-services",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"gd-eventlog": "^0.1.22"
|
|
6
6
|
},
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"lib": "./src"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"incyclist-devices": "^2.0.
|
|
39
|
+
"incyclist-devices": "^2.0.9",
|
|
40
40
|
"uuid": "^9.0.0"
|
|
41
41
|
}
|
|
42
42
|
}
|