From 455a05c360e1dc4df0a40e2c0369277cf17c70e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Sun, 2 Jul 2023 15:39:14 +0100 Subject: [PATCH] fix: warn when 0 keys imported (#38) --- src/features/settings/panels/PanelKWMv2Key.tsx | 10 ++++++++-- src/features/settings/panels/PanelQMCv2Key.tsx | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/features/settings/panels/PanelKWMv2Key.tsx b/src/features/settings/panels/PanelKWMv2Key.tsx index 42289a4..ba6d4e7 100644 --- a/src/features/settings/panels/PanelKWMv2Key.tsx +++ b/src/features/settings/panels/PanelKWMv2Key.tsx @@ -49,8 +49,14 @@ export function PanelKWMv2Key() { const fileBuffer = await file.arrayBuffer(); keys = MMKVParser.parseKuwoEKey(new DataView(fileBuffer)); } - - if (keys) { + if (keys?.length === 0) { + toast({ + title: '未导入密钥', + description: '选择的密钥数据库文件未发现任何可用的密钥。', + isClosable: true, + status: 'warning', + }); + } else if (keys) { dispatch(kwm2ImportKeys(keys)); setShowImportModal(false); toast({ diff --git a/src/features/settings/panels/PanelQMCv2Key.tsx b/src/features/settings/panels/PanelQMCv2Key.tsx index 32bcffd..c4be627 100644 --- a/src/features/settings/panels/PanelQMCv2Key.tsx +++ b/src/features/settings/panels/PanelQMCv2Key.tsx @@ -71,14 +71,20 @@ export function PanelQMCv2Key() { qmc2Keys = Array.from(map.entries(), ([name, ekey]) => ({ name: getFileName(name), ekey })); } - if (qmc2Keys) { + if (qmc2Keys?.length === 0) { + toast({ + title: '未导入密钥', + description: '选择的密钥数据库文件未发现任何可用的密钥。', + isClosable: true, + status: 'warning', + }); + } else if (qmc2Keys) { dispatch(qmc2ImportKeys(qmc2Keys)); setShowImportModal(false); toast({ title: `导入成功 (${qmc2Keys.length})`, description: '记得保存更改来应用。', isClosable: true, - duration: 5000, status: 'success', }); } else {