Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e846390d04 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "media-downloader",
|
||||
"version": "1.1.2",
|
||||
"version": "1.1.3",
|
||||
"description": "在线视频下载",
|
||||
"author": "caorushizi",
|
||||
"main": "dist/main/index.js",
|
||||
|
||||
@@ -22,6 +22,7 @@ export default function handleStore(): void {
|
||||
tip: true,
|
||||
proxy: "",
|
||||
useProxy: false,
|
||||
statistics: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -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<AppState, Settings>((state) => state.settings);
|
||||
const dispatch = useDispatch();
|
||||
const formRef = useRef<FormInstance<FormData>>();
|
||||
const [proxyChecked, setProxyChecked] = useState<boolean>(false);
|
||||
|
||||
useEffect(() => {
|
||||
const { useProxy } = settings;
|
||||
setProxyChecked(useProxy);
|
||||
}, []);
|
||||
const formRef = useRef<FormInstance<Settings>>();
|
||||
const {
|
||||
store,
|
||||
getPath,
|
||||
showOpenDialog,
|
||||
openConfigDir: openConfigDirElectron,
|
||||
openBinDir: openBinDirElectron,
|
||||
openPath,
|
||||
} = useElectron();
|
||||
|
||||
// 选择下载地址
|
||||
const handleSelectDir = async (): Promise<void> => {
|
||||
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<void> => {
|
||||
window.electron.openConfigDir();
|
||||
openConfigDirElectron();
|
||||
};
|
||||
|
||||
// 打开可执行程序文件夹
|
||||
const openBinDir = () => {
|
||||
window.electron.openBinDir();
|
||||
openBinDirElectron();
|
||||
};
|
||||
|
||||
// 本地存储文件夹
|
||||
const localDir = async (): Promise<void> => {
|
||||
const { workspace } = settings;
|
||||
window.electron.openPath(workspace);
|
||||
await openPath(workspace);
|
||||
};
|
||||
|
||||
// 更改代理设置
|
||||
const toggleProxySetting = async (enableProxy: boolean): Promise<void> => {
|
||||
setProxyChecked(enableProxy);
|
||||
await window.electron.store.set("useProxy", enableProxy);
|
||||
};
|
||||
|
||||
const { workspace, exeFile, tip, proxy } = settings;
|
||||
const { useProxy } = settings;
|
||||
|
||||
return (
|
||||
<Box className="setting-form">
|
||||
<ProForm<FormData>
|
||||
<ProForm<Settings>
|
||||
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 }));
|
||||
}}
|
||||
>
|
||||
<ProFormGroup label="基础设置" direction={"vertical"}>
|
||||
@@ -128,18 +130,33 @@ const Setting: FC = () => {
|
||||
name="proxy"
|
||||
placeholder="请填写代理地址"
|
||||
label="代理设置"
|
||||
fieldProps={{
|
||||
addonAfter: (
|
||||
<Tooltip title="该代理会对软件自带浏览器以及下载时生效">
|
||||
<Switch
|
||||
checked={proxyChecked}
|
||||
checkedChildren="代理生效"
|
||||
unCheckedChildren="代理关闭"
|
||||
onChange={toggleProxySetting}
|
||||
/>
|
||||
/>
|
||||
<ProFormSwitch
|
||||
name={"useProxy"}
|
||||
label={
|
||||
<Box d={"flex"} flexDirection={"row"} alignItems={"center"}>
|
||||
<Box mr={5}>代理开关</Box>
|
||||
<Tooltip
|
||||
title={"该代理会对软件自带浏览器以及下载时生效"}
|
||||
placement={"right"}
|
||||
>
|
||||
<QuestionCircleOutlined />
|
||||
</Tooltip>
|
||||
),
|
||||
}}
|
||||
</Box>
|
||||
}
|
||||
>
|
||||
<Switch />
|
||||
</ProFormSwitch>
|
||||
<ProFormSwitch
|
||||
label={
|
||||
<Box d={"flex"} flexDirection={"row"} alignItems={"center"}>
|
||||
<Box mr={5}>允许打点统计</Box>
|
||||
<Tooltip title={statisticsTooltip} placement={"right"}>
|
||||
<QuestionCircleOutlined />
|
||||
</Tooltip>
|
||||
</Box>
|
||||
}
|
||||
name="statistics"
|
||||
/>
|
||||
</ProFormGroup>
|
||||
<ProFormGroup label="下载设置" direction={"vertical"}>
|
||||
|
||||
@@ -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<void> => {
|
||||
const item: SourceItem = {
|
||||
...source,
|
||||
exeFile,
|
||||
status: SourceStatus.Ready,
|
||||
type: SourceType.M3u8,
|
||||
directory: settings.workspace,
|
||||
|
||||
@@ -4,6 +4,7 @@ export interface Settings {
|
||||
proxy: string;
|
||||
useProxy: boolean;
|
||||
exeFile: string;
|
||||
statistics: boolean; // 是否允许打点统计
|
||||
}
|
||||
|
||||
export const UPDATE_SETTINGS = "UPDATE_SETTINGS";
|
||||
|
||||
@@ -10,6 +10,7 @@ const initialState: Settings = {
|
||||
tip: true,
|
||||
proxy: "",
|
||||
useProxy: false,
|
||||
statistics: true,
|
||||
};
|
||||
|
||||
export default function settings(
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
@@ -137,6 +137,7 @@ declare interface AppStore {
|
||||
proxy: string;
|
||||
useProxy: boolean;
|
||||
exeFile: string;
|
||||
statistics: boolean; // 是否允许打点统计
|
||||
}
|
||||
|
||||
declare interface Manifest {
|
||||
|
||||
Reference in New Issue
Block a user