{favoriteList.map((item) => {
return (
diff --git a/packages/renderer/src/pages/SourceExtract/components/ToolBar.tsx b/packages/renderer/src/pages/SourceExtract/components/ToolBar.tsx
index 7de46450..6e6eae8e 100644
--- a/packages/renderer/src/pages/SourceExtract/components/ToolBar.tsx
+++ b/packages/renderer/src/pages/SourceExtract/components/ToolBar.tsx
@@ -2,7 +2,7 @@ import useElectron from "@/hooks/electron";
import { cn, generateUrl, getFavIcon, tdApp } from "@/utils";
import { useRequest } from "ahooks";
import { Input, Tooltip } from "antd";
-import React, { useContext, useMemo } from "react";
+import React, { useMemo } from "react";
import { useTranslation } from "react-i18next";
import {
BackIcon,
@@ -17,7 +17,6 @@ import {
PCIcon,
} from "@/assets/svg";
import { IconButton } from "@/components/IconButton";
-import { ThemeContext } from "@/context/ThemeContext";
import { EyeInvisibleOutlined } from "@ant-design/icons";
import { OPEN_URL } from "@/const";
import {
@@ -33,6 +32,7 @@ import {
setBrowserSelector,
useBrowserStore,
} from "@/store/browser";
+import { themeSelector, useSessionStore } from "@/store/session";
interface Props {
page: boolean;
@@ -50,7 +50,7 @@ export function ToolBar({ page }: Props) {
setUserAgent,
webviewUrlContextMenu,
} = useElectron();
- const theme = useContext(ThemeContext);
+ const { theme } = useSessionStore(useShallow(themeSelector));
const store = useBrowserStore(useShallow(browserStoreSelector));
const { setBrowserStore } = useBrowserStore(useShallow(setBrowserSelector));
const appStore = useAppStore(useShallow(appStoreSelector));
diff --git a/packages/renderer/src/store/config.ts b/packages/renderer/src/store/config.ts
index 512eab43..d5672d63 100644
--- a/packages/renderer/src/store/config.ts
+++ b/packages/renderer/src/store/config.ts
@@ -8,45 +8,23 @@ type State = {
// Last download type
lastIsBatch: boolean;
lastDownloadTypes: DownloadType;
-
- // Video type selected last time (only m3u8 can be cached)
- lastVideoType: string;
- lastVideoName: string;
- lastVideoNumber: number;
};
type Actions = {
setLastDownloadTypes: (type: DownloadType) => void;
- setLastVideo: (data: {
- type?: string;
- name?: string;
- number?: number;
- }) => void;
setLastIsBatch: (isBatch: boolean) => void;
};
-export type ConfigStore = State & Actions;
-
export const useConfigStore = create
()(
persist(
immer((set) => ({
lastIsBatch: false,
lastDownloadTypes: DownloadType.m3u8,
- lastVideoType: "",
- lastVideoName: "",
- lastVideoNumber: 1,
setLastDownloadTypes: (type) => {
set((state) => {
state.lastDownloadTypes = type;
});
},
- setLastVideo: ({ type, name, number }) => {
- set((state) => {
- if (type) state.lastVideoType = type;
- if (name) state.lastVideoName = name;
- if (number) state.lastVideoNumber = number;
- });
- },
setLastIsBatch: (isBatch) => {
set((state) => {
state.lastIsBatch = isBatch;
@@ -59,3 +37,10 @@ export const useConfigStore = create()(
},
),
);
+
+export const downloadFormSelector = (s: State & Actions) => ({
+ lastIsBatch: s.lastIsBatch,
+ lastDownloadTypes: s.lastDownloadTypes,
+ setLastDownloadTypes: s.setLastDownloadTypes,
+ setLastIsBatch: s.setLastIsBatch,
+});
diff --git a/packages/renderer/src/store/session.ts b/packages/renderer/src/store/session.ts
index 826e62a3..25c9b38d 100644
--- a/packages/renderer/src/store/session.ts
+++ b/packages/renderer/src/store/session.ts
@@ -4,19 +4,24 @@ import { immer } from "zustand/middleware/immer";
type State = {
updateAvailable: boolean;
updateChecking: boolean;
+
+ // theme
+ theme: "light" | "dark";
};
type Actions = {
setUpdateAvailable: (available: boolean) => void;
setUploadChecking: (loading: boolean) => void;
-};
-export type SessionStore = State & Actions;
+ // theme
+ setTheme: (theme: "light" | "dark") => void;
+};
export const useSessionStore = create()(
immer((set) => ({
updateAvailable: false,
updateChecking: true,
+ theme: "light",
setUpdateAvailable: (available) => {
set((state) => {
state.updateAvailable = available;
@@ -27,5 +32,22 @@ export const useSessionStore = create()(
state.updateChecking = loading;
});
},
+ setTheme: (theme) => {
+ set((state) => {
+ state.theme = theme;
+ });
+ },
})),
);
+
+export const themeSelector = (s: State & Actions) => ({
+ theme: s.theme,
+ setTheme: s.setTheme,
+});
+
+export const updateSelector = (s: State & Actions) => ({
+ updateAvailable: s.updateAvailable,
+ updateChecking: s.updateChecking,
+ setUpdateAvailable: s.setUpdateAvailable,
+ setUploadChecking: s.setUploadChecking,
+});
From 5a32df61c55070b383b81ef557a24cbe87b0885f Mon Sep 17 00:00:00 2001
From: caorushizi <84996057@qq.com>
Date: Fri, 3 Jan 2025 03:06:33 +0800
Subject: [PATCH 2/4] =?UTF-8?q?style:=20=F0=9F=92=84=20=20optimized=20the?=
=?UTF-8?q?=20file=20reference=20path=20problem?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
packages/renderer/src/App.tsx | 2 +-
packages/renderer/src/components/DownloadForm.tsx | 2 +-
packages/renderer/src/components/DownloadTerminal.tsx | 2 +-
packages/renderer/src/components/WebView.tsx | 2 +-
packages/renderer/src/hooks/{electron.ts => useElectron.ts} | 0
packages/renderer/src/layout/App.tsx | 2 +-
packages/renderer/src/layout/AppHeader.tsx | 2 +-
packages/renderer/src/layout/AppSideBar.tsx | 2 +-
packages/renderer/src/pages/Converter/index.tsx | 6 +++---
.../renderer/src/pages/HomePage/components/DownloadItem.tsx | 2 +-
.../renderer/src/pages/HomePage/components/DownloadList.tsx | 2 +-
.../renderer/src/pages/HomePage/components/ListHeader.tsx | 2 +-
packages/renderer/src/pages/HomePage/index.tsx | 6 +++---
packages/renderer/src/pages/SettingPage/index.tsx | 6 +++---
.../src/pages/SourceExtract/components/BrowserView.tsx | 2 +-
.../src/pages/SourceExtract/components/BrowserViewPanel.tsx | 2 +-
.../src/pages/SourceExtract/components/FavoriteList.tsx | 2 +-
.../renderer/src/pages/SourceExtract/components/ToolBar.tsx | 2 +-
packages/renderer/src/pages/SourceExtract/index.tsx | 4 ++--
packages/renderer/src/store/browser.ts | 2 +-
20 files changed, 26 insertions(+), 26 deletions(-)
rename packages/renderer/src/hooks/{electron.ts => useElectron.ts} (100%)
diff --git a/packages/renderer/src/App.tsx b/packages/renderer/src/App.tsx
index b46eed7c..f3e2c5eb 100644
--- a/packages/renderer/src/App.tsx
+++ b/packages/renderer/src/App.tsx
@@ -3,7 +3,7 @@ import React, { FC, Suspense, lazy, useEffect } from "react";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import "dayjs/locale/zh-cn";
import zhCN from "antd/locale/zh_CN";
-import useElectron from "./hooks/electron";
+import useElectron from "@/hooks/useElectron";
import Loading from "./components/Loading";
import { DownloadFilter } from "./types";
import { isWeb, tdApp } from "./utils";
diff --git a/packages/renderer/src/components/DownloadForm.tsx b/packages/renderer/src/components/DownloadForm.tsx
index bff5bf7e..df3f50fb 100644
--- a/packages/renderer/src/components/DownloadForm.tsx
+++ b/packages/renderer/src/components/DownloadForm.tsx
@@ -17,7 +17,7 @@ import { useAsyncEffect, useMemoizedFn } from "ahooks";
import { DownloadType } from "@/types";
import { tdApp } from "@/utils";
import { ADD_TO_LIST, DOWNLOAD_NOW } from "@/const";
-import useElectron from "@/hooks/electron";
+import useElectron from "@/hooks/useElectron";
export interface DownloadFormType {
batch?: boolean;
diff --git a/packages/renderer/src/components/DownloadTerminal.tsx b/packages/renderer/src/components/DownloadTerminal.tsx
index 20843705..30000f92 100644
--- a/packages/renderer/src/components/DownloadTerminal.tsx
+++ b/packages/renderer/src/components/DownloadTerminal.tsx
@@ -3,7 +3,7 @@ import "@xterm/xterm/css/xterm.css";
import { Terminal as XTerminal } from "@xterm/xterm";
import { FitAddon } from "@xterm/addon-fit";
import { cn } from "@/utils";
-import useElectron from "@/hooks/electron";
+import useElectron from "@/hooks/useElectron";
interface TerminalProps {
className?: string;
diff --git a/packages/renderer/src/components/WebView.tsx b/packages/renderer/src/components/WebView.tsx
index cd832d3b..0f04b57a 100644
--- a/packages/renderer/src/components/WebView.tsx
+++ b/packages/renderer/src/components/WebView.tsx
@@ -1,5 +1,5 @@
import React, { FC, useRef, useEffect } from "react";
-import useElectron from "../hooks/electron";
+import useElectron from "@/hooks/useElectron";
import { cn } from "@/utils";
interface DivRect {
diff --git a/packages/renderer/src/hooks/electron.ts b/packages/renderer/src/hooks/useElectron.ts
similarity index 100%
rename from packages/renderer/src/hooks/electron.ts
rename to packages/renderer/src/hooks/useElectron.ts
diff --git a/packages/renderer/src/layout/App.tsx b/packages/renderer/src/layout/App.tsx
index 636f0f0f..8485635e 100644
--- a/packages/renderer/src/layout/App.tsx
+++ b/packages/renderer/src/layout/App.tsx
@@ -1,6 +1,6 @@
import React, { FC, useEffect } from "react";
import { Outlet, useLocation } from "react-router-dom";
-import useElectron from "../hooks/electron";
+import useElectron from "@/hooks/useElectron";
import { useAsyncEffect } from "ahooks";
import { AppHeader } from "./AppHeader";
import { AppSideBar } from "./AppSideBar";
diff --git a/packages/renderer/src/layout/AppHeader.tsx b/packages/renderer/src/layout/AppHeader.tsx
index cefe9916..dcd4cece 100644
--- a/packages/renderer/src/layout/AppHeader.tsx
+++ b/packages/renderer/src/layout/AppHeader.tsx
@@ -1,4 +1,4 @@
-import useElectron from "@/hooks/electron";
+import useElectron from "@/hooks/useElectron";
import { cn } from "@/utils";
import React from "react";
import { useTranslation } from "react-i18next";
diff --git a/packages/renderer/src/layout/AppSideBar.tsx b/packages/renderer/src/layout/AppSideBar.tsx
index 469c21c8..30ae192f 100644
--- a/packages/renderer/src/layout/AppSideBar.tsx
+++ b/packages/renderer/src/layout/AppSideBar.tsx
@@ -1,7 +1,7 @@
import React, { cloneElement, PropsWithChildren, ReactElement } from "react";
import { Link, useLocation, useNavigate } from "react-router-dom";
import { Badge } from "antd";
-import useElectron from "../hooks/electron";
+import useElectron from "@/hooks/useElectron";
import { useTranslation } from "react-i18next";
import { cn, isWeb } from "@/utils";
import {
diff --git a/packages/renderer/src/pages/Converter/index.tsx b/packages/renderer/src/pages/Converter/index.tsx
index 8d9c2cf5..d6c9429e 100644
--- a/packages/renderer/src/pages/Converter/index.tsx
+++ b/packages/renderer/src/pages/Converter/index.tsx
@@ -1,10 +1,10 @@
import React, { ReactNode, useState } from "react";
-import PageContainer from "../../components/PageContainer";
+import PageContainer from "@/components/PageContainer";
import { useTranslation } from "react-i18next";
import { App, Empty } from "antd";
-import useElectron from "../../hooks/electron";
+import useElectron from "@/hooks/useElectron";
import { useMemoizedFn, usePagination } from "ahooks";
-import { getFileName, tdApp } from "../../utils";
+import { getFileName, tdApp } from "@/utils";
import { Conversion } from "../../../../main/types/entity/Conversion";
import { DeleteOutlined, SyncOutlined } from "@ant-design/icons";
import { produce } from "immer";
diff --git a/packages/renderer/src/pages/HomePage/components/DownloadItem.tsx b/packages/renderer/src/pages/HomePage/components/DownloadItem.tsx
index 075912d5..b0df0a9b 100644
--- a/packages/renderer/src/pages/HomePage/components/DownloadItem.tsx
+++ b/packages/renderer/src/pages/HomePage/components/DownloadItem.tsx
@@ -14,7 +14,7 @@ import {
PauseIcon,
TerminalIcon,
} from "@/assets/svg";
-import useElectron from "@/hooks/electron";
+import useElectron from "@/hooks/useElectron";
import { DownloadTag } from "@/components/DownloadTag";
import { IconButton } from "@/components/IconButton";
import { useMemoizedFn } from "ahooks";
diff --git a/packages/renderer/src/pages/HomePage/components/DownloadList.tsx b/packages/renderer/src/pages/HomePage/components/DownloadList.tsx
index e50e18e7..30c45264 100644
--- a/packages/renderer/src/pages/HomePage/components/DownloadList.tsx
+++ b/packages/renderer/src/pages/HomePage/components/DownloadList.tsx
@@ -6,7 +6,7 @@ import { produce } from "immer";
import { App, Empty, Pagination } from "antd";
import { DownloadFilter } from "@/types";
import { ListPagination } from "./types";
-import useElectron from "@/hooks/electron";
+import useElectron from "@/hooks/useElectron";
import { useTranslation } from "react-i18next";
import Loading from "@/components/Loading";
import { useMemoizedFn } from "ahooks";
diff --git a/packages/renderer/src/pages/HomePage/components/ListHeader.tsx b/packages/renderer/src/pages/HomePage/components/ListHeader.tsx
index 9c28adf9..fa78d282 100644
--- a/packages/renderer/src/pages/HomePage/components/ListHeader.tsx
+++ b/packages/renderer/src/pages/HomePage/components/ListHeader.tsx
@@ -4,7 +4,7 @@ import { Trans, useTranslation } from "react-i18next";
import { Checkbox } from "@/components/ui/checkbox";
import { DownloadFilter } from "@/types";
import { useMemoizedFn } from "ahooks";
-import useElectron from "@/hooks/electron";
+import useElectron from "@/hooks/useElectron";
import { isWeb } from "@/utils";
interface Props {
diff --git a/packages/renderer/src/pages/HomePage/index.tsx b/packages/renderer/src/pages/HomePage/index.tsx
index f83acc7d..e3a6ebba 100644
--- a/packages/renderer/src/pages/HomePage/index.tsx
+++ b/packages/renderer/src/pages/HomePage/index.tsx
@@ -1,8 +1,8 @@
import React, { FC, useEffect, useRef, useState } from "react";
-import PageContainer from "../../components/PageContainer";
+import PageContainer from "@/components/PageContainer";
import { useMemoizedFn, useMount, usePagination } from "ahooks";
-import useElectron from "../../hooks/electron";
-import { DownloadFilter, DownloadType } from "../../types";
+import useElectron from "@/hooks/useElectron";
+import { DownloadFilter, DownloadType } from "@/types";
import { useTranslation } from "react-i18next";
import { DownloadList } from "./components";
import DownloadForm, {
diff --git a/packages/renderer/src/pages/SettingPage/index.tsx b/packages/renderer/src/pages/SettingPage/index.tsx
index 7a57d839..4de2ecc5 100644
--- a/packages/renderer/src/pages/SettingPage/index.tsx
+++ b/packages/renderer/src/pages/SettingPage/index.tsx
@@ -1,5 +1,5 @@
import React, { PropsWithChildren, useEffect, useRef, useState } from "react";
-import PageContainer from "../../components/PageContainer";
+import PageContainer from "@/components/PageContainer";
import {
App,
Badge,
@@ -28,9 +28,9 @@ import {
appStoreSelector,
setAppStoreSelector,
} from "@/store/app";
-import useElectron from "../../hooks/electron";
+import useElectron from "@/hooks/useElectron";
import { useMemoizedFn, useRequest } from "ahooks";
-import { AppLanguage, AppTheme } from "../../types";
+import { AppLanguage, AppTheme } from "@/types";
import { useTranslation } from "react-i18next";
import { updateSelector, useSessionStore } from "@/store/session";
import { useShallow } from "zustand/react/shallow";
diff --git a/packages/renderer/src/pages/SourceExtract/components/BrowserView.tsx b/packages/renderer/src/pages/SourceExtract/components/BrowserView.tsx
index c32447af..98653554 100644
--- a/packages/renderer/src/pages/SourceExtract/components/BrowserView.tsx
+++ b/packages/renderer/src/pages/SourceExtract/components/BrowserView.tsx
@@ -1,7 +1,7 @@
import DownloadForm, { DownloadFormRef } from "@/components/DownloadForm";
import { Button } from "@/components/ui/button";
import WebView from "@/components/WebView";
-import useElectron from "@/hooks/electron";
+import useElectron from "@/hooks/useElectron";
import {
BrowserStatus,
browserStoreSelector,
diff --git a/packages/renderer/src/pages/SourceExtract/components/BrowserViewPanel.tsx b/packages/renderer/src/pages/SourceExtract/components/BrowserViewPanel.tsx
index 10a19c3d..9fb86ccb 100644
--- a/packages/renderer/src/pages/SourceExtract/components/BrowserViewPanel.tsx
+++ b/packages/renderer/src/pages/SourceExtract/components/BrowserViewPanel.tsx
@@ -1,7 +1,7 @@
import { DeleteIcon } from "@/assets/svg";
import { IconButton } from "@/components/IconButton";
import { Button } from "@/components/ui/button";
-import useElectron from "@/hooks/electron";
+import useElectron from "@/hooks/useElectron";
import {
browserStoreSelector,
setBrowserSelector,
diff --git a/packages/renderer/src/pages/SourceExtract/components/FavoriteList.tsx b/packages/renderer/src/pages/SourceExtract/components/FavoriteList.tsx
index 2374eea8..31d5015b 100644
--- a/packages/renderer/src/pages/SourceExtract/components/FavoriteList.tsx
+++ b/packages/renderer/src/pages/SourceExtract/components/FavoriteList.tsx
@@ -1,4 +1,4 @@
-import useElectron from "@/hooks/electron";
+import useElectron from "@/hooks/useElectron";
import { getFavIcon, tdApp } from "@/utils";
import { PlusOutlined } from "@ant-design/icons";
import { useRequest } from "ahooks";
diff --git a/packages/renderer/src/pages/SourceExtract/components/ToolBar.tsx b/packages/renderer/src/pages/SourceExtract/components/ToolBar.tsx
index 6e6eae8e..457bc9f5 100644
--- a/packages/renderer/src/pages/SourceExtract/components/ToolBar.tsx
+++ b/packages/renderer/src/pages/SourceExtract/components/ToolBar.tsx
@@ -1,4 +1,4 @@
-import useElectron from "@/hooks/electron";
+import useElectron from "@/hooks/useElectron";
import { cn, generateUrl, getFavIcon, tdApp } from "@/utils";
import { useRequest } from "ahooks";
import { Input, Tooltip } from "antd";
diff --git a/packages/renderer/src/pages/SourceExtract/index.tsx b/packages/renderer/src/pages/SourceExtract/index.tsx
index 0bb9a343..dce0f516 100644
--- a/packages/renderer/src/pages/SourceExtract/index.tsx
+++ b/packages/renderer/src/pages/SourceExtract/index.tsx
@@ -1,7 +1,7 @@
import { useAsyncEffect } from "ahooks";
import React, { useEffect, useRef } from "react";
-import PageContainer from "../../components/PageContainer";
-import useElectron from "../../hooks/electron";
+import PageContainer from "@/components/PageContainer";
+import useElectron from "@/hooks/useElectron";
import { FavoriteList } from "./components/FavoriteList";
import { BrowserView } from "./components/BrowserView";
import { ToolBar } from "./components/ToolBar";
diff --git a/packages/renderer/src/store/browser.ts b/packages/renderer/src/store/browser.ts
index 0f50acae..92603dd2 100644
--- a/packages/renderer/src/store/browser.ts
+++ b/packages/renderer/src/store/browser.ts
@@ -1,4 +1,4 @@
-import useElectron from "../hooks/electron";
+import useElectron from "@/hooks/useElectron";
import { DownloadType } from "@/types";
import { convertPlainObject } from "@/utils";
import { create } from "zustand";
From 623ed941f4a61d29264190e7a636fd1d115d6849 Mon Sep 17 00:00:00 2001
From: caorushizi <84996057@qq.com>
Date: Fri, 3 Jan 2025 03:37:35 +0800
Subject: [PATCH 3/4] =?UTF-8?q?perf:=20=F0=9F=9A=80=20=20use=20memoized=20?=
=?UTF-8?q?function?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
packages/renderer/eslint.config.js | 12 +
packages/renderer/package.json | 1 +
packages/renderer/src/App.tsx | 20 +-
packages/renderer/src/layout/AppHeader.tsx | 5 +-
packages/renderer/src/layout/AppSideBar.tsx | 217 ++++++++++--------
.../renderer/src/pages/Converter/index.tsx | 6 +-
.../HomePage/components/DownloadItem.tsx | 20 +-
.../HomePage/components/DownloadList.tsx | 18 +-
.../pages/HomePage/components/ListHeader.tsx | 3 +-
.../renderer/src/pages/HomePage/index.tsx | 88 +++----
packages/renderer/src/pages/Player/index.tsx | 4 +-
.../renderer/src/pages/SettingPage/index.tsx | 12 +-
.../SourceExtract/components/FavoriteList.tsx | 26 +--
.../SourceExtract/components/ToolBar.tsx | 60 ++---
.../src/pages/SourceExtract/index.tsx | 36 +--
pnpm-lock.yaml | 3 +
16 files changed, 295 insertions(+), 236 deletions(-)
diff --git a/packages/renderer/eslint.config.js b/packages/renderer/eslint.config.js
index febe369f..03a28c33 100644
--- a/packages/renderer/eslint.config.js
+++ b/packages/renderer/eslint.config.js
@@ -2,6 +2,7 @@ import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import pluginReactConfig from "eslint-plugin-react/configs/recommended.js";
+import pluginReactHooks from "eslint-plugin-react-hooks";
import { fixupConfigRules } from "@eslint/compat";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
@@ -11,6 +12,17 @@ export default [
...tseslint.configs.recommended,
...fixupConfigRules(pluginReactConfig),
eslintPluginPrettierRecommended,
+ {
+ files: ["src/**/*.{js,ts,jsx,tsx}"],
+ plugins: {
+ "react-hooks": pluginReactHooks,
+ },
+ rules: {
+ "react/react-in-jsx-scope": "off",
+ "react/prop-types": "off",
+ ...pluginReactHooks.configs.recommended.rules,
+ },
+ },
{
rules: {
"@typescript-eslint/no-explicit-any": "warn",
diff --git a/packages/renderer/package.json b/packages/renderer/package.json
index f68e9306..36f957a2 100644
--- a/packages/renderer/package.json
+++ b/packages/renderer/package.json
@@ -61,6 +61,7 @@
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react": "^7.34.3",
+ "eslint-plugin-react-hooks": "^4.6.2",
"globals": "^15.3.0",
"lint-staged": "^15.2.5",
"postcss": "^8.4.39",
diff --git a/packages/renderer/src/App.tsx b/packages/renderer/src/App.tsx
index f3e2c5eb..a1891234 100644
--- a/packages/renderer/src/App.tsx
+++ b/packages/renderer/src/App.tsx
@@ -7,7 +7,7 @@ import useElectron from "@/hooks/useElectron";
import Loading from "./components/Loading";
import { DownloadFilter } from "./types";
import { isWeb, tdApp } from "./utils";
-import { useAsyncEffect } from "ahooks";
+import { useAsyncEffect, useMemoizedFn } from "ahooks";
import {
themeSelector,
updateSelector,
@@ -41,28 +41,26 @@ const App: FC = () => {
const { increase } = useDownloadStore(useShallow(downloadStoreSelector));
const { theme, setTheme } = useSessionStore(useShallow(themeSelector));
- const themeChange = (event: MediaQueryListEvent) => {
+ const themeChange = useMemoizedFn((event: MediaQueryListEvent) => {
if (event.matches) {
setTheme("dark");
} else {
setTheme("light");
}
- };
+ });
// 监听store变化
- const onAppStoreChange = (event: any, store: AppStore) => {
+ const onAppStoreChange = useMemoizedFn((event: any, store: AppStore) => {
setAppStore(store);
- };
+ });
- const onReceiveDownloadItem = () => {
+ const onReceiveDownloadItem = useMemoizedFn(() => {
increase();
- };
+ });
- const onChangePrivacy = () => {
+ const onChangePrivacy = useMemoizedFn(() => {
setBrowserStore({ url: "", title: "", mode: PageMode.Default });
- };
-
- console.log("App.tsx: onAppStoreChange", onAppStoreChange);
+ });
useEffect(() => {
const updateAvailable = () => {
diff --git a/packages/renderer/src/layout/AppHeader.tsx b/packages/renderer/src/layout/AppHeader.tsx
index dcd4cece..4b83acb5 100644
--- a/packages/renderer/src/layout/AppHeader.tsx
+++ b/packages/renderer/src/layout/AppHeader.tsx
@@ -4,6 +4,7 @@ import React from "react";
import { useTranslation } from "react-i18next";
import { HelpIcon } from "@/assets/svg";
import LogoImg from "../assets/images/logo.png";
+import { useMemoizedFn } from "ahooks";
interface Props {
className?: string;
@@ -13,10 +14,10 @@ export function AppHeader({ className }: Props) {
const { openUrl } = useElectron();
const { t } = useTranslation();
- const openHelpUrl = () => {
+ const openHelpUrl = useMemoizedFn(() => {
const url = "https://downloader.caorushizi.cn/guides.html?form=client";
openUrl(url);
- };
+ });
return (
{
+ return activeKey === processLocation(link);
+ }, [activeKey, link]);
+
return (
) => {
- e.stopPropagation();
- e.preventDefault();
+ const activeKey = useMemo(
+ () => processLocation(location.pathname),
+ [location.pathname],
+ );
- setAppStore({ openInNewWindow: true });
- if (location.pathname === "/source") {
- navigate("/");
- }
- // FIXME: It is possible that the webview is not completely hidden yet
- await ipcSetAppStore("openInNewWindow", true);
- await showBrowserWindow();
- };
+ const handleExternalLink = useMemoizedFn(
+ async (e: React.MouseEvent
) => {
+ e.stopPropagation();
+ e.preventDefault();
- const items1: MenuItem[] = [
- {
- label: (
- {
- clearCount();
- }}
- activeKey={activeKey}
- icon={}
- >
- {t("downloadList")}
- {count > 0 && (
-
- )}
-
- ),
- key: "home",
- },
- {
- label: (
- }>
- {t("downloadComplete")}
-
- ),
- key: "done",
- },
- {
- label: (
- }
- >
- {t("converter")}
-
- ),
- key: "converter",
- },
- {
- label: (
- }
- >
- {t("materialExtraction")}
- handleExternalLink(e)}
- >
-
-
-
- ),
- key: "source",
- },
- {
- label: (
- }
- >
- {t("setting")}
-
-
- ),
- key: "settings",
+ setAppStore({ openInNewWindow: true });
+ if (location.pathname === "/source") {
+ navigate("/");
+ }
+ // FIXME: It is possible that the webview is not completely hidden yet
+ await ipcSetAppStore("openInNewWindow", true);
+ await showBrowserWindow();
},
- ];
- const items = items1.filter((i) =>
- isWeb ? i.key !== "source" && i.key !== "converter" : true,
);
- const finalItems = items.filter((item) =>
- appStore.openInNewWindow ? item?.key !== "source" : true,
- );
+ const handleClearCount = useMemoizedFn(() => {
+ clearCount();
+ });
+
+ const items1: MenuItem[] = useMemo(() => {
+ return [
+ {
+ label: (
+ }
+ >
+ {t("downloadList")}
+ {count > 0 && (
+
+ )}
+
+ ),
+ key: "home",
+ },
+ {
+ label: (
+ }>
+ {t("downloadComplete")}
+
+ ),
+ key: "done",
+ },
+ {
+ label: (
+ }
+ >
+ {t("converter")}
+
+ ),
+ key: "converter",
+ },
+ {
+ label: (
+ }
+ >
+ {t("materialExtraction")}
+
+
+
+
+ ),
+ key: "source",
+ },
+ {
+ label: (
+ }
+ >
+ {t("setting")}
+
+
+ ),
+ key: "settings",
+ },
+ ];
+ }, [
+ activeKey,
+ count,
+ handleExternalLink,
+ location.pathname,
+ t,
+ updateAvailable,
+ handleClearCount,
+ ]);
+
+ const finalItems = useMemo(() => {
+ return items1
+ .filter((i) =>
+ isWeb ? i.key !== "source" && i.key !== "converter" : true,
+ )
+ .filter((item) =>
+ appStore.openInNewWindow ? item?.key !== "source" : true,
+ );
+ }, [items1, appStore.openInNewWindow]);
return (
{
refresh();
});
- const renderActionButtons = (dom: ReactNode, item: Conversion): ReactNode => {
+ const renderActionButtons = useMemoizedFn((item: Conversion): ReactNode => {
// Download successfully
return [
{
} />
,
];
- };
+ });
const handleSelectFile = useMemoizedFn(async () => {
const file = await selectFile();
@@ -111,7 +111,7 @@ const Converter = () => {
{item.name}
- {renderActionButtons(null, item)}
+ {renderActionButtons(item)}
{item.path}
diff --git a/packages/renderer/src/pages/HomePage/components/DownloadItem.tsx b/packages/renderer/src/pages/HomePage/components/DownloadItem.tsx
index b0df0a9b..1982884e 100644
--- a/packages/renderer/src/pages/HomePage/components/DownloadItem.tsx
+++ b/packages/renderer/src/pages/HomePage/components/DownloadItem.tsx
@@ -54,7 +54,7 @@ export function DownloadItem({
const { t } = useTranslation();
const { openPlayerWindow } = useElectron();
- const renderTerminalBtn = (item: DownloadItem) => {
+ const renderTerminalBtn = useMemoizedFn((item: DownloadItem) => {
if (!appStore.showTerminal) return null;
return (
@@ -71,10 +71,10 @@ export function DownloadItem({
log={item.log}
/>
);
- };
+ });
// Edit form
- const renderEditIconBtn = (item: DownloadItem) => {
+ const renderEditIconBtn = useMemoizedFn((item: DownloadItem) => {
return (
onShowEditForm(item)}
/>
);
- };
+ });
const handlePlay = useMemoizedFn(() => {
openPlayerWindow();
@@ -109,7 +109,7 @@ export function DownloadItem({
tdApp.onEvent(STOP_DOWNLOAD);
});
- const renderActionButtons = (item: VideoStat): ReactNode => {
+ const renderActionButtons = useMemoizedFn((item: VideoStat): ReactNode => {
if (item.status === DownloadStatus.Ready) {
return [
renderTerminalBtn(item),
@@ -171,9 +171,9 @@ export function DownloadItem({
onClick={handlePlay}
/>,
];
- };
+ });
- const renderTitle = (item: VideoStat): ReactNode => {
+ const renderTitle = useMemoizedFn((item: VideoStat): ReactNode => {
return (
);
- };
+ });
const handleRenderTag = useMemoizedFn(() => {
let tag = null;
@@ -249,7 +249,7 @@ export function DownloadItem({
);
});
- const renderDescription = (item: DownloadItem): ReactNode => {
+ const renderDescription = useMemoizedFn((item: DownloadItem): ReactNode => {
if (progress) {
const { percent, speed } = progress;
const val = Math.round(Number(percent));
@@ -286,7 +286,7 @@ export function DownloadItem({
)}
);
- };
+ });
return (
{
+ const handleSelectAll = useMemoizedFn(() => {
setSelected(
produce((draft) => {
if (draft.length) {
@@ -131,7 +131,7 @@ export function DownloadList({
}
}),
);
- };
+ });
const listChecked = useMemo(() => {
if (selected.length === 0) {
@@ -141,7 +141,7 @@ export function DownloadList({
return true;
}
return "indeterminate";
- }, [selected]);
+ }, [selected, data.length]);
useEffect(() => {
setSelected([]);
@@ -185,15 +185,15 @@ export function DownloadList({
onDownloadListContextMenu(item);
});
- const onDeleteItems = async (ids: number[]) => {
+ const onDeleteItems = useMemoizedFn(async (ids: number[]) => {
for (const id of ids) {
await deleteDownloadItem(Number(id));
}
setSelected([]);
refresh();
- };
+ });
- const onDownloadItems = async (ids: number[]) => {
+ const onDownloadItems = useMemoizedFn(async (ids: number[]) => {
for (const id of ids) {
await startDownload(Number(id));
}
@@ -201,11 +201,11 @@ export function DownloadList({
message.success(t("addTaskSuccess"));
refresh();
setSelected([]);
- };
+ });
- const onCancelItems = async () => {
+ const onCancelItems = useMemoizedFn(async () => {
setSelected([]);
- };
+ });
const handleShowDownloadForm = useMemoizedFn((item: DownloadItem) => {
tdApp.onEvent(EDIT_DOWNLOAD);
diff --git a/packages/renderer/src/pages/HomePage/components/ListHeader.tsx b/packages/renderer/src/pages/HomePage/components/ListHeader.tsx
index fa78d282..a147063a 100644
--- a/packages/renderer/src/pages/HomePage/components/ListHeader.tsx
+++ b/packages/renderer/src/pages/HomePage/components/ListHeader.tsx
@@ -37,7 +37,8 @@ export function ListHeader({
label: t("exportDownloadList"),
},
];
- }, []);
+ }, [t]);
+
const onMenuClick: MenuProps["onClick"] = useMemoizedFn(async (e) => {
const { key } = e;
if (key === "exportDownloadList") {
diff --git a/packages/renderer/src/pages/HomePage/index.tsx b/packages/renderer/src/pages/HomePage/index.tsx
index e3a6ebba..1762dc32 100644
--- a/packages/renderer/src/pages/HomePage/index.tsx
+++ b/packages/renderer/src/pages/HomePage/index.tsx
@@ -101,52 +101,62 @@ const HomePage: FC
= ({ filter = DownloadFilter.list }) => {
setLocalIP(ip);
});
- const confirmAddItems = async (values: DownloadFormType, now?: boolean) => {
- const { batch, batchList = "", name, headers, type, url, folder } = values;
- if (batch) {
- /**
- * Here you need to parse the batchList
- * The format is batchList
- * url1 name1\n
- * url2 name2\n
- * url3
- * ...
- */
- const items: Omit[] = batchList
- .split("\n")
- .map((line: string) => {
- const [url, name, folder] = line.trim().split(" ");
- return {
- url: url.trim(),
- name: name || randomName(),
- headers,
- type,
- folder,
- };
- });
- if (now) {
- await downloadItemsNow(items);
- } else {
- await addDownloadItems(items);
- }
- } else {
- const item: Omit = {
+ const confirmAddItems = useMemoizedFn(
+ async (values: DownloadFormType, now?: boolean) => {
+ const {
+ batch,
+ batchList = "",
name,
- url,
headers,
type,
+ url,
folder,
- };
- if (now) {
- await downloadNow(item);
+ } = values;
+ if (batch) {
+ /**
+ * Here you need to parse the batchList
+ * The format is batchList
+ * url1 name1\n
+ * url2 name2\n
+ * url3
+ * ...
+ */
+ const items: Omit[] = batchList
+ .split("\n")
+ .map((line: string) => {
+ const [url, name, folder] = line.trim().split(" ");
+ return {
+ url: url.trim(),
+ name: name || randomName(),
+ headers,
+ type,
+ folder,
+ };
+ });
+ if (now) {
+ await downloadItemsNow(items);
+ } else {
+ await addDownloadItems(items);
+ }
} else {
- await addDownloadItem(item);
+ const item: Omit = {
+ name,
+ url,
+ headers,
+ type,
+ folder,
+ };
+ if (now) {
+ await downloadNow(item);
+ } else {
+ await addDownloadItem(item);
+ }
}
- }
- refresh();
- return true;
- };
+ refresh();
+ return true;
+ },
+ );
const handleOpenForm = useMemoizedFn(() => {
tdApp.onEvent(CLICK_DOWNLOAD);
diff --git a/packages/renderer/src/pages/Player/index.tsx b/packages/renderer/src/pages/Player/index.tsx
index 4fe32c10..013851bb 100644
--- a/packages/renderer/src/pages/Player/index.tsx
+++ b/packages/renderer/src/pages/Player/index.tsx
@@ -35,13 +35,13 @@ export default function PlayerPage() {
}
}, []);
- const handleVideoClick = (url: string) => {
+ const handleVideoClick = useMemoizedFn((url: string) => {
setCurrentVideo(url);
player.current.src = url;
player.current.play();
setOpen(false);
- };
+ });
const onClose = useMemoizedFn(() => {
setOpen(false);
diff --git a/packages/renderer/src/pages/SettingPage/index.tsx b/packages/renderer/src/pages/SettingPage/index.tsx
index 4de2ecc5..36ed10fd 100644
--- a/packages/renderer/src/pages/SettingPage/index.tsx
+++ b/packages/renderer/src/pages/SettingPage/index.tsx
@@ -90,13 +90,13 @@ const SettingPage: React.FC = () => {
formRef.current?.setFieldsValue(settings);
}, [settings]);
- const onSelectDir = async () => {
+ const onSelectDir = useMemoizedFn(async () => {
const local = await onSelectDownloadDir();
if (local) {
setAppStore({ local });
formRef.current?.setFieldValue("local", local);
}
- };
+ });
const renderButtonLabel = useMemoizedFn(() => {
if (isWeb) {
@@ -135,7 +135,7 @@ const SettingPage: React.FC = () => {
},
];
- const onMenuClick: MenuProps["onClick"] = async (e) => {
+ const onMenuClick: MenuProps["onClick"] = useMemoizedFn(async (e) => {
const { key } = e;
if (key === "1") {
try {
@@ -145,16 +145,16 @@ const SettingPage: React.FC = () => {
message.error(t("importFavoriteFailed"));
}
}
- };
+ });
- const handleExportFavorite = async () => {
+ const handleExportFavorite = useMemoizedFn(async () => {
try {
await exportFavorites();
message.success(t("exportFavoriteSuccess"));
} catch (e: any) {
message.error(t("exportFavoriteFailed"));
}
- };
+ });
const handleCheckUpdate = useMemoizedFn(async () => {
tdApp.onEvent(CHECK_UPDATE);
diff --git a/packages/renderer/src/pages/SourceExtract/components/FavoriteList.tsx b/packages/renderer/src/pages/SourceExtract/components/FavoriteList.tsx
index 31d5015b..fbf5a5e6 100644
--- a/packages/renderer/src/pages/SourceExtract/components/FavoriteList.tsx
+++ b/packages/renderer/src/pages/SourceExtract/components/FavoriteList.tsx
@@ -1,7 +1,7 @@
import useElectron from "@/hooks/useElectron";
import { getFavIcon, tdApp } from "@/utils";
import { PlusOutlined } from "@ant-design/icons";
-import { useRequest } from "ahooks";
+import { useMemoizedFn, useRequest } from "ahooks";
import { App, Form, Input, Modal } from "antd";
import React, { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
@@ -32,31 +32,31 @@ export function FavoriteList() {
const [isModalOpen, setIsModalOpen] = useState(false);
const { setBrowserStore } = useBrowserStore(useShallow(setBrowserSelector));
- const loadUrl = (url: string) => {
+ const loadUrl = useMemoizedFn((url: string) => {
setBrowserStore({
url,
mode: PageMode.Browser,
status: BrowserStatus.Loading,
});
webviewLoadURL(url);
- };
+ });
- const onClickLoadItem = (item: Favorite) => {
+ const onClickLoadItem = useMemoizedFn((item: Favorite) => {
loadUrl(item.url);
tdApp.onEvent(OPEN_FAVORITE);
- };
+ });
- const handleRemoveFavorite = async (id: number) => {
+ const handleRemoveFavorite = useMemoizedFn(async (id: number) => {
removeFavorite(id);
refresh();
- };
+ });
- const showModal = () => {
+ const showModal = useMemoizedFn(() => {
setIsModalOpen(true);
tdApp.onEvent(ADD_FAVORITE);
- };
+ });
- const handleOk = async () => {
+ const handleOk = useMemoizedFn(async () => {
try {
const values = await favoriteAddForm.validateFields();
const icon = await getFavIcon(values.url);
@@ -72,11 +72,11 @@ export function FavoriteList() {
} catch (err: any) {
message.error(err.message || t("addFavoriteFailed"));
}
- };
+ });
- const handleCancel = () => {
+ const handleCancel = useMemoizedFn(() => {
setIsModalOpen(false);
- };
+ });
useEffect(() => {
const onClickLoadItem = (item: Favorite) => {
diff --git a/packages/renderer/src/pages/SourceExtract/components/ToolBar.tsx b/packages/renderer/src/pages/SourceExtract/components/ToolBar.tsx
index 457bc9f5..109eb427 100644
--- a/packages/renderer/src/pages/SourceExtract/components/ToolBar.tsx
+++ b/packages/renderer/src/pages/SourceExtract/components/ToolBar.tsx
@@ -1,6 +1,6 @@
import useElectron from "@/hooks/useElectron";
import { cn, generateUrl, getFavIcon, tdApp } from "@/utils";
-import { useRequest } from "ahooks";
+import { useMemoizedFn, useRequest } from "ahooks";
import { Input, Tooltip } from "antd";
import React, { useMemo } from "react";
import { useTranslation } from "react-i18next";
@@ -62,48 +62,50 @@ export function ToolBar({ page }: Props) {
store.status !== BrowserStatus.Loaded || store.mode !== PageMode.Browser;
// Set default UA
- const onSetDefaultUA = () => {
+ const onSetDefaultUA = useMemoizedFn(() => {
const nextMode = !appStore.isMobile;
setUserAgent(nextMode);
setAppStore({
isMobile: nextMode,
});
- };
+ });
const curIsFavorite = useMemo(() => {
return favoriteList.find((item) => item.url === store.url);
}, [favoriteList, store.url]);
- const onInputKeyDown = async (e: React.KeyboardEvent) => {
- if (!store.url) {
- return;
- }
- if (e.key !== "Enter") {
- return;
- }
-
- await goto();
- };
+ const onInputKeyDown = useMemoizedFn(
+ async (e: React.KeyboardEvent) => {
+ if (!store.url) {
+ return;
+ }
+ if (e.key !== "Enter") {
+ return;
+ }
+
+ await goto();
+ },
+ );
- const onClickGoBack = async () => {
+ const onClickGoBack = useMemoizedFn(async () => {
const back = await webviewGoBack();
if (!back) {
// TODO: Reset title
// document.title = originTitle.current;
setBrowserStore({ url: "", title: "", mode: PageMode.Default });
}
- };
+ });
- const onClickGoHome = async () => {
+ const onClickGoHome = useMemoizedFn(async () => {
await webviewGoHome();
setBrowserStore({
url: "",
title: "",
mode: PageMode.Default,
});
- };
+ });
- const loadUrl = (url: string) => {
+ const loadUrl = useMemoizedFn((url: string) => {
tdApp.onEvent(OPEN_URL);
setBrowserStore({
url,
@@ -111,21 +113,21 @@ export function ToolBar({ page }: Props) {
status: BrowserStatus.Loading,
});
webviewLoadURL(url);
- };
+ });
- const onInputContextMenu = () => {
+ const onInputContextMenu = useMemoizedFn(() => {
webviewUrlContextMenu();
- };
+ });
- const onClickEnter = async () => {
+ const onClickEnter = useMemoizedFn(async () => {
if (!store.url) {
return;
}
await goto();
- };
+ });
- const onClickAddFavorite = async () => {
+ const onClickAddFavorite = useMemoizedFn(async () => {
if (curIsFavorite) {
await removeFavorite(curIsFavorite.id);
} else {
@@ -137,17 +139,17 @@ export function ToolBar({ page }: Props) {
});
}
refresh();
- };
+ });
// Merge to home page
- const onCombineToHome = () => {
+ const onCombineToHome = useMemoizedFn(() => {
combineToHomePage(store);
- };
+ });
- const goto = () => {
+ const goto = useMemoizedFn(() => {
const link = generateUrl(store.url);
loadUrl(link);
- };
+ });
const iconColor = theme === "dark" ? "white" : "black";
diff --git a/packages/renderer/src/pages/SourceExtract/index.tsx b/packages/renderer/src/pages/SourceExtract/index.tsx
index dce0f516..266a8bb9 100644
--- a/packages/renderer/src/pages/SourceExtract/index.tsx
+++ b/packages/renderer/src/pages/SourceExtract/index.tsx
@@ -1,4 +1,4 @@
-import { useAsyncEffect } from "ahooks";
+import { useAsyncEffect, useMemoizedFn } from "ahooks";
import React, { useEffect, useRef } from "react";
import PageContainer from "@/components/PageContainer";
import useElectron from "@/hooks/useElectron";
@@ -56,38 +56,40 @@ const SourceExtract: React.FC = ({ page = false }) => {
};
}, [store.status]);
- const setPageInfo = ({ url, title }: UrlDetail) => {
+ const setPageInfo = useMemoizedFn(({ url, title }: UrlDetail) => {
document.title = title;
setBrowserStore({ url, title });
- };
+ });
- const onDomReady = (e: unknown, info: UrlDetail) => {
+ const onDomReady = useMemoizedFn((e: unknown, info: UrlDetail) => {
setPageInfo(info);
- };
+ });
- const onFailLoad = (e: unknown, data: { code: number; desc: string }) => {
- setBrowserStore({
- status: BrowserStatus.Failed,
- errCode: data.code,
- errMsg: data.desc,
- });
- };
+ const onFailLoad = useMemoizedFn(
+ (e: unknown, data: { code: number; desc: string }) => {
+ setBrowserStore({
+ status: BrowserStatus.Failed,
+ errCode: data.code,
+ errMsg: data.desc,
+ });
+ },
+ );
- const onDidNavigate = (e: unknown, info: UrlDetail) => {
+ const onDidNavigate = useMemoizedFn((e: unknown, info: UrlDetail) => {
setPageInfo(info);
setBrowserStore({ status: BrowserStatus.Loaded });
- };
+ });
- const onDidNavigateInPage = (e: unknown, info: UrlDetail) => {
+ const onDidNavigateInPage = useMemoizedFn((e: unknown, info: UrlDetail) => {
setPageInfo(info);
- };
+ });
useEffect(() => {
document.title = store.title || document.title;
return () => {
document.title = originTitle.current;
};
- }, []);
+ }, [store.title]);
return (
Date: Fri, 3 Jan 2025 04:19:31 +0800
Subject: [PATCH 4/4] =?UTF-8?q?feat:=20=E2=9C=A8=20=20video=20sniffing=20p?=
=?UTF-8?q?age=20added=20one-click=20cleanup=20and=20one-click=20download?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
packages/renderer/src/assets/svg/EditIcon.tsx | 13 +----
.../renderer/src/components/ui/button.tsx | 2 +-
.../components/BrowserViewPanel.tsx | 56 ++++++++++++++++---
packages/renderer/src/store/browser.ts | 7 +++
4 files changed, 59 insertions(+), 19 deletions(-)
diff --git a/packages/renderer/src/assets/svg/EditIcon.tsx b/packages/renderer/src/assets/svg/EditIcon.tsx
index 4916de49..3d32a3b3 100644
--- a/packages/renderer/src/assets/svg/EditIcon.tsx
+++ b/packages/renderer/src/assets/svg/EditIcon.tsx
@@ -10,16 +10,9 @@ export function EditIcon(props: React.SVGProps) {
xmlns="http://www.w3.org/2000/svg"
{...props}
>
-
-
-
-
-
-
-
-
-
-
+
+
+
);
}
diff --git a/packages/renderer/src/components/ui/button.tsx b/packages/renderer/src/components/ui/button.tsx
index 205fec86..375be871 100644
--- a/packages/renderer/src/components/ui/button.tsx
+++ b/packages/renderer/src/components/ui/button.tsx
@@ -22,7 +22,7 @@ const buttonVariants = cva(
},
size: {
default: "h-[30px] px-3 py-1",
- sm: "h-[20px] rounded-md px-1",
+ sm: "h-[20px] rounded-md px-1.5 text-xs",
lg: "h-11 rounded-md px-8",
icon: "h-10 w-10",
},
diff --git a/packages/renderer/src/pages/SourceExtract/components/BrowserViewPanel.tsx b/packages/renderer/src/pages/SourceExtract/components/BrowserViewPanel.tsx
index 9fb86ccb..bd047ddb 100644
--- a/packages/renderer/src/pages/SourceExtract/components/BrowserViewPanel.tsx
+++ b/packages/renderer/src/pages/SourceExtract/components/BrowserViewPanel.tsx
@@ -1,24 +1,53 @@
-import { DeleteIcon } from "@/assets/svg";
-import { IconButton } from "@/components/IconButton";
import { Button } from "@/components/ui/button";
import useElectron from "@/hooks/useElectron";
import {
browserStoreSelector,
setBrowserSelector,
+ SourceData,
useBrowserStore,
} from "@/store/browser";
import React from "react";
import { useTranslation } from "react-i18next";
import { useShallow } from "zustand/react/shallow";
+import { Button as AntdButton, App } from "antd";
+import { DeleteOutlined, EditOutlined } from "@ant-design/icons";
+import { useMemoizedFn } from "ahooks";
export function BrowserViewPanel() {
const store = useBrowserStore(useShallow(browserStoreSelector));
- const { deleteSource } = useBrowserStore(useShallow(setBrowserSelector));
+ const { deleteSource, clearSources } = useBrowserStore(
+ useShallow(setBrowserSelector),
+ );
const { t } = useTranslation();
const { showDownloadDialog } = useElectron();
+ const { downloadNow } = useElectron();
+ const { message } = App.useApp();
+
+ const handleClear = useMemoizedFn(() => {
+ clearSources();
+ });
+
+ const handleDownloadNow = useMemoizedFn(async (item: SourceData) => {
+ try {
+ const downloadItem: Omit = {
+ url: item.url,
+ name: item.name,
+ headers: item.headers,
+ type: item.type,
+ };
+ await downloadNow(downloadItem);
+ } catch (e) {
+ message.error((e as any).message);
+ }
+ });
return (
+
{store.sources.map((item, index) => {
return (
-
-
}
+
+
}
+ type="text"
+ size="small"
onClick={() => deleteSource(item.url)}
+ title={t("delete")}
+ danger
+ />
+
}
+ type="text"
+ size="small"
+ title={t("edit")}
+ onClick={() => showDownloadDialog([item])}
/>
-
diff --git a/packages/renderer/src/store/browser.ts b/packages/renderer/src/store/browser.ts
index 92603dd2..80d3955c 100644
--- a/packages/renderer/src/store/browser.ts
+++ b/packages/renderer/src/store/browser.ts
@@ -4,6 +4,7 @@ import { convertPlainObject } from "@/utils";
import { create } from "zustand";
import { immer } from "zustand/middleware/immer";
+// eslint-disable-next-line react-hooks/rules-of-hooks
const { setSharedState } = useElectron();
export enum PageMode {
@@ -42,6 +43,7 @@ type Actions = {
addSource: (source: SourceData) => void;
deleteSource: (url: string) => void;
setSources: (sources: SourceData[]) => void;
+ clearSources: () => void;
};
export const useBrowserStore = create
()(
@@ -68,6 +70,10 @@ export const useBrowserStore = create()(
set((state) => {
state.sources = sources;
}),
+ clearSources: () =>
+ set((state) => {
+ state.sources = [];
+ }),
})),
);
@@ -89,5 +95,6 @@ export const setBrowserSelector = (state: BrowserStore & Actions) => {
addSource: state.addSource,
deleteSource: state.deleteSource,
setSources: state.setSources,
+ clearSources: state.clearSources,
};
};