feat: use td app

pull/186/head
caorushizi 7 months ago
parent deef1182e3
commit 59d4056620

@ -1,6 +1,4 @@
APP_TD_APPID=
APP_CLARITY_APPID=
APP_APLUS_APPID=
GH_TOKEN=
LOAD_DEVTOOLS=

@ -1,6 +1,4 @@
APP_TD_APPID=
APP_CLARITY_APPID=
APP_APLUS_APPID=
GH_TOKEN=
DEBUG_PLUGINS=false

@ -9,6 +9,8 @@ import "./App.scss";
import useElectron from "./hooks/electron";
import Loading from "./components/Loading";
import { DownloadFilter } from "./types";
import { tdApp } from "./utils";
import { useAsyncEffect } from "ahooks";
const AppLayout = lazy(() => import("./layout/App"));
const HomePage = lazy(() => import("./pages/HomePage"));
@ -23,7 +25,7 @@ function getAlgorithm(appTheme: "dark" | "light") {
const App: FC = () => {
const dispatch = useDispatch();
const [appTheme, setAppTheme] = React.useState<"dark" | "light">("light");
const { addIpcListener, removeIpcListener } = useElectron();
const { addIpcListener, removeIpcListener, getMachineId } = useElectron();
const themeChange = (event: MediaQueryListEvent) => {
if (event.matches) {
@ -52,6 +54,11 @@ const App: FC = () => {
};
}, []);
useAsyncEffect(async () => {
const deviceId = await getMachineId();
tdApp.onEvent("页面加载", { deviceId });
}, []);
useEffect(() => {
const isDarkTheme = matchMedia("(prefers-color-scheme: dark)");
isDarkTheme.addEventListener("change", themeChange);

@ -5,13 +5,12 @@ import { Provider } from "react-redux";
import store from "./store";
import dayjs from "dayjs";
import "dayjs/locale/zh-cn";
import { tdApp, apApp } from "./utils";
import { tdApp } from "./utils";
import App from "./App";
import "./i18n";
dayjs.locale("zh-cn");
tdApp.init();
apApp.init();
createRoot(document.getElementById("root") as HTMLElement).render(
<StrictMode>

@ -19,7 +19,7 @@ import { selectAppStore } from "../../store";
import DownloadForm, { DownloadItemForm } from "../../components/DownloadForm";
import { Trans, useTranslation } from "react-i18next";
import Terminal from "../../components/Terminal";
import { apApp, moment } from "../../utils";
import { moment } from "../../utils";
import { produce } from "immer";
const { Text } = Typography;
@ -209,10 +209,7 @@ const HomePage: FC<Props> = ({ filter = DownloadFilter.list }) => {
key="download"
icon={<DownloadOutlined />}
title={t("download")}
onClick={() => {
apApp.record("startDownload");
onStartDownload(item.id);
}}
onClick={() => onStartDownload(item.id)}
/>,
];
}

@ -1,67 +0,0 @@
class APApp {
async init() {
try {
const id = (await window.electron.getMachineId()) as any;
if (id.code !== 0) return;
window.aplus_queue = window.aplus_queue || [];
const script = document.getElementsByTagName("script")[0];
const ap = document.createElement("script");
ap.async = true;
ap.id = "beacon-aplus";
ap.src = "https://d.alicdn.com/alilog/mlog/aplus/203467608.js";
script.parentNode.insertBefore(ap, script);
window.aplus_queue.push({
action: "aplus.setMetaInfo",
arguments: ["appKey", import.meta.env.APP_APLUS_APPID],
});
window.aplus_queue.push({
action: "aplus.setMetaInfo",
arguments: ["aplus-waiting", "MAN"],
});
window.aplus_queue.push({
action: "aplus.setMetaInfo",
arguments: ["DEBUG", import.meta.env.MODE === "development"],
});
window.aplus_queue.push({
action: "aplus.setMetaInfo",
arguments: ["aplus-idtype", "uuid"],
});
window.aplus_queue.push({
action: "aplus.setMetaInfo",
arguments: ["uuid", id.data],
});
} catch (e) {
// empty
}
}
sendPV() {
try {
const { aplus_queue } = window;
aplus_queue.push({
action: "aplus.sendPV",
arguments: [{ is_auto: false }], // 此处上报的数据暂时在后台没有展示
});
} catch (e) {
// empty
}
}
record(event: string, params: Record<string, string> = {}) {
try {
const { aplus_queue } = window;
aplus_queue.push({
action: "aplus.record",
arguments: [event, "CLK", params],
});
} catch (e) {
// empty
}
}
}
const apApp = new APApp();
export { apApp };

@ -3,7 +3,6 @@ import { isUrl } from "./url";
export { http } from "./http";
export { tdApp } from "./tdapp";
export { apApp } from "./aplus";
export const requestImage = (url: string, timeout = 1000): Promise<void> => {
return new Promise((resolve, reject) => {

@ -17,7 +17,7 @@ class TDEvent {
headElement.appendChild(script);
}
private onEvent(eventId: string, mapKv: Record<string, string> = {}) {
onEvent(eventId: string, mapKv: Record<string, string> = {}) {
try {
window.TDAPP?.onEvent(eventId, "", mapKv);
} catch (e) {

@ -11,8 +11,6 @@ declare global {
mapKv: Record<string, string>
) => void;
};
clarity?: any;
aplus_queue?: any[];
}
}

Loading…
Cancel
Save