From 2b4a3cdbcaa48724c4606da1c14827e858ab41bf Mon Sep 17 00:00:00 2001 From: yj <1336058017@qq.com> Date: Wed, 26 Feb 2025 09:59:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=8B=E5=8A=A8=E6=9B=B4=E6=96=B0=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.js | 12 +++++++++++- src/components/UpdateModal/index.tsx | 9 ++++++--- src/page/Home/index.module.scss | 21 +++++++++++++++++++-- src/page/Home/index.tsx | 23 +++++++++++++++++++---- 4 files changed, 55 insertions(+), 10 deletions(-) diff --git a/main.js b/main.js index c3ff590..0873591 100644 --- a/main.js +++ b/main.js @@ -517,6 +517,11 @@ app.on('ready', () => { downloadUpdate() } else if (data === '2') { // 下载完成 点击安装 quitAndInstall() + } else if (data === '3') { // 打开弹窗 + let message = JSON.stringify({ + type: '3', + }) + sendUpdateMessage(message) } }); // 选择文件夹 @@ -766,9 +771,14 @@ function updateHandle() { autoUpdater.on('update-available', function (info) { let messageStr = JSON.stringify({ type: '0' }) sendUpdateMessage(messageStr) + mainWindow.webContents.send('changeLocalStorage', { + isUpdate: true, + }); }) autoUpdater.on('update-not-available', function (info) { - + mainWindow.webContents.send('changeLocalStorage', { + isUpdate: false, + }); }) // 更新下载进度事件 autoUpdater.on('download-progress', function (progressObj) { diff --git a/src/components/UpdateModal/index.tsx b/src/components/UpdateModal/index.tsx index 5d77680..5f25c2c 100644 --- a/src/components/UpdateModal/index.tsx +++ b/src/components/UpdateModal/index.tsx @@ -4,7 +4,7 @@ import { getUpdateUrl } from '@/utils/package/public'; import { Button, Flex, Modal, Progress } from 'antd'; import { forwardRef, useImperativeHandle, useState, memo } from "react"; -const UpdateModal = forwardRef((props: any, ref: any) => { +const UpdateModal = forwardRef((_props: any, ref: any) => { useImperativeHandle(ref, () => ({ changeModal: (data: any) => { try { @@ -30,6 +30,9 @@ const UpdateModal = forwardRef((props: any, ref: any) => { setIsUpdateModal(true) } setProgress(100) + } else if (dataJson.type === '3') { + getContent() + setIsUpdateModal(true) } } catch (error) { @@ -51,9 +54,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/page/Home/index.module.scss b/src/page/Home/index.module.scss index db9972a..fa82e24 100644 --- a/src/page/Home/index.module.scss +++ b/src/page/Home/index.module.scss @@ -120,8 +120,25 @@ @else if $i ==4 { flex-shrink: 0; - color: #ccc; - font-size: 16px; + + >div:nth-child(1) { + color: #ccc; + font-size: 16px; + display: flex; + justify-content: space-between; + align-items: center; + + >span:nth-child(2) { + background-color: red; + padding: 2px 8px; + border-radius: 10px; + } + } + + >div:nth-child(2) { + width: 100%; + margin-top: 10px; + } } @else if $i ==5 { diff --git a/src/page/Home/index.tsx b/src/page/Home/index.tsx index b0e1c3b..eef3ff8 100644 --- a/src/page/Home/index.tsx +++ b/src/page/Home/index.tsx @@ -1,7 +1,7 @@ import styles from '@/page/Home/index.module.scss' import { useEffect, useState, useRef } from "react"; import { Outlet, useNavigate } from 'react-router-dom'; -import { Popconfirm, Popover } from 'antd'; +import { Button, Popconfirm, Popover } from 'antd'; import dayjs from 'dayjs'; import 'dayjs/locale/zh-cn' import { storage } from '@/utils'; @@ -45,6 +45,7 @@ const Home: React.FC = () => { ]); const [userInfo, setUserInfo] = useState({}) const [version, setVersion] = useState('') + const [update, setUpdate] = useState(false) const [dateInfo, setDateInfo] = useState<{ work: string; time: string; @@ -67,11 +68,18 @@ const Home: React.FC = () => { }) }; const timer = setInterval(updateTime, 1000); + window.addEventListener('customStorageChange', handleCustomStorageChange); return () => { + window.removeEventListener('customStorageChange', handleCustomStorageChange); clearInterval(timer); }; }, []); + const handleCustomStorageChange = (e: any): void => { + if (e.key === 'isUpdate') { + setUpdate(e.value) + } + }; const changtNavList = (index: number, bool?: boolean): void => { const newNavList = [...navList]; if (typeof bool === 'boolean') { @@ -126,9 +134,16 @@ const Home: React.FC = () => { ) })} -
- 版本号:{version} - {/* new */} +
+
+ 版本号:{version} + {update ? new : null} +
+ {update ?
+ +
: null}