From be0faff9fdf4aea6a2659325520d68b2f348c656 Mon Sep 17 00:00:00 2001 From: streakingman Date: Fri, 5 May 2023 00:33:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9B=BE=E7=89=87=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=A7=E5=B0=8F=E6=A0=A1=E9=AA=8C=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ConfigDialog.tsx | 48 ++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/src/components/ConfigDialog.tsx b/src/components/ConfigDialog.tsx index 2058d5e..5db625d 100644 --- a/src/components/ConfigDialog.tsx +++ b/src/components/ConfigDialog.tsx @@ -146,10 +146,14 @@ const ConfigDialog: FC<{ new Array(10).fill('') ); // 文件体积校验开关 + const initEnableFileSizeValidate = localStorage.getItem( + CUSTOM_THEME_FILE_VALIDATE_STORAGE_KEY + ); const [enableFileSizeValidate, setEnableFileSizeValidate] = useState( - localStorage.getItem(CUSTOM_THEME_FILE_VALIDATE_STORAGE_KEY) !== - 'false' + initEnableFileSizeValidate === null + ? true + : initEnableFileSizeValidate === 'true' ); useEffect(() => { localStorage.setItem( @@ -184,16 +188,16 @@ const ConfigDialog: FC<{ case 'background': setBackgroundError(''); try { - const compressFile = await canvasToFile({ - canvas: await createCanvasByImgSrc({ - imgSrc: await getFileBase64String(file), - }), - maxFileSize: 20 * 1024, - }); - const compressFileBase64 = await getFileBase64String( - compressFile - ); - updateCustomTheme('background', compressFileBase64); + const _file = enableFileSizeValidate + ? await canvasToFile({ + canvas: await createCanvasByImgSrc({ + imgSrc: await getFileBase64String(file), + }), + maxFileSize: 20 * 1024, + }) + : file; + const fileBase64 = await getFileBase64String(_file); + updateCustomTheme('background', fileBase64); } catch (e: any) { setBackgroundError(e); } @@ -215,20 +219,20 @@ const ConfigDialog: FC<{ if (idx == null) return; setIconErrors(makeIconErrors(idx, '')); try { - const compressFile = await canvasToFile({ - canvas: await createCanvasByImgSrc({ - imgSrc: await getFileBase64String(file), - }), - maxFileSize: 4 * 1024, - }); - const compressFileBase64 = await getFileBase64String( - compressFile - ); + const _file = enableFileSizeValidate + ? await canvasToFile({ + canvas: await createCanvasByImgSrc({ + imgSrc: await getFileBase64String(file), + }), + maxFileSize: 4 * 1024, + }) + : file; + const fileBase64 = await getFileBase64String(_file); updateCustomTheme( 'icons', customTheme.icons.map((icon, _idx) => _idx === idx - ? { ...icon, content: compressFileBase64 } + ? { ...icon, content: fileBase64 } : icon ) );