Skip to content

Commit

Permalink
chore: fix sdk url (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteZhang1024 authored Feb 24, 2024
1 parent 57e90bd commit 6353b0c
Show file tree
Hide file tree
Showing 8 changed files with 287 additions and 153 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-example-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- name: Install dependencies
run: |
yarn
yarn setup
- name: Cache Gradle packages
uses: actions/cache@v2
Expand Down
4 changes: 3 additions & 1 deletion packages/connect-examples/expo-example/locale/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"action__full_coverage_res": "Upload Full Resource",
"action__pick_file": "Pick File",
"action__export_report": "Export Report",
"action__switch_device": "Input Pin on Device",

"action__start_test": "Start Test",
"action__stop_test": "Stop Test",
Expand All @@ -39,6 +40,7 @@
"title__common_parameters": "Common Parameters",
"title__hardware_api_test": "Hardware Api Test",
"title__updating": "Updating",
"title__input_pin": "Input Pin",

"title__device_info": "Device Information",
"title__device_firmware_update": "Device Firmware Update",
Expand Down Expand Up @@ -96,7 +98,7 @@
"message__reboot_to_bootloader": "Reboot to bootloader...",
"message__wait_begin_update": "Wait begin update...",
"message__confirm_on_device": "Confirm on device...",
"message__firmware_erase_success": "Firmware erase success",
"message__firmware_erase_success": "Firmware installing...",
"message__firmware_start_transfer": "Firmware start transfer...",
"message__firmware_installing": "Firmware installing...",
"message__bootloader_update": "Bootloader update...",
Expand Down
4 changes: 3 additions & 1 deletion packages/connect-examples/expo-example/locale/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"action__full_coverage_res": "上传完整资源",
"action__pick_file": "选择文件",
"action__export_report": "导出报告",
"action__switch_device": "切换到设备输入",

"action__start_test": "开始测试",
"action__stop_test": "停止测试",
Expand All @@ -39,6 +40,7 @@
"title__common_parameters": "常用参数",
"title__hardware_api_test": "硬件 API 测试",
"title__updating": "正在更新",
"title__input_pin": "输入 PIN",

"title__device_info": "设备信息",
"title__device_firmware_update": "设备固件更新",
Expand Down Expand Up @@ -96,7 +98,7 @@
"message__reboot_to_bootloader": "重启到 Bootloader...",
"message__wait_begin_update": "等待开始更新中...",
"message__confirm_on_device": "在设备上确认...",
"message__firmware_erase_success": "固件擦除成功",
"message__firmware_erase_success": "固件安装中...",
"message__firmware_start_transfer": "固件开始传输中...",
"message__firmware_installing": "固件安装中...",
"message__bootloader_update": "Bootloader 更新中...",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { useCallback, useContext, useEffect, useRef, useState } from 'react';
import { useCallback, useContext, useState } from 'react';
import {
CoreMessage,
DEVICE,
FIRMWARE_EVENT,
LOG_EVENT,
UI_EVENT,
UI_REQUEST,
UI_RESPONSE,
supportInputPinOnSoftware,
} from '@onekeyfe/hd-core';

import { useIsFocused } from '@react-navigation/native';
import { useFocusEffect } from '@react-navigation/native';
import { View } from 'tamagui';
import HardwareSDKContext from '../provider/HardwareSDKContext';
import { ReceivePin } from './ReceivePin';
Expand All @@ -18,79 +20,6 @@ let registerListener = false;
export default function HandleSDKEvents() {
const { sdk: SDK, lowLevelSDK: HardwareLowLevelSDK, type } = useContext(HardwareSDKContext);
const [showPinInput, setShowPinInput] = useState(false);
const [pinValue, setPinValue] = useState('');

const focus = useIsFocused();
const focusRef = useRef<boolean>(false);

useEffect(() => {
focusRef.current = focus;
}, [focus]);

useEffect(() => {
// 监听 SDK 事件
if (registerListener) {
return;
}
if (!SDK) return;

HardwareLowLevelSDK?.addHardwareGlobalEventListener(params => {
SDK.emit?.(params.event, { ...params });
});

SDK.on(UI_EVENT, (message: CoreMessage) => {
if (!focusRef.current) return;
console.log('TopLEVEL EVENT ===>>>>: ', message);
if (message.type === UI_REQUEST.REQUEST_PIN) {
// setShowPinInput(true);
SDK.uiResponse({
type: UI_RESPONSE.RECEIVE_PIN,
payload: '@@ONEKEY_INPUT_PIN_IN_DEVICE',
});
}
if (message.type === UI_REQUEST.REQUEST_PASSPHRASE) {
setTimeout(() => {
SDK.uiResponse({
type: UI_RESPONSE.RECEIVE_PASSPHRASE,
payload: {
value: '',
passphraseOnDevice: true,
save: false,
},
});
}, 2000);
}
});

// SDK.on(LOG_EVENT, (message: CoreMessage) => {
// if (Array.isArray(message.payload)) {
// const msg = message.payload.join(' ');
// console.log('receive log event: ', msg);
// }
// });

SDK.on(FIRMWARE_EVENT, (message: CoreMessage) => {
console.log('example get firmware event: ', message);
});

SDK.on(DEVICE.FEATURES, (message: CoreMessage) => {
console.log('example get features event: ', message);
});

SDK.on(DEVICE.CONNECT, (message: CoreMessage) => {
console.log('example get connect event: ', message);
});

SDK.on(DEVICE.DISCONNECT, (message: CoreMessage) => {
console.log('example get disconnect event: ', message);
});
registerListener = true;

return () => {
registerListener = false;
SDK.removeAllListeners();
};
}, [SDK, HardwareLowLevelSDK, focus]);

// 输入 pin 码的确认回调
const onConfirmPin = useCallback(
Expand All @@ -106,16 +35,94 @@ export default function HandleSDKEvents() {
SDK?.cancel('pin-cancelled');
}, [SDK]);

// input pin on device
const onInputPinOnDeviceCallback = useCallback(() => {
SDK?.uiResponse({
type: UI_RESPONSE.RECEIVE_PIN,
payload: '@@ONEKEY_INPUT_PIN_IN_DEVICE',
});
}, [SDK]);

useFocusEffect(
useCallback(() => {
// 监听 SDK 事件
if (registerListener) {
return;
}
if (!SDK) return;

HardwareLowLevelSDK?.addHardwareGlobalEventListener(params => {
SDK.emit?.(params.event, { ...params });
});

const uiEventCallback = (message: CoreMessage) => {
console.log('TopLEVEL EVENT (Api Payload)===>>>>: ', message);
if (message.type === UI_REQUEST.REQUEST_PIN) {
if (supportInputPinOnSoftware(message.payload.device.features).support) {
setShowPinInput(true);
} else {
onInputPinOnDeviceCallback();
}
}
if (message.type === UI_REQUEST.REQUEST_PASSPHRASE) {
setTimeout(() => {
SDK.uiResponse({
type: UI_RESPONSE.RECEIVE_PASSPHRASE,
payload: {
value: '',
passphraseOnDevice: true,
save: false,
},
});
}, 2000);
}
};
SDK.on(UI_EVENT, uiEventCallback);

// SDK.on(LOG_EVENT, (message: CoreMessage) => {
// if (Array.isArray(message.payload)) {
// const msg = message.payload.join(' ');
// console.log('receive log event: ', msg);
// }
// });

SDK.on(FIRMWARE_EVENT, (message: CoreMessage) => {
console.log('example get firmware event: ', message);
});

SDK.on(DEVICE.FEATURES, (message: CoreMessage) => {
console.log('example get features event: ', message);
});

SDK.on(DEVICE.CONNECT, (message: CoreMessage) => {
console.log('example get connect event: ', message);
});

SDK.on(DEVICE.DISCONNECT, (message: CoreMessage) => {
console.log('example get disconnect event: ', message);
});

registerListener = true;
console.log('Api payload: register sdk listeners');

return () => {
console.log('Api payload: remove all sdk listeners');

SDK.off(UI_EVENT, uiEventCallback);
registerListener = false;
};
}, [HardwareLowLevelSDK, SDK, onInputPinOnDeviceCallback])
);

return (
<View>
{showPinInput && (
<ReceivePin
value={pinValue}
onChange={val => setPinValue(val)}
onConfirm={val => onConfirmPin(val)}
onCancel={onPinCancelCallback}
/>
)}
<ReceivePin
open={showPinInput}
onOpenChange={setShowPinInput}
onConfirm={val => onConfirmPin(val)}
onSwitchDevice={onInputPinOnDeviceCallback}
onCancel={onPinCancelCallback}
/>
</View>
);
}
Loading

0 comments on commit 6353b0c

Please sign in to comment.