incyclist-services 1.0.20 → 1.0.22
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.
|
@@ -26,7 +26,7 @@ export declare class DeviceConfigurationService extends EventEmitter {
|
|
|
26
26
|
protected initInterfaces(): void;
|
|
27
27
|
isInitialized(): boolean;
|
|
28
28
|
initFromLegacy(settings?: LegacySettings): void;
|
|
29
|
-
protected removeLegacySettings(): void
|
|
29
|
+
protected removeLegacySettings(): Promise<void>;
|
|
30
30
|
protected getDeviceConfigurationInfo(): DeviceConfigurationInfo;
|
|
31
31
|
protected emitCapabiltyChanged(capability?: ExtendedIncyclistCapability): void;
|
|
32
32
|
protected emitInitialized(): void;
|
|
@@ -19,6 +19,7 @@ const uuid_1 = require("uuid");
|
|
|
19
19
|
const events_1 = __importDefault(require("events"));
|
|
20
20
|
const merge_1 = require("../../utils/merge");
|
|
21
21
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
22
|
+
const clone_1 = __importDefault(require("../../utils/clone"));
|
|
22
23
|
class DeviceConfigurationService extends events_1.default {
|
|
23
24
|
static getInstance() {
|
|
24
25
|
if (!DeviceConfigurationService._instance)
|
|
@@ -49,8 +50,7 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
49
50
|
return;
|
|
50
51
|
}
|
|
51
52
|
this.logEvent({ message: 'DeviceConfig.init' });
|
|
52
|
-
|
|
53
|
-
if (this.userSettings.get('devices', null) == null && (this.userSettings.get('gearSelection', null) !== null || this.userSettings.get('connections', null) !== null)) {
|
|
53
|
+
if ((this.userSettings.get('gearSelection', 'removed') !== 'removed' || this.userSettings.get('connections', 'removed') !== 'removed')) {
|
|
54
54
|
const settings = {};
|
|
55
55
|
settings.connections = this.userSettings.get('connections', {});
|
|
56
56
|
settings.gearSelection = this.userSettings.get('gearSelection', {});
|
|
@@ -64,6 +64,7 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
64
64
|
this.emitInitialized();
|
|
65
65
|
return;
|
|
66
66
|
}
|
|
67
|
+
yield this.userSettings.init();
|
|
67
68
|
this.settings = {
|
|
68
69
|
devices: this.userSettings.get('devices', []),
|
|
69
70
|
capabilities: this.userSettings.get('capabilities', []),
|
|
@@ -129,8 +130,9 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
129
130
|
initFromLegacy(settings = {}) {
|
|
130
131
|
var _a, _b, _c, _d, _e;
|
|
131
132
|
const { gearSelection, connections, modeSettings = {} } = settings;
|
|
132
|
-
this.logEvent({ message: 'converting settings.json', gearSelection });
|
|
133
|
-
const
|
|
133
|
+
this.logEvent({ message: 'converting settings.json', gearSelection, connections });
|
|
134
|
+
const gears = (0, clone_1.default)(gearSelection || {});
|
|
135
|
+
const { bikes = [], hrms = [] } = gears;
|
|
134
136
|
this.settings = { interfaces: [], devices: [], capabilities: [] };
|
|
135
137
|
const { interfaces, devices, capabilities } = this.settings;
|
|
136
138
|
interfaces.push({ name: 'ant', enabled: ((_a = connections === null || connections === void 0 ? void 0 : connections.ant) === null || _a === void 0 ? void 0 : _a.enabled) || true });
|
|
@@ -191,7 +193,7 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
191
193
|
});
|
|
192
194
|
const key = legacyProfile ? `${legacyProtocol}-${legacyProfile}` : legacyProtocol;
|
|
193
195
|
const modeInfo = modeSettings[key];
|
|
194
|
-
if (modeInfo) {
|
|
196
|
+
if (modeInfo && deviceEntry) {
|
|
195
197
|
deviceEntry.modes = {};
|
|
196
198
|
deviceEntry.modes[modeInfo.mode] = modeInfo.settings;
|
|
197
199
|
deviceEntry.mode = modeInfo.mode;
|
|
@@ -248,12 +250,16 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
248
250
|
this.updateUserSettings();
|
|
249
251
|
}
|
|
250
252
|
removeLegacySettings() {
|
|
251
|
-
|
|
252
|
-
this.userSettings.set('connections',
|
|
253
|
-
|
|
254
|
-
this.userSettings.set('
|
|
255
|
-
|
|
256
|
-
this.userSettings.set('
|
|
253
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
254
|
+
this.userSettings.set('connections', 'removed', false);
|
|
255
|
+
this.userSettings.set('gearSelection', 'removed', false);
|
|
256
|
+
this.userSettings.set('preferences.gear', 'removed', false);
|
|
257
|
+
yield this.userSettings.save();
|
|
258
|
+
this.userSettings.set('connections', null, false);
|
|
259
|
+
this.userSettings.set('gearSelection', null, false);
|
|
260
|
+
this.userSettings.set('preferences.gear', null, false);
|
|
261
|
+
yield this.userSettings.save();
|
|
262
|
+
});
|
|
257
263
|
}
|
|
258
264
|
getDeviceConfigurationInfo() {
|
|
259
265
|
const { capabilities = [], devices = [] } = this.settings;
|
|
@@ -14,7 +14,7 @@ export declare class UserSettingsService {
|
|
|
14
14
|
init(): Promise<boolean>;
|
|
15
15
|
getAll(): any;
|
|
16
16
|
get(key: string, defValue: any): any;
|
|
17
|
-
set(key: string, value: any): void;
|
|
17
|
+
set(key: string, value: any, save?: boolean): void;
|
|
18
18
|
update(data: any): Promise<boolean>;
|
|
19
19
|
updateSettings(data: any): Promise<boolean>;
|
|
20
20
|
save(): Promise<void>;
|
|
@@ -79,7 +79,7 @@ class UserSettingsService {
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
set(key, value) {
|
|
82
|
+
set(key, value, save = true) {
|
|
83
83
|
if (!this.isInitialized)
|
|
84
84
|
throw new Error('Settings are not yet initialized');
|
|
85
85
|
const settings = this.settings;
|
|
@@ -92,7 +92,8 @@ class UserSettingsService {
|
|
|
92
92
|
delete settings[key];
|
|
93
93
|
else
|
|
94
94
|
settings[key] = value;
|
|
95
|
-
|
|
95
|
+
if (save)
|
|
96
|
+
this.save();
|
|
96
97
|
return value;
|
|
97
98
|
}
|
|
98
99
|
let child = {};
|
|
@@ -103,7 +104,8 @@ class UserSettingsService {
|
|
|
103
104
|
delete child[k];
|
|
104
105
|
else
|
|
105
106
|
child[k] = value;
|
|
106
|
-
|
|
107
|
+
if (save)
|
|
108
|
+
this.save();
|
|
107
109
|
return value;
|
|
108
110
|
}
|
|
109
111
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "incyclist-services",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.22",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"gd-eventlog": "^0.1.24"
|
|
6
6
|
},
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"lib": "./src"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"incyclist-devices": "^2.0.
|
|
40
|
+
"incyclist-devices": "^2.0.24",
|
|
41
41
|
"uuid": "^9.0.0"
|
|
42
42
|
}
|
|
43
43
|
}
|