From bcfc790dd3c36beeaf789a33c8b3fdd992596541 Mon Sep 17 00:00:00 2001 From: yj <1336058017@qq.com> Date: Wed, 5 Mar 2025 18:15:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E9=94=99=E8=AF=AF=E6=89=8B?= =?UTF-8?q?=E5=8A=A8=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/UpdateModal/index.tsx | 39 ++++++++++++++++++++++++---- src/utils/package/public.ts | 4 +-- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/components/UpdateModal/index.tsx b/src/components/UpdateModal/index.tsx index 69b9c86..b60a177 100644 --- a/src/components/UpdateModal/index.tsx +++ b/src/components/UpdateModal/index.tsx @@ -1,10 +1,12 @@ import styles from '@/components/UpdateModal/index.module.scss' import ImageUrl from '@/utils/package/imageUrl'; -import { getUpdateUrl } from '@/utils/package/public'; +import { getUpdateUrl, isVersion } from '@/utils/package/public'; +import { ExclamationCircleFilled } from '@ant-design/icons'; import { Button, Flex, Modal, Progress } from 'antd'; import { forwardRef, useImperativeHandle, useState, memo, useEffect } from "react"; +const { confirm } = Modal; -const UpdateModal = forwardRef((props: any, ref: any) => { +const UpdateModal = forwardRef((_props: any, ref: any) => { useImperativeHandle(ref, () => ({ changeModal: (data: any) => { try { @@ -37,7 +39,33 @@ const UpdateModal = forwardRef((props: any, ref: any) => { } } } catch (error) { - + if (typeof data === 'string' && data.includes('Error')) { + setIsError(res => { + if (res) { + setIsError(false) + confirm({ + keyboard: false, + title: '提示', + icon: , + content: `更新失败,请尝试手动更新!`, + centered: true, + okText: '立即更新', + wrapClassName: 'hideCancelText', + cancelText: '', + async onOk() { + isVersion((bool: boolean, req: any) => { + if (bool && req) { + window.electron.getEnv().then(res => { + location.href = `${getUpdateUrl(res)}/${req.path}` + }) + } + }) + }, + }) + } + return res + }) + } } } })) @@ -45,6 +73,7 @@ const UpdateModal = forwardRef((props: any, ref: any) => { const [progress, setProgress] = useState(0); // 下载进度值 const [updateContent, setUpdateContent] = useState('') // 版本更新内容 const [env, setEnv] = useState('') + const [_isError, setIsError] = useState(true) useEffect(() => { window.electron.getEnv().then(res => { setEnv(res) @@ -59,9 +88,9 @@ const UpdateModal = forwardRef((props: any, ref: any) => { } throw new Error('Network response was not ok.'); }) - .then(textContent => { + .then(_textContent => { }) - .catch(error => { + .catch(_error => { }); }) } diff --git a/src/utils/package/public.ts b/src/utils/package/public.ts index ec71c0b..beac8d1 100644 --- a/src/utils/package/public.ts +++ b/src/utils/package/public.ts @@ -107,9 +107,9 @@ export const isVersion = (callBack: Function) => { const data = yaml.load(res.data); // 解析 YAML 内容 window.electron.getVersion().then(req => { if (compareVersions(data.version, req) == 1) { - callBack(true) + callBack(true, data) } else { - callBack(false) + callBack(false, data) } }) } else {