Skip to content

Commit

Permalink
fix: 替换完成
Browse files Browse the repository at this point in the history
  • Loading branch information
youngster-yj committed Dec 6, 2023
1 parent 546a513 commit bfc6c29
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
22 changes: 6 additions & 16 deletions app/main/handlers/payloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ module.exports = (win, getClient) => {
let stream = getClient().GetAllPayloadFromFile(params)
handlerHelper.registerHandler(win, stream, streamPayloadFromFileMap, token)
})
const streamAllPayloadMap = new Map()
ipcMain.handle("cancel-GetAllPayload", handlerHelper.cancelHandler(streamAllPayloadMap))
ipcMain.handle("GetAllPayload", async (e, params, token) => {
let stream = getClient().GetAllPayload(params)
handlerHelper.registerHandler(win, stream, streamAllPayloadMap, token)
})

// 用于去重
const streamRemoveDuplicateMap = new Map()
Expand Down Expand Up @@ -256,20 +262,4 @@ module.exports = (win, getClient) => {
ipcMain.handle("UpdatePayloadToFile", async (e, params) => {
return await asyncUpdatePayloadToFile(params)
})

const asyncGetAllPayload = (params) => {
return new Promise((resolve, reject) => {
getClient().GetAllPayload(params, (err, data) => {
if (err) {
reject(err)
return
}
resolve(data)
})
})
}
// 用于导出
ipcMain.handle("GetAllPayload", async (e, params) => {
return await asyncGetAllPayload(params)
})
}
17 changes: 7 additions & 10 deletions app/renderer/src/main/src/pages/payloadManager/newPayload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2934,14 +2934,15 @@ export const ExportByGrpc: React.FC<ExportByGrpcProps> = (props) => {
})
.then((data: any) => {
if (data.filePaths.length) {
let absolutePath = data.filePaths[0].replace(/\\/g, "\\")
exportPathRef.current = absolutePath
let absolutePath:string = data.filePaths[0].replace(/\\/g, "\\")
let currentPath:string = `${absolutePath}\\${group}.${isFile?"txt":'csv'}`
exportPathRef.current = currentPath
ipcRenderer.invoke(
isFile ? "GetAllPayloadFromFile" : "GetAllPayload",
{
Group: group,
Folder: folder,
savePath: absolutePath
savePath: currentPath
},
exportToken
)
Expand All @@ -2953,7 +2954,7 @@ export const ExportByGrpc: React.FC<ExportByGrpcProps> = (props) => {
})
// 取消导出任务
const cancelExportFile = useMemoizedFn(() => {
ipcRenderer.invoke("cancel-GetAllPayloadFromFile", exportToken)
ipcRenderer.invoke(isFile ? "cancel-GetAllPayloadFromFile":"cancel-GetAllPayload", exportToken)
})

const onExportStreamData = useThrottleFn(
Expand Down Expand Up @@ -2982,12 +2983,12 @@ export const ExportByGrpc: React.FC<ExportByGrpcProps> = (props) => {
exportPathRef.current && openABSFileLocated(exportPathRef.current)
})
return () => {
ipcRenderer.invoke("cancel-GetAllPayloadFromFile", exportToken)
ipcRenderer.invoke(isFile ? "cancel-GetAllPayloadFromFile":"cancel-GetAllPayload", exportToken)
ipcRenderer.removeAllListeners(`${exportToken}-data`)
ipcRenderer.removeAllListeners(`${exportToken}-error`)
ipcRenderer.removeAllListeners(`${exportToken}-end`)
}
}, [group])
}, [])
return (
<YakitModal
centered
Expand All @@ -3006,12 +3007,8 @@ export const ExportByGrpc: React.FC<ExportByGrpcProps> = (props) => {
cancelExportFile()
setExportVisible(false)
}}
onClose={() => {
setExportVisible(false)
}}
logInfo={[]}
showDownloadDetail={false}
autoClose={true}
/>
</YakitModal>
)
Expand Down

0 comments on commit bfc6c29

Please sign in to comment.