Skip to content

Commit

Permalink
update electron.
Browse files Browse the repository at this point in the history
  • Loading branch information
caorushizi committed Jan 21, 2024
1 parent 2609b0a commit 3ce5c9d
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
APP_NAME=media-downloader
APP_ID=mediago.ziying.site
APP_COPYRIGHT=caorushizi
APP_VERSION=2.0.3-beta.1
APP_VERSION=2.0.3-beta.2

APP_SERVER_PORT=8433
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
APP_TD_APPID=
APP_CLARITY_APPID=
APP_DOWNLOAD_DEBUG=true

GH_TOKEN=
Expand Down
1 change: 1 addition & 0 deletions .env.production
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
APP_TD_APPID=
APP_CLARITY_APPID=
APP_DOWNLOAD_DEBUG=

GH_TOKEN=
2 changes: 1 addition & 1 deletion packages/main/app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "media-downloader",
"version": "2.0.3-beta.1",
"version": "2.0.3-beta.2",
"description": "在线视频下载器",
"main": "main/index.js",
"author": "",
Expand Down
2 changes: 0 additions & 2 deletions packages/renderer/src/layout/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
selectCount,
} from "../../store";
import { useAsyncEffect } from "ahooks";
import { tdApp } from "../../utils";

const { Footer, Sider, Content } = Layout;

Expand Down Expand Up @@ -126,7 +125,6 @@ const App: FC = () => {
);

const openHelpUrl = () => {
tdApp.openHelpPage();
const url = "https://downloader.caorushizi.cn/guides.html?form=client";
openUrl(url);
};
Expand Down
3 changes: 2 additions & 1 deletion packages/renderer/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { Provider } from "react-redux";
import store from "./store";
import dayjs from "dayjs";
import "dayjs/locale/zh-cn";
import { tdApp } from "./utils";
import { tdApp, initClarity } from "./utils";
import App from "./App";

dayjs.locale("zh-cn");
tdApp.init();
initClarity();

createRoot(document.getElementById("root") as HTMLElement).render(
<StrictMode>
Expand Down
4 changes: 0 additions & 4 deletions packages/renderer/src/nodes/HomePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
} from "@ant-design/icons";
import { useSelector } from "react-redux";
import { selectAppStore } from "../../store";
import { tdApp } from "../../utils";
import DownloadFrom from "../../components/DownloadForm";
import dayjs from "dayjs";
import classNames from "classnames";
Expand Down Expand Up @@ -96,12 +95,10 @@ const HomePage: FC<Props> = ({ filter = DownloadFilter.list }) => {
};

const onDownloadSuccess = () => {
tdApp.downloadSuccess();
refresh();
};

const onDownloadFailed = () => {
tdApp.downloadFailed();
refresh();
};

Expand Down Expand Up @@ -156,7 +153,6 @@ const HomePage: FC<Props> = ({ filter = DownloadFilter.list }) => {
}, []);

const onStartDownload = async (id: number) => {
tdApp.startDownload();
await startDownload(id);
messageApi.success("添加任务成功");
refresh();
Expand Down
14 changes: 14 additions & 0 deletions packages/renderer/src/utils/clarity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* eslint-disable */
// @ts-nocheck
// prettier-ignore
export function initClarity() {
try {
(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
})(window, document, "clarity", "script", import.meta.env.APP_CLARITY_APPID);
} catch (e) {
// empty
}
}
1 change: 1 addition & 0 deletions packages/renderer/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { isUrl } from "./url";

export { http } from "./http";
export { tdApp } from "./tdapp";
export { initClarity } from "./clarity";

export const requestImage = (url: string, timeout = 1000): Promise<void> => {
return new Promise((resolve, reject) => {
Expand Down
8 changes: 2 additions & 6 deletions packages/renderer/src/utils/tdapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,18 @@ class TDEvent {
init() {
const script = document.createElement("script");
script.src = `https://jic.talkingdata.com/app/h5/v1?appid=${this.appId}&vn=${this.vn}&vc=${this.vc}`;
script.async = true;
const headElement = document.getElementsByTagName("head")[0];
headElement.appendChild(script);
}

onEvent(eventId: string, mapKv: Record<string, string> = {}) {
private onEvent(eventId: string, mapKv: Record<string, string> = {}) {
try {
window.TDAPP?.onEvent(eventId, "", mapKv);
} catch (e) {
// empty
}
}

downloadFailed = () => this.onEvent("下载页面-下载视频失败");
downloadSuccess = () => this.onEvent("下载页面-下载视频成功");
openHelpPage = () => this.onEvent("下载页面-打开使用帮助");
startDownload = () => this.onEvent("资源下载-下载按钮");
}

const tdApp = new TDEvent();
Expand Down
3 changes: 2 additions & 1 deletion packages/renderer/src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ declare global {
onEvent: (
eventId: string,
label: "",
mapKv: Record<string, string>
mapKv: Record<string, string>,
) => void;
};
clarity?: any;
}
}

Expand Down

0 comments on commit 3ce5c9d

Please sign in to comment.