incyclist-services 1.0.7 → 1.0.8
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,6 +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
30
|
protected getDeviceConfigurationInfo(): DeviceConfigurationInfo;
|
|
30
31
|
protected emitCapabiltyChanged(capability?: ExtendedIncyclistCapability): void;
|
|
31
32
|
protected emitInitialized(): void;
|
|
@@ -61,6 +61,7 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
61
61
|
this.logError(err, 'init()');
|
|
62
62
|
}
|
|
63
63
|
this.emitInitialized();
|
|
64
|
+
return;
|
|
64
65
|
}
|
|
65
66
|
this.settings = {
|
|
66
67
|
devices: this.userSettings.get('devices', []),
|
|
@@ -88,6 +89,7 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
88
89
|
this.logError(err, 'init()->Adapterfactory.create()');
|
|
89
90
|
}
|
|
90
91
|
});
|
|
92
|
+
this.removeLegacySettings();
|
|
91
93
|
this.emitInitialized();
|
|
92
94
|
});
|
|
93
95
|
}
|
|
@@ -118,6 +120,7 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
118
120
|
}
|
|
119
121
|
initFromLegacy(settings = {}) {
|
|
120
122
|
var _a, _b, _c, _d, _e;
|
|
123
|
+
this.logEvent({ message: 'converting settings.json' });
|
|
121
124
|
const { gearSelection, connections, modeSettings = {} } = settings;
|
|
122
125
|
const { bikes = [], hrms = [] } = gearSelection || {};
|
|
123
126
|
this.settings = { interfaces: [], devices: [], capabilities: [] };
|
|
@@ -136,7 +139,13 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
136
139
|
delete bike.displayName;
|
|
137
140
|
if (bike.interface === 'ant')
|
|
138
141
|
delete bike.name;
|
|
139
|
-
|
|
142
|
+
let adapter;
|
|
143
|
+
try {
|
|
144
|
+
adapter = incyclist_devices_1.AdapterFactory.create(bike);
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
this.logError(err, 'initFromLegacy#bike');
|
|
148
|
+
}
|
|
140
149
|
if (!adapter) {
|
|
141
150
|
return;
|
|
142
151
|
}
|
|
@@ -186,7 +195,13 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
186
195
|
delete hrm.displayName;
|
|
187
196
|
if (hrm.interface === 'ant')
|
|
188
197
|
delete hrm.name;
|
|
189
|
-
|
|
198
|
+
let adapter;
|
|
199
|
+
try {
|
|
200
|
+
adapter = incyclist_devices_1.AdapterFactory.create(hrm);
|
|
201
|
+
}
|
|
202
|
+
catch (err) {
|
|
203
|
+
this.logError(err, 'initFromLegacy#bike');
|
|
204
|
+
}
|
|
190
205
|
if (!adapter) {
|
|
191
206
|
return;
|
|
192
207
|
}
|
|
@@ -220,12 +235,18 @@ class DeviceConfigurationService extends events_1.default {
|
|
|
220
235
|
else
|
|
221
236
|
capabilities.push({ capability: incyclist_devices_1.IncyclistCapability.HeartRate, devices: [], selected: undefined, disabled: true });
|
|
222
237
|
}
|
|
223
|
-
this.
|
|
224
|
-
this.userSettings.set('gearSelection', null);
|
|
225
|
-
this.userSettings.set('preferences.gear', null);
|
|
238
|
+
this.removeLegacySettings();
|
|
226
239
|
this.settings = { devices, capabilities, interfaces };
|
|
227
240
|
this.updateUserSettings();
|
|
228
241
|
}
|
|
242
|
+
removeLegacySettings() {
|
|
243
|
+
if (this.userSettings.get('connections', null) !== null)
|
|
244
|
+
this.userSettings.set('connections', null);
|
|
245
|
+
if (this.userSettings.get('gearSelection', null) !== null)
|
|
246
|
+
this.userSettings.set('gearSelection', null);
|
|
247
|
+
if (this.userSettings.get('preferences.gear', null) !== null)
|
|
248
|
+
this.userSettings.set('preferences.gear', null);
|
|
249
|
+
}
|
|
229
250
|
getDeviceConfigurationInfo() {
|
|
230
251
|
const { capabilities = [], devices = [] } = this.settings;
|
|
231
252
|
const { adapters } = this;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export interface IUserSettingsBinding {
|
|
2
2
|
getAll(): Promise<any>;
|
|
3
3
|
set(key: string, value: any): Promise<boolean>;
|
|
4
|
-
save(settings: any): Promise<boolean>;
|
|
4
|
+
save(settings: any, final?: boolean): Promise<boolean>;
|
|
5
5
|
canOverwrite(): boolean;
|
|
6
6
|
}
|
|
7
7
|
export declare abstract class UserSettingsBinding implements IUserSettingsBinding {
|
|
8
8
|
static getInstance(): IUserSettingsBinding;
|
|
9
9
|
abstract getAll(): Promise<any>;
|
|
10
10
|
abstract set(key: string, value: any): Promise<boolean>;
|
|
11
|
-
abstract save(settings: any): Promise<boolean>;
|
|
11
|
+
abstract save(settings: any, final?: boolean): Promise<boolean>;
|
|
12
12
|
abstract canOverwrite(): boolean;
|
|
13
13
|
}
|
|
@@ -18,6 +18,7 @@ export declare class UserSettingsService {
|
|
|
18
18
|
update(data: any): Promise<boolean>;
|
|
19
19
|
updateSettings(data: any): Promise<boolean>;
|
|
20
20
|
save(): Promise<void>;
|
|
21
|
+
onAppClose(): Promise<void>;
|
|
21
22
|
}
|
|
22
23
|
export declare const useUserSettings: () => UserSettingsService;
|
|
23
24
|
export declare const initUserSettings: (binding: IUserSettingsBinding) => UserSettingsService;
|
|
@@ -16,7 +16,6 @@ exports.initUserSettings = exports.useUserSettings = exports.UserSettingsService
|
|
|
16
16
|
const gd_eventlog_1 = require("gd-eventlog");
|
|
17
17
|
const clone_1 = __importDefault(require("../../utils/clone"));
|
|
18
18
|
const merge_1 = require("../../utils/merge");
|
|
19
|
-
const sleep_1 = require("../../utils/sleep");
|
|
20
19
|
const valid_1 = require("../../utils/valid");
|
|
21
20
|
class UserSettingsService {
|
|
22
21
|
constructor() {
|
|
@@ -83,8 +82,6 @@ class UserSettingsService {
|
|
|
83
82
|
set(key, value) {
|
|
84
83
|
if (!this.isInitialized)
|
|
85
84
|
throw new Error('Settings are not yet initialized');
|
|
86
|
-
if (!this.binding.canOverwrite())
|
|
87
|
-
this.binding.set(key, value);
|
|
88
85
|
const settings = this.settings;
|
|
89
86
|
if (key === undefined || key === null || key === '') {
|
|
90
87
|
throw new Error('key must be specified');
|
|
@@ -147,21 +144,27 @@ class UserSettingsService {
|
|
|
147
144
|
return;
|
|
148
145
|
}
|
|
149
146
|
this.savePromise = this.binding.save(this.settings);
|
|
147
|
+
this.isDirty = false;
|
|
150
148
|
try {
|
|
151
149
|
yield this.savePromise;
|
|
152
150
|
this.savePromise = null;
|
|
153
|
-
|
|
154
|
-
yield (0, sleep_1.sleep)(50);
|
|
151
|
+
if (this.isDirty) {
|
|
155
152
|
this.isDirty = false;
|
|
156
153
|
yield this.save();
|
|
157
154
|
}
|
|
158
155
|
}
|
|
159
156
|
catch (err) {
|
|
160
|
-
this.
|
|
157
|
+
this.logger.logEvent({ message: 'Error', fn: 'save()', error: err.message, stack: err.stack });
|
|
158
|
+
this.isDirty = false;
|
|
161
159
|
}
|
|
162
160
|
return;
|
|
163
161
|
});
|
|
164
162
|
}
|
|
163
|
+
onAppClose() {
|
|
164
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
this.binding.save(this.settings, true);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
165
168
|
}
|
|
166
169
|
exports.UserSettingsService = UserSettingsService;
|
|
167
170
|
const useUserSettings = () => UserSettingsService.getInstance();
|