Skip to content

Let's use AI to Earn!

fix: 修复了渲染成监听主进程事件内存泄露的问题,修复了UserSelect组件报错的问题

gaoSir3af6fa2d0daf
diff --git a/src/icp/receiveMsg.ts b/src/icp/receiveMsg.ts
index 968f724e..c1e26806 100644
--- a/src/icp/receiveMsg.ts
+++ b/src/icp/receiveMsg.ts
@@ -1,10 +1,29 @@
// 接收主进程发来的消息
import { SendChannelEnum } from '../../commont/UtilsEnum';
import { VideoPublishProgressRes } from '../../electron/main/plat/pub/PubItemVideo';
+import IpcRendererEvent = Electron.IpcRendererEvent;
+
+// 绑定事件中间层方法
+const bindEventCore = (
+ channel: SendChannelEnum,
+ listener: (event: IpcRendererEvent, ...args: any[]) => void,
+): (() => void) => {
+ const e = window.ipcRenderer.on(channel, listener);
+ // @ts-ignore
+ const events: any[] = e._events[channel];
+ if (!events) return () => {};
+ const f = events[events.length === 0 ? 0 : events.length - 1];
+
+ return () => {
+ if (f) {
+ window.ipcRenderer.off(channel, f);
+ }
+ };
+};
// 账户登录完成
export const onAccountLoginFinish = (callback: () => void) => {
- window.ipcRenderer.on(SendChannelEnum.AccountLoginFinish, () => {
+ return bindEventCore(SendChannelEnum.AccountLoginFinish, () => {
callback();
});
};
@@ -13,9 +32,9 @@ export const onAccountLoginFinish = (callback: () => void) => {
export const onVideoPublishProgress = (
callback: (progressData: VideoPublishProgressRes) => void,
) => {
- window.ipcRenderer.on(
+ return bindEventCore(
SendChannelEnum.VideoPublishProgress,
- (_event, progressData) => {
+ (_, progressData) => {
callback(progressData);
},
);
diff --git a/src/views/account/components/AccountSidebar.tsx b/src/views/account/components/AccountSidebar.tsx
index d6146fbc..b61c9616 100644
--- a/src/views/account/components/AccountSidebar.tsx
+++ b/src/views/account/components/AccountSidebar.tsx
@@ -121,7 +121,7 @@ const AccountSidebar = memo(
useEffect(() => {
getAccountList();
- onAccountLoginFinish(() => {
+ return onAccountLoginFinish(() => {
getAccountList();
});
}, []);
diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/VideoPubSetModal.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/VideoPubSetModal.tsx
index 148a6319..c3ceaf7c 100644
--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/VideoPubSetModal.tsx
+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/VideoPubSetModal.tsx
@@ -102,7 +102,7 @@ const VideoPubSetModal = memo(
useEffect(() => {
// 发布进度监听
- onVideoPublishProgress((progressData) => {
+ return onVideoPublishProgress((progressData) => {
setPubProgressMap((prev) => {
const newMap = new Map(prev);
newMap.set(progressData.account.id!, progressData);
diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_DouYin.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_DouYin.tsx
index 4672c974..98be6960 100644
--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_DouYin.tsx
+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_DouYin.tsx
@@ -146,7 +146,7 @@ const ActivitySelect = ({ currChooseAccount }: IVideoPubSetModalChildProps) => {
useEffect(() => {
init();
- onAccountLoginFinish(() => {
+ return onAccountLoginFinish(() => {
init();
});
}, []);
diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_KWAI.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_KWAI.tsx
index 4de858ab..d7a5e1b6 100644
--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_KWAI.tsx
+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/children/VideoPubSetModal_KWAI.tsx
@@ -57,7 +57,7 @@ const VideoPubSetModal_KWAI = memo(
maxCount={3}
title="@好友"
tips="您可以添加3个好友"
- isSearch={false}
+ showSearch={false}
/>
<LocationSelect currChooseAccount={currChooseAccount} />
diff --git a/src/views/publish/children/videoPage/components/VideoPubSetModal/components/UserSelect.tsx b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/UserSelect.tsx
index 73126078..2ab81b62 100644
--- a/src/views/publish/children/videoPage/components/VideoPubSetModal/components/UserSelect.tsx
+++ b/src/views/publish/children/videoPage/components/VideoPubSetModal/components/UserSelect.tsx
@@ -19,8 +19,6 @@ interface DebounceSelectProps<ValueType = any>
currChooseAccount: IVideoChooseItem;
tips?: string;
title: string;
- // 是否需要搜索,默认需要
- isSearch?: boolean;
}
// 话题选择器
@@ -60,7 +58,7 @@ export default function UserSelect({
};
useEffect(() => {
- if (props.isSearch === false) {
+ if (props.showSearch === false) {
getList().then((res) => {
setOptions(res);
});
@@ -77,7 +75,10 @@ export default function UserSelect({
<>
<h1>{props.title}</h1>
<Select
- showSearch={props.hasOwnProperty('isSearch') ? props.isSearch : true}
+ {...props}
+ showSearch={
+ props.hasOwnProperty('showSearch') ? props.showSearch : true
+ }
allowClear
style={{ width: '100%' }}
mode="multiple"
@@ -85,7 +86,7 @@ export default function UserSelect({
labelInValue
filterOption={false}
onSearch={
- (props.hasOwnProperty('isSearch') ? props.isSearch : true)
+ (props.hasOwnProperty('showSearch') ? props.showSearch : true)
? debounceFetcher
: undefined
}
@@ -94,7 +95,6 @@ export default function UserSelect({
label: 'name',
value: 'id',
}}
- {...props}
options={options}
optionRender={({ data }) => {
return (
diff --git a/src/views/publish/components/ChooseAccountModule/components/PlatChoose.tsx b/src/views/publish/components/ChooseAccountModule/components/PlatChoose.tsx
index 29eeac0d..6090857e 100644
--- a/src/views/publish/components/ChooseAccountModule/components/PlatChoose.tsx
+++ b/src/views/publish/components/ChooseAccountModule/components/PlatChoose.tsx
@@ -112,7 +112,7 @@ const PlatChoose = memo(
useEffect(() => {
getAccountList();
- onAccountLoginFinish(() => {
+ const revmoeListener = onAccountLoginFinish(() => {
getAccountList();
});
@@ -120,6 +120,7 @@ const PlatChoose = memo(
setAccountMap(new Map());
setChoosedAcountMap(new Map());
init();
+ revmoeListener();
};
}, []);