Skip to content

Commit

Permalink
fix(connect): send cancel message on the first run to preven unexpect…
Browse files Browse the repository at this point in the history
…ed message
  • Loading branch information
mroz22 committed Feb 3, 2025
1 parent 5e7ed63 commit 5782dae
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/connect/src/device/Device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,9 @@ export class Device extends TypedEmitter<DeviceEvents> {
DataManager.getSettings('env') === 'react-native'
? GET_FEATURES_TIMEOUT_REACT_NATIVE
: GET_FEATURES_TIMEOUT;
_log.debug('sending cancel');
await cancelPrompt(this, true).catch(() => {});
_log.debug('sending cancel done');

let getFeaturesTimeoutId: ReturnType<typeof setTimeout> | undefined;

Expand Down
15 changes: 11 additions & 4 deletions packages/connect/src/device/__tests__/DeviceList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,22 @@ describe('DeviceList', () => {
let readCount = 0;
const transport = createTestTransport({
read: () => {
let features = '3f232300110000000c1002180020006000aa010154'; // 2.0.0
if (readCount > 0) {
features = `3f232300110000000c10021800200${1}6000aa010154`; // 2.0.1
let res = '';
if (readCount === 0) {
// cancel response
res = '3f2323000300000000000000000000000000000000';
} else if (readCount === 1) {
// features
res = '3f232300110000000c1002180020006000aa010154'; // 2.0.0;
} else {
// features
res = `3f232300110000000c10021800200${1}6000aa010154`; // 2.0.1
}
readCount++;

return Promise.resolve({
success: true,
payload: Buffer.from(features, 'hex'),
payload: Buffer.from(res, 'hex'),
});
},
});
Expand Down

0 comments on commit 5782dae

Please sign in to comment.