From 2c146d811ab5c0b589ffe5641dd58c7c2e890b8b Mon Sep 17 00:00:00 2001 From: caorushizi <84996057@qq.com> Date: Fri, 3 Jan 2025 03:01:53 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=E2=9C=A8=20=20some=20performance?= =?UTF-8?q?=20issues=20were=20optimized?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/renderer/src/App.tsx | 41 +- .../renderer/src/components/DownloadForm.tsx | 405 +++++++++--------- .../renderer/src/components/EpisodeNumber.tsx | 182 -------- .../renderer/src/components/IconButton.tsx | 12 +- packages/renderer/src/context/ThemeContext.ts | 3 - packages/renderer/src/layout/AppSideBar.tsx | 8 +- .../renderer/src/pages/Converter/index.tsx | 9 +- .../HomePage/components/DownloadList.tsx | 9 +- .../pages/HomePage/components/ListHeader.tsx | 7 +- .../renderer/src/pages/HomePage/index.tsx | 9 +- packages/renderer/src/pages/Player/index.tsx | 7 +- .../renderer/src/pages/SettingPage/index.tsx | 28 +- .../SourceExtract/components/BrowserView.tsx | 99 ++--- .../components/BrowserViewPanel.tsx | 56 +++ .../SourceExtract/components/FavoriteList.tsx | 7 +- .../SourceExtract/components/ToolBar.tsx | 6 +- packages/renderer/src/store/config.ts | 29 +- packages/renderer/src/store/session.ts | 26 +- 18 files changed, 365 insertions(+), 578 deletions(-) delete mode 100644 packages/renderer/src/components/EpisodeNumber.tsx delete mode 100644 packages/renderer/src/context/ThemeContext.ts create mode 100644 packages/renderer/src/pages/SourceExtract/components/BrowserViewPanel.tsx diff --git a/packages/renderer/src/App.tsx b/packages/renderer/src/App.tsx index b96b4b4d..b46eed7c 100644 --- a/packages/renderer/src/App.tsx +++ b/packages/renderer/src/App.tsx @@ -8,13 +8,17 @@ import Loading from "./components/Loading"; import { DownloadFilter } from "./types"; import { isWeb, tdApp } from "./utils"; import { useAsyncEffect } from "ahooks"; -import { ThemeContext } from "./context/ThemeContext"; -import { SessionStore, useSessionStore } from "./store/session"; +import { + themeSelector, + updateSelector, + useSessionStore, +} from "./store/session"; import { useShallow } from "zustand/react/shallow"; import { DOWNLOAD_FAIL, DOWNLOAD_SUCCESS, PAGE_LOAD } from "./const"; import { useAppStore, setAppStoreSelector } from "./store/app"; import { PageMode, setBrowserSelector, useBrowserStore } from "./store/browser"; import { downloadStoreSelector, useDownloadStore } from "./store/download"; +import { App as AntdApp } from "antd"; const AppLayout = lazy(() => import("./layout/App")); const HomePage = lazy(() => import("./pages/HomePage")); @@ -27,26 +31,21 @@ function getAlgorithm(appTheme: "dark" | "light") { return appTheme === "dark" ? theme.darkAlgorithm : theme.defaultAlgorithm; } -const sessionSelector = (s: SessionStore) => ({ - setUpdateAvailable: s.setUpdateAvailable, - setUploadChecking: s.setUploadChecking, -}); - const App: FC = () => { - const [appTheme, setAppTheme] = React.useState<"dark" | "light">("light"); const { addIpcListener, removeIpcListener, getMachineId } = useElectron(); const { setUpdateAvailable, setUploadChecking } = useSessionStore( - useShallow(sessionSelector), + useShallow(updateSelector), ); const { setAppStore } = useAppStore(useShallow(setAppStoreSelector)); const { setBrowserStore } = useBrowserStore(useShallow(setBrowserSelector)); const { increase } = useDownloadStore(useShallow(downloadStoreSelector)); + const { theme, setTheme } = useSessionStore(useShallow(themeSelector)); const themeChange = (event: MediaQueryListEvent) => { if (event.matches) { - setAppTheme("dark"); + setTheme("dark"); } else { - setAppTheme("light"); + setTheme("light"); } }; @@ -114,9 +113,9 @@ const App: FC = () => { isDarkTheme.addEventListener("change", themeChange); if (isDarkTheme.matches) { - setAppTheme("dark"); + setTheme("dark"); } else { - setAppTheme("light"); + setTheme("light"); } return () => { @@ -125,12 +124,12 @@ const App: FC = () => { }, []); return ( - - + + { /> - - + + ); }; diff --git a/packages/renderer/src/components/DownloadForm.tsx b/packages/renderer/src/components/DownloadForm.tsx index 2267d453..bff5bf7e 100644 --- a/packages/renderer/src/components/DownloadForm.tsx +++ b/packages/renderer/src/components/DownloadForm.tsx @@ -1,4 +1,5 @@ import { + App, AutoComplete, Button, Form, @@ -6,12 +7,11 @@ import { Modal, Select, Switch, - message, } from "antd"; import React, { forwardRef, useImperativeHandle, useState } from "react"; import { useTranslation } from "react-i18next"; import TextArea from "antd/es/input/TextArea"; -import { ConfigStore, useConfigStore } from "@/store/config"; +import { downloadFormSelector, useConfigStore } from "@/store/config"; import { useShallow } from "zustand/react/shallow"; import { useAsyncEffect, useMemoizedFn } from "ahooks"; import { DownloadType } from "@/types"; @@ -51,11 +51,6 @@ export interface DownloadItemForm extends DownloadItem { batchList?: string; } -const configSelector = (s: ConfigStore) => ({ - setLastDownloadTypes: s.setLastDownloadTypes, - setLastIsBatch: s.setLastIsBatch, -}); - interface Options { label: string; value: string; @@ -77,9 +72,9 @@ export default forwardRef( const [modalOpen, setModalOpen] = useState(false); const [form] = Form.useForm(); const { t } = useTranslation(); - const [messageApi, contextHolder] = message.useMessage(); + const { message } = App.useApp(); const { setLastDownloadTypes, setLastIsBatch } = useConfigStore( - useShallow(configSelector), + useShallow(downloadFormSelector), ); const [folders, setFolders] = useState([]); const [videoFolders, setVideoFolders] = useState([]); @@ -146,7 +141,7 @@ export default forwardRef( tdApp.onEvent(ADD_TO_LIST, { id }); } catch (e: any) { console.error(e); - messageApi.error(e?.message || t("pleaseEnterCorrectFomeInfo")); + message.error(e?.message || t("pleaseEnterCorrectFomeInfo")); } }); @@ -165,7 +160,7 @@ export default forwardRef( tdApp.onEvent(DOWNLOAD_NOW, { id }); } catch (e: any) { console.error(e); - messageApi.error(e?.message || t("pleaseEnterCorrectFomeInfo")); + message.error(e?.message || t("pleaseEnterCorrectFomeInfo")); } }); @@ -178,213 +173,203 @@ export default forwardRef( }); return ( - <> - {contextHolder} - setModalOpen(false)} - onCancel={() => setModalOpen(false)} - afterOpenChange={afterOpenChange} - destroyOnClose={destroyOnClose} - footer={[ - , - , - , - ]} + setModalOpen(false)} + onCancel={() => setModalOpen(false)} + afterOpenChange={afterOpenChange} + destroyOnClose={destroyOnClose} + footer={[ + , + , + , + ]} + > +
- + + - - - {(form) => { - if (isEdit || !form.getFieldValue("batch")) { - return null; - } - return ( - { - const lines = value.split("\n"); - for (const line of lines) { - const params = line.trim().split(" "); - if (params.length > 3) { - return Promise.reject( - new Error(t("pleaseEnterCorrectBatchList")), - ); - } - const [url] = params; - if (!/^(https?):\/\/.+/.test(url)) { - return Promise.reject( - new Error(t("pleaseEnterCorrectBatchList")), - ); - } + return ( + + + + ); + }} + + + {(form) => { + if (isEdit || !form.getFieldValue("batch")) { + return null; + } + return ( + { + const lines = value.split("\n"); + for (const line of lines) { + const params = line.trim().split(" "); + if (params.length > 3) { + return Promise.reject( + new Error(t("pleaseEnterCorrectBatchList")), + ); } - return Promise.resolve(); - }, - }, - ]} - > -