From 90da95dec7e805ae09c6fd92889bc7a64765e9d0 Mon Sep 17 00:00:00 2001 From: caorushizi <84996057@qq.com> Date: Tue, 25 Jan 2022 23:52:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=95=B0=E6=8D=AE=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E8=AE=B8=E5=8F=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/main/helper/handleStore.ts | 1 + .../nodes/main/elements/Setting/index.tsx | 129 ++++++++++-------- src/renderer/nodes/main/index.tsx | 5 +- .../store/actions/settings.actions.ts | 1 + src/renderer/store/reducers/settings.ts | 1 + src/renderer/utils/td.ts | 6 +- src/types/renderer.d.ts | 1 + 8 files changed, 86 insertions(+), 60 deletions(-) diff --git a/package.json b/package.json index 36700b5..8a70703 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "media-downloader", - "version": "1.1.2", + "version": "1.1.3", "description": "在线视频下载", "author": "caorushizi", "main": "dist/main/index.js", diff --git a/src/main/helper/handleStore.ts b/src/main/helper/handleStore.ts index 7423746..ff8876d 100644 --- a/src/main/helper/handleStore.ts +++ b/src/main/helper/handleStore.ts @@ -22,6 +22,7 @@ export default function handleStore(): void { tip: true, proxy: "", useProxy: false, + statistics: true, }, }); diff --git a/src/renderer/nodes/main/elements/Setting/index.tsx b/src/renderer/nodes/main/elements/Setting/index.tsx index 8fba85d..47e77b0 100644 --- a/src/renderer/nodes/main/elements/Setting/index.tsx +++ b/src/renderer/nodes/main/elements/Setting/index.tsx @@ -1,5 +1,5 @@ -import React, { FC, useEffect, useRef, useState } from "react"; -import { Button, FormInstance, Space, Switch, Tooltip } from "antd"; +import React, { FC, useRef } from "react"; +import { Button, FormInstance, Space, Switch, Tooltip, Form } from "antd"; import "./index.scss"; import ProForm, { ProFormGroup, @@ -7,7 +7,7 @@ import ProForm, { ProFormSwitch, ProFormText, } from "@ant-design/pro-form"; -import { FolderOpenOutlined } from "@ant-design/icons"; +import { FolderOpenOutlined, QuestionCircleOutlined } from "@ant-design/icons"; import { AppState } from "renderer/store/reducers"; import { Settings, @@ -17,30 +17,33 @@ import { useDispatch, useSelector } from "react-redux"; import { Box } from "@chakra-ui/react"; import { version } from "../../../../../../package.json"; import { downloaderOptions } from "renderer/utils/variables"; +import useElectron from "renderer/hooks/electron"; -interface FormData { - exeFile: string; - workspace: string; - tip: boolean; - proxy: string; -} +const statisticsTooltip = ` +是否允许统计用户数据 +1. 统计数据不会用于商业用途,仅仅用于优化用户体验 +2. 关闭用户统计依然会收集打开页面的次数,但不会收集任何自定义数据 +3. 软件会统计页面报错,以便排查错误,请谅解~ +`; // 设置页面 const Setting: FC = () => { const settings = useSelector((state) => state.settings); const dispatch = useDispatch(); - const formRef = useRef>(); - const [proxyChecked, setProxyChecked] = useState(false); - - useEffect(() => { - const { useProxy } = settings; - setProxyChecked(useProxy); - }, []); + const formRef = useRef>(); + const { + store, + getPath, + showOpenDialog, + openConfigDir: openConfigDirElectron, + openBinDir: openBinDirElectron, + openPath, + } = useElectron(); // 选择下载地址 const handleSelectDir = async (): Promise => { - const defaultPath = await window.electron.getPath("documents"); - const { filePaths } = await window.electron.showOpenDialog({ + const defaultPath = await getPath("documents"); + const { filePaths } = await showOpenDialog({ defaultPath, properties: ["openDirectory"], }); @@ -49,7 +52,7 @@ const Setting: FC = () => { // 返回值为空 if (Array.isArray(filePaths) && filePaths.length <= 0) return; const workspaceValue = filePaths[0]; - await window.electron.store.set("workspace", workspaceValue); + await store.set("workspace", workspaceValue); formRef.current?.setFieldsValue({ workspace: workspaceValue || "", }); @@ -59,55 +62,54 @@ const Setting: FC = () => { // 打开配置文件文件夹 const openConfigDir = async (): Promise => { - window.electron.openConfigDir(); + openConfigDirElectron(); }; // 打开可执行程序文件夹 const openBinDir = () => { - window.electron.openBinDir(); + openBinDirElectron(); }; // 本地存储文件夹 const localDir = async (): Promise => { const { workspace } = settings; - window.electron.openPath(workspace); - }; - - // 更改代理设置 - const toggleProxySetting = async (enableProxy: boolean): Promise => { - setProxyChecked(enableProxy); - await window.electron.store.set("useProxy", enableProxy); + await openPath(workspace); }; - const { workspace, exeFile, tip, proxy } = settings; + const { useProxy } = settings; return ( - + formRef={formRef} layout="horizontal" submitter={false} labelCol={{ style: { width: "130px" } }} labelAlign={"left"} + size={"small"} colon={false} - initialValues={{ workspace, exeFile, tip, proxy }} + initialValues={settings} onValuesChange={async (changedValue) => { - if (Object.keys(changedValue).includes("tip")) { - await window.electron.store.set("tip", changedValue["tip"]); - } - if (Object.keys(changedValue).includes("exeFile")) { - const value = changedValue["exeFile"]; - await window.electron.store.set("exeFile", value); - dispatch(updateSettings({ exeFile: value })); - } - // 代理 onchange 事件 - if (Object.keys(changedValue).includes("proxy")) { - const value = changedValue["proxy"]; - await window.electron.store.set("proxy", value); - if (proxyChecked) { - await toggleProxySetting(false); + for (const key in changedValue) { + if (changedValue.hasOwnProperty(key)) { + const value = changedValue[key]; + await store.set(key, value); + + // 如果修改代理地址,关闭代理,可以手动打开 + if (key === "proxy" && useProxy) { + await store.set("useProxy", false); + const form = formRef.current; + if (form) { + form.setFieldsValue({ + ...settings, + useProxy: false, + proxy: value, + }); + } + } } } + dispatch(updateSettings({ ...settings, ...changedValue })); }} > @@ -128,18 +130,33 @@ const Setting: FC = () => { name="proxy" placeholder="请填写代理地址" label="代理设置" - fieldProps={{ - addonAfter: ( - - + /> + + 代理开关 + + + + + } + > + + + + 允许打点统计 + + - ), - }} + + } + name="statistics" /> diff --git a/src/renderer/nodes/main/index.tsx b/src/renderer/nodes/main/index.tsx index 7a5986b..45c8995 100644 --- a/src/renderer/nodes/main/index.tsx +++ b/src/renderer/nodes/main/index.tsx @@ -1,6 +1,6 @@ import React, { FC, useEffect, useRef, useState } from "react"; import "./index.scss"; -import { Badge, Button, Drawer, message, Tabs } from "antd"; +import { Badge, Button, message, Tabs } from "antd"; import WindowToolBar from "renderer/components/WindowToolBar"; import Setting from "renderer/nodes/main/elements/Setting"; import { SourceStatus, SourceType } from "renderer/types"; @@ -45,7 +45,7 @@ const MainPage: FC = () => { (state) => state.main ); countRef.current = notifyCount; - const { workspace } = settings; + const { workspace, exeFile } = settings; const { addEventListener, removeEventListener, @@ -80,6 +80,7 @@ const MainPage: FC = () => { ): Promise => { const item: SourceItem = { ...source, + exeFile, status: SourceStatus.Ready, type: SourceType.M3u8, directory: settings.workspace, diff --git a/src/renderer/store/actions/settings.actions.ts b/src/renderer/store/actions/settings.actions.ts index 5536985..091ec2d 100644 --- a/src/renderer/store/actions/settings.actions.ts +++ b/src/renderer/store/actions/settings.actions.ts @@ -4,6 +4,7 @@ export interface Settings { proxy: string; useProxy: boolean; exeFile: string; + statistics: boolean; // 是否允许打点统计 } export const UPDATE_SETTINGS = "UPDATE_SETTINGS"; diff --git a/src/renderer/store/reducers/settings.ts b/src/renderer/store/reducers/settings.ts index bb46bfb..887e7c5 100644 --- a/src/renderer/store/reducers/settings.ts +++ b/src/renderer/store/reducers/settings.ts @@ -10,6 +10,7 @@ const initialState: Settings = { tip: true, proxy: "", useProxy: false, + statistics: true, }; export default function settings( diff --git a/src/renderer/utils/td.ts b/src/renderer/utils/td.ts index d77d5e1..5625bc0 100644 --- a/src/renderer/utils/td.ts +++ b/src/renderer/utils/td.ts @@ -1,4 +1,5 @@ import { version } from "../../../package.json"; +import store from "renderer/store"; const isProd = process.env.NODE_ENV === "production"; @@ -21,7 +22,10 @@ class TDEvent { } onEvent(eventId: string, mapKv: any = {}) { - window.TDAPP.onEvent(eventId, "", mapKv); + const { settings } = store.getState(); + if (settings.statistics) { + window.TDAPP.onEvent(eventId, "", mapKv); + } } } diff --git a/src/types/renderer.d.ts b/src/types/renderer.d.ts index b7cae1a..604e82c 100644 --- a/src/types/renderer.d.ts +++ b/src/types/renderer.d.ts @@ -137,6 +137,7 @@ declare interface AppStore { proxy: string; useProxy: boolean; exeFile: string; + statistics: boolean; // 是否允许打点统计 } declare interface Manifest {