@onekeyfe/hd-core 0.1.0 → 0.1.3
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/dist/api/CheckBLEFirmwareRelease.d.ts +8 -1
- package/dist/api/CheckBLEFirmwareRelease.d.ts.map +1 -1
- package/dist/api/CheckFirmwareRelease.d.ts +8 -1
- package/dist/api/CheckFirmwareRelease.d.ts.map +1 -1
- package/dist/constants/errors.d.ts +1 -0
- package/dist/constants/errors.d.ts.map +1 -1
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +10 -0
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/device/Device.d.ts +2 -1
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts.map +1 -1
- package/dist/device/DeviceList.d.ts.map +1 -1
- package/dist/events/call.d.ts +7 -0
- package/dist/events/call.d.ts.map +1 -1
- package/dist/events/core.d.ts +2 -2
- package/dist/events/core.d.ts.map +1 -1
- package/dist/events/iframe.d.ts +1 -0
- package/dist/events/iframe.d.ts.map +1 -1
- package/dist/index.d.ts +42 -6
- package/dist/index.js +143 -47
- package/dist/types/api/checkBLEFirmwareRelease.d.ts +12 -2
- package/dist/types/api/checkBLEFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/checkFirmwareRelease.d.ts +11 -1
- package/dist/types/api/checkFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/index.d.ts +1 -1
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/utils/release.d.ts +4 -0
- package/dist/utils/release.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/api/CheckBLEFirmwareRelease.ts +7 -1
- package/src/api/CheckFirmwareRelease.ts +7 -1
- package/src/constants/errors.ts +1 -0
- package/src/core/index.ts +28 -1
- package/src/data-manager/DataManager.ts +36 -20
- package/src/device/Device.ts +18 -11
- package/src/device/DeviceCommands.ts +4 -0
- package/src/device/DeviceList.ts +13 -1
- package/src/events/call.ts +6 -0
- package/src/events/core.ts +2 -1
- package/src/events/iframe.ts +1 -0
- package/src/types/api/checkBLEFirmwareRelease.ts +12 -4
- package/src/types/api/checkFirmwareRelease.ts +11 -1
- package/src/types/api/index.ts +1 -1
- package/src/utils/release.ts +24 -0
|
@@ -18,6 +18,7 @@ import type {
|
|
|
18
18
|
IDeviceBLEFirmwareStatus,
|
|
19
19
|
ITransportStatus,
|
|
20
20
|
} from '../types';
|
|
21
|
+
import { getReleaseChangelog, getReleaseStatus } from '../utils/release';
|
|
21
22
|
|
|
22
23
|
export default class DataManager {
|
|
23
24
|
static deviceMap: DeviceTypeMap = {
|
|
@@ -59,21 +60,30 @@ export default class DataManager {
|
|
|
59
60
|
}
|
|
60
61
|
|
|
61
62
|
const targetDeviceConfigList = this.deviceMap[deviceType]?.firmware ?? [];
|
|
62
|
-
const latestFirmware = targetDeviceConfigList[targetDeviceConfigList.length - 1];
|
|
63
|
-
|
|
64
|
-
if (!latestFirmware) return 'valid';
|
|
65
|
-
|
|
66
|
-
const latestVersion = latestFirmware.version.join('.');
|
|
67
63
|
const currentVersion = deviceFirmwareVersion.join('.');
|
|
64
|
+
return getReleaseStatus(targetDeviceConfigList, currentVersion);
|
|
65
|
+
};
|
|
68
66
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
static getFirmwareChangelog = (features: Features) => {
|
|
68
|
+
const deviceType = getDeviceType(features);
|
|
69
|
+
const deviceFirmwareVersion = getDeviceFirmwareVersion(features);
|
|
72
70
|
|
|
73
|
-
|
|
71
|
+
if (
|
|
72
|
+
features.firmware_present === false ||
|
|
73
|
+
(deviceType === 'classic' && features.bootloader_mode)
|
|
74
|
+
) {
|
|
75
|
+
return [];
|
|
74
76
|
}
|
|
75
77
|
|
|
76
|
-
|
|
78
|
+
const targetDeviceConfigList = this.deviceMap[deviceType]?.firmware ?? [];
|
|
79
|
+
const currentVersion = deviceFirmwareVersion.join('.');
|
|
80
|
+
return getReleaseChangelog(targetDeviceConfigList, currentVersion);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
static getFirmwareLeatestRelease = (features: Features) => {
|
|
84
|
+
const deviceType = getDeviceType(features);
|
|
85
|
+
const targetDeviceConfigList = this.deviceMap[deviceType]?.firmware ?? [];
|
|
86
|
+
return targetDeviceConfigList[targetDeviceConfigList.length - 1];
|
|
77
87
|
};
|
|
78
88
|
|
|
79
89
|
static getBLEFirmwareStatus = (features: Features): IDeviceBLEFirmwareStatus => {
|
|
@@ -86,21 +96,27 @@ export default class DataManager {
|
|
|
86
96
|
}
|
|
87
97
|
|
|
88
98
|
const targetDeviceConfigList = this.deviceMap[deviceType]?.ble ?? [];
|
|
89
|
-
const latestBLEFirmware = targetDeviceConfigList[targetDeviceConfigList.length - 1];
|
|
90
|
-
|
|
91
|
-
if (!latestBLEFirmware) return 'valid';
|
|
92
|
-
|
|
93
|
-
const latestVersion = latestBLEFirmware.version.join('.');
|
|
94
99
|
const currentVersion = deviceBLEFirmwareVersion.join('.');
|
|
100
|
+
return getReleaseStatus(targetDeviceConfigList, currentVersion);
|
|
101
|
+
};
|
|
95
102
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
103
|
+
static getBleFirmwareChangelog = (features: Features) => {
|
|
104
|
+
const deviceType = getDeviceType(features);
|
|
105
|
+
const deviceBLEFirmwareVersion = getDeviceBLEFirmwareVersion(features);
|
|
99
106
|
|
|
100
|
-
|
|
107
|
+
if (!deviceBLEFirmwareVersion) {
|
|
108
|
+
return [];
|
|
101
109
|
}
|
|
102
110
|
|
|
103
|
-
|
|
111
|
+
const targetDeviceConfigList = this.deviceMap[deviceType]?.ble ?? [];
|
|
112
|
+
const currentVersion = deviceBLEFirmwareVersion.join('.');
|
|
113
|
+
return getReleaseChangelog(targetDeviceConfigList, currentVersion);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
static getBleFirmwareLeatestRelease = (features: Features) => {
|
|
117
|
+
const deviceType = getDeviceType(features);
|
|
118
|
+
const targetDeviceConfigList = this.deviceMap[deviceType]?.ble ?? [];
|
|
119
|
+
return targetDeviceConfigList[targetDeviceConfigList.length - 1];
|
|
104
120
|
};
|
|
105
121
|
|
|
106
122
|
static getTransportStatus = (localVersion: string): ITransportStatus => {
|
package/src/device/Device.ts
CHANGED
|
@@ -85,8 +85,6 @@ export class Device extends EventEmitter {
|
|
|
85
85
|
|
|
86
86
|
internalState: string[] = [];
|
|
87
87
|
|
|
88
|
-
loaded = false;
|
|
89
|
-
|
|
90
88
|
needReloadDevice = false;
|
|
91
89
|
|
|
92
90
|
/**
|
|
@@ -281,10 +279,19 @@ export class Device extends EventEmitter {
|
|
|
281
279
|
}
|
|
282
280
|
}
|
|
283
281
|
|
|
282
|
+
updateFromCache(device: Device) {
|
|
283
|
+
this.mainId = device.mainId;
|
|
284
|
+
this.commands = device.commands;
|
|
285
|
+
this.updateDescriptor(device.originalDescriptor);
|
|
286
|
+
if (device.features) {
|
|
287
|
+
this._updateFeatures(device.features);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
284
291
|
async run(fn?: () => Promise<void>, options?: RunOptions) {
|
|
285
292
|
if (this.runPromise) {
|
|
286
|
-
|
|
287
|
-
|
|
293
|
+
this.interruption();
|
|
294
|
+
Log.debug('[Device] run error:', 'Device is running, but will cancel previous operate');
|
|
288
295
|
}
|
|
289
296
|
|
|
290
297
|
options = parseRunOptions(options);
|
|
@@ -319,11 +326,6 @@ export class Device extends EventEmitter {
|
|
|
319
326
|
await fn();
|
|
320
327
|
}
|
|
321
328
|
|
|
322
|
-
// reload features
|
|
323
|
-
if (this.loaded && this.features) {
|
|
324
|
-
await this.getFeatures();
|
|
325
|
-
}
|
|
326
|
-
|
|
327
329
|
if (
|
|
328
330
|
(!this.keepSession && typeof options.keepSession !== 'boolean') ||
|
|
329
331
|
options.keepSession === false
|
|
@@ -338,9 +340,14 @@ export class Device extends EventEmitter {
|
|
|
338
340
|
}
|
|
339
341
|
|
|
340
342
|
this.runPromise = null;
|
|
343
|
+
}
|
|
341
344
|
|
|
342
|
-
|
|
343
|
-
|
|
345
|
+
interruption() {
|
|
346
|
+
if (this.commands) {
|
|
347
|
+
this.commands.dispose();
|
|
348
|
+
}
|
|
349
|
+
if (this.runPromise) {
|
|
350
|
+
this.runPromise.reject(ERRORS.TypedError('Device_Interrupted'));
|
|
344
351
|
}
|
|
345
352
|
}
|
|
346
353
|
|
|
@@ -56,7 +56,11 @@ export class DeviceCommands {
|
|
|
56
56
|
|
|
57
57
|
dispose() {
|
|
58
58
|
this.disposed = true;
|
|
59
|
+
if (this._cancelableRequest) {
|
|
60
|
+
this._cancelableRequest();
|
|
61
|
+
}
|
|
59
62
|
this._cancelableRequest = undefined;
|
|
63
|
+
this.transport.cancel?.();
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
// Sends an async message to the opened device.
|
package/src/device/DeviceList.ts
CHANGED
|
@@ -2,6 +2,11 @@ import EventEmitter from 'events';
|
|
|
2
2
|
import DeviceConnector from './DeviceConnector';
|
|
3
3
|
import { Device } from './Device';
|
|
4
4
|
import { getDeviceUUID } from '../utils/deviceFeaturesUtils';
|
|
5
|
+
import { initLog } from '../utils';
|
|
6
|
+
|
|
7
|
+
const cacheDeviceMap = new Map<string, Device>();
|
|
8
|
+
|
|
9
|
+
const Log = initLog('DeviceList');
|
|
5
10
|
|
|
6
11
|
export class DeviceList extends EventEmitter {
|
|
7
12
|
devices: Record<string, Device> = {};
|
|
@@ -20,7 +25,7 @@ export class DeviceList extends EventEmitter {
|
|
|
20
25
|
const deviceList = [];
|
|
21
26
|
console.log('get device list');
|
|
22
27
|
for await (const descriptor of descriptorList) {
|
|
23
|
-
|
|
28
|
+
let device = Device.fromDescriptor(descriptor);
|
|
24
29
|
device.deviceConnector = this.connector;
|
|
25
30
|
await device.connect();
|
|
26
31
|
await device.initialize();
|
|
@@ -30,7 +35,14 @@ export class DeviceList extends EventEmitter {
|
|
|
30
35
|
deviceList.push(device);
|
|
31
36
|
if (device.features) {
|
|
32
37
|
const uuid = getDeviceUUID(device.features);
|
|
38
|
+
if (cacheDeviceMap.has(uuid)) {
|
|
39
|
+
const cache = cacheDeviceMap.get(uuid);
|
|
40
|
+
cache?.updateFromCache(device);
|
|
41
|
+
device = cache as Device;
|
|
42
|
+
Log.debug('use cache device: ', uuid);
|
|
43
|
+
}
|
|
33
44
|
this.devices[uuid] = device;
|
|
45
|
+
cacheDeviceMap.set(uuid, device);
|
|
34
46
|
}
|
|
35
47
|
}
|
|
36
48
|
|
package/src/events/call.ts
CHANGED
|
@@ -46,6 +46,12 @@ export interface IFrameCallMessage {
|
|
|
46
46
|
payload: CallMethodPayload;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
export interface IFrameCancelMessage {
|
|
50
|
+
event: typeof IFRAME.CANCEL;
|
|
51
|
+
type: typeof IFRAME.CANCEL;
|
|
52
|
+
payload: { connectId?: string };
|
|
53
|
+
}
|
|
54
|
+
|
|
49
55
|
export const RESPONSE_EVENT = 'RESPONSE_EVENT';
|
|
50
56
|
|
|
51
57
|
export interface MethodResponseMessage {
|
package/src/events/core.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Unsuccessful } from '../types/params';
|
|
2
|
-
import { IFrameCallMessage } from './call';
|
|
2
|
+
import { IFrameCallMessage, IFrameCancelMessage } from './call';
|
|
3
3
|
import { DeviceEventMessage } from './device';
|
|
4
4
|
import { IFrameEventMessage } from './iframe';
|
|
5
5
|
import { UiEventMessage } from './ui-request';
|
|
@@ -13,6 +13,7 @@ export type CoreMessage = {
|
|
|
13
13
|
} & (
|
|
14
14
|
| IFrameEventMessage
|
|
15
15
|
| IFrameCallMessage
|
|
16
|
+
| IFrameCancelMessage
|
|
16
17
|
| UiResponseMessage
|
|
17
18
|
| UiEventMessage
|
|
18
19
|
| DeviceEventMessage
|
package/src/events/iframe.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import type { Response } from '../params';
|
|
2
|
-
import type {
|
|
2
|
+
import type { IDeviceBLEFirmwareStatus } from '../device';
|
|
3
|
+
import { IBLEFirmwareReleaseInfo } from '../settings';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
type BleFirmwareRelease = {
|
|
6
|
+
status: IDeviceBLEFirmwareStatus;
|
|
7
|
+
changelog: {
|
|
8
|
+
'zh-CN': string;
|
|
9
|
+
'en-US': string;
|
|
10
|
+
}[];
|
|
11
|
+
release: IBLEFirmwareReleaseInfo;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export declare function checkBLEFirmwareRelease(connectId?: string): Response<BleFirmwareRelease>;
|
|
@@ -1,4 +1,14 @@
|
|
|
1
1
|
import type { Response } from '../params';
|
|
2
2
|
import type { IDeviceFirmwareStatus } from '../device';
|
|
3
|
+
import { IFirmwareReleaseInfo } from '../settings';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
type FirmwareRelease = {
|
|
6
|
+
status: IDeviceFirmwareStatus;
|
|
7
|
+
changelog: {
|
|
8
|
+
'en-US': string;
|
|
9
|
+
'zh-CN': string;
|
|
10
|
+
}[];
|
|
11
|
+
release: IFirmwareReleaseInfo;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export declare function checkFirmwareRelease(connectId?: string): Response<FirmwareRelease>;
|
package/src/types/api/index.ts
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import semver from 'semver';
|
|
2
|
+
import { IBLEFirmwareReleaseInfo, IDeviceFirmwareStatus, IFirmwareReleaseInfo } from '../types';
|
|
3
|
+
|
|
4
|
+
export const getReleaseStatus = (
|
|
5
|
+
releases: (IFirmwareReleaseInfo | IBLEFirmwareReleaseInfo)[],
|
|
6
|
+
currentVersion: string
|
|
7
|
+
): IDeviceFirmwareStatus => {
|
|
8
|
+
const newVersions = releases.filter(r => semver.gt(r.version.join('.'), currentVersion));
|
|
9
|
+
if (newVersions.length === 0) {
|
|
10
|
+
return 'valid';
|
|
11
|
+
}
|
|
12
|
+
if (newVersions.some(r => r.required)) {
|
|
13
|
+
return 'required';
|
|
14
|
+
}
|
|
15
|
+
return 'outdated';
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const getReleaseChangelog = (
|
|
19
|
+
releases: (IFirmwareReleaseInfo | IBLEFirmwareReleaseInfo)[],
|
|
20
|
+
currentVersion: string
|
|
21
|
+
): IFirmwareReleaseInfo['changelog'][] => {
|
|
22
|
+
const newVersions = releases.filter(r => semver.gt(r.version.join('.'), currentVersion));
|
|
23
|
+
return newVersions.map(r => r.changelog);
|
|
24
|
+
};
|