+
@@ -21,12 +25,12 @@ const store = useBrcatStore();
- {{ device.address }}
+ {{ displayAddress }}
-
+
diff --git a/src/composables/useErrno.ts b/src/composables/useErrno.ts
new file mode 100644
index 0000000..1484fcd
--- /dev/null
+++ b/src/composables/useErrno.ts
@@ -0,0 +1,14 @@
+export const ERRNO: Record
= {
+ 5010: '找不到指定 ID 的设备',
+ 5011: '设备没有公开的心率服务'
+}
+
+export const useErrno = (errno: string | null | undefined) => {
+ if (errno) {
+ const err = ERRNO[Number(errno)]
+ if (err) {
+ return err
+ }
+ }
+ return '未知错误'
+}
\ No newline at end of file
diff --git a/src/pages/index.vue b/src/pages/index.vue
index bc5c4d7..fe143d8 100644
--- a/src/pages/index.vue
+++ b/src/pages/index.vue
@@ -3,6 +3,7 @@ import { invoke } from '@tauri-apps/api/tauri';
import { useBrcatStore } from '../stores';
import { computed, onMounted, ref } from 'vue';
import { useSnackbar } from 'vue3-snackbar';
+import { useErrno } from '../composables/useErrno';
const store = useBrcatStore();
const snackbar = useSnackbar();
@@ -10,14 +11,14 @@ const is_connecting = ref(false);
const scanning_devices = computed(() => store.scanning_devices.filter(d => d.name !== 'Unknown'));
-async function connect(address: String) {
+async function connect(peripheral_id: String) {
is_connecting.value = true;
store.stopScan();
- invoke('connect', { address })
- .catch(err => {
+ invoke('connect', { peripheralId: peripheral_id })
+ .catch(errno => {
snackbar.add({
type: 'error',
- text: `连接设备失败: ${err}`
+ text: useErrno(errno),
});
store.startScan();
}).finally(() => {
@@ -51,29 +52,24 @@ onMounted(() => {