Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrated clipboard text function #2134

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed .github/CODEOWNERS
Empty file.
5 changes: 0 additions & 5 deletions app/main/handlers/listenPort.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ module.exports = (win, getClient) => {
streams[addr] = stream;
})


ipcMain.handle("copy-clipboard", (e, text) => {
clipboard.writeText(text);
});

const asyncGetReverseShellProgramList = (params) => {
return new Promise((resolve, reject) => {
getClient().GetReverseShellProgramList(params, (err, data) => {
Expand Down
9 changes: 0 additions & 9 deletions app/main/uiOperate/other.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ module.exports = (win, getClient) => {
if (flag) shell.openExternal(url)
})

// 将渲染进程传入内容复制进系统剪切板内
ipcMain.handle("set-copy-clipboard", (e, text) => {
clipboard.writeText(text)
})
/** 将剪贴板中的内容传递进渲染进程 */
ipcMain.handle("get-copy-clipboard", (e, text) => {
return clipboard.readText()
})

// 将绝对路径里的文件名(不带文件后缀)提取出来
ipcMain.handle("fetch-path-file-name", (e, path) => {
const extension = Path.extname(path)
Expand Down
5 changes: 5 additions & 0 deletions app/main/utils/clipboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ module.exports = (win, getClient) => {
return {size: image.getSize(), blob: image.toDataURL()}
})

// 设置剪切板文本信息
ipcMain.handle("set-clipboard-text", (e, text) => {
clipboard.writeText(text)
return
})
// 获取剪切板文本信息
ipcMain.handle("get-clipboard-text", (e) => {
return clipboard.readText()
Expand Down
12 changes: 7 additions & 5 deletions app/renderer/src/main/src/components/CVXterm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {XTerm} from "xterm-for-react"
import ReactResizeDetector from "react-resize-detector"
import {xtermFit} from "../utils/xtermUtils"
import {TERMINAL_INPUT_KEY} from "./yakitUI/YakitCVXterm/YakitCVXterm"

const {ipcRenderer} = window.require("electron")
import {setClipboardText} from "@/utils/clipboard"

export interface CVXtermProps extends IProps {
isWrite?: boolean
Expand Down Expand Up @@ -92,9 +91,12 @@ export const CVXterm = forwardRef((props: CVXtermProps, ref) => {
timer.current = null
}
timer.current = setTimeout(() => {
ipcRenderer.invoke("copy-clipboard", str).finally(() => {
timer.current = null
setLoading(false)
setClipboardText(str, {
hiddenHint: true,
finalCallback: () => {
timer.current = null
setLoading(false)
}
})
}, 300)
}
Expand Down
9 changes: 3 additions & 6 deletions app/renderer/src/main/src/components/HTTPFlowDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useEffect, useState, useMemo, useRef, ReactNode, ReactElement, useImperativeHandle} from "react"
import {Button, Card, Col, Descriptions, Empty, PageHeader, Row, Space, Spin, Tag, Tooltip, Typography} from "antd"
import React, {useEffect, useState, useMemo, useRef, ReactNode, ReactElement} from "react"
import {Button, Card, Col, Descriptions, Empty, PageHeader, Row, Space, Tag, Tooltip, Typography} from "antd"
import {LeftOutlined, RightOutlined} from "@ant-design/icons"
import {HTTPFlow} from "./HTTPFlowTable/HTTPFlowTable"
import {IMonacoEditor, NewHTTPPacketEditor, RenderTypeOptionVal} from "../utils/editors"
Expand All @@ -8,17 +8,14 @@ import {FuzzableParamList} from "./FuzzableParamList"
import {FuzzerResponse} from "../pages/fuzzer/HTTPFuzzerPage"
import {HTTPHistorySourcePageType, HTTPPacketFuzzable} from "./HTTPHistory"
import {Buffer} from "buffer"
import {StringToUint8Array, Uint8ArrayToString} from "@/utils/str"
import {Uint8ArrayToString} from "@/utils/str"
import {HTTPFlowForWebsocketViewer, WebSocketEditor} from "@/pages/websocket/HTTPFlowForWebsocketViewer"
import {WebsocketFrameHistory} from "@/pages/websocket/WebsocketFrameHistory"

import styles from "./hTTPFlowDetail.module.scss"
import {callCopyToClipboard} from "@/utils/basic"
import {useDebounceEffect, useMemoizedFn, useUpdateEffect} from "ahooks"
import {HTTPFlowExtractedData, HTTPFlowExtractedDataTable} from "@/components/HTTPFlowExtractedDataTable"
import {showResponseViaResponseRaw} from "@/components/ShowInBrowser"
import {ChevronDownIcon, ChevronUpIcon, ChromeSvgIcon, SideBarCloseIcon, SideBarOpenIcon} from "@/assets/newIcon"
import {OtherMenuListProps} from "./yakitUI/YakitEditor/YakitEditorType"
import {YakitEmpty} from "./yakitUI/YakitEmpty/YakitEmpty"
import classNames from "classnames"
import {getRemoteValue, setRemoteValue} from "@/utils/kv"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {ReactNode, Ref, useEffect, useMemo, useRef, useState} from "react"
import {Button, Divider, Empty, Form, Input, Select, Space, Tooltip, Badge} from "antd"
import {Button, Divider, Empty, Form, Input, Space, Tooltip, Badge} from "antd"
import {YakQueryHTTPFlowRequest} from "../../utils/yakQueryHTTPFlow"
import {showDrawer} from "../../utils/showModal"
import {PaginationSchema, YakScript} from "../../pages/invoker/schema"
Expand All @@ -11,7 +11,6 @@ import {formatTime, formatTimestamp} from "../../utils/timeUtil"
import {useHotkeys} from "react-hotkeys-hook"
import {useDebounceEffect, useDebounceFn, useGetState, useMemoizedFn, useUpdateEffect, useVirtualList} from "ahooks"
import ReactResizeDetector from "react-resize-detector"
import {callCopyToClipboard} from "../../utils/basic"
import {
generateCSRFPocByRequest,
generateYakCodeByRequest,
Expand Down Expand Up @@ -73,16 +72,11 @@ import {IconSolidAIIcon, IconSolidAIWhiteIcon} from "@/assets/icon/colors"
import {YakitRoute} from "@/enums/yakitRoute"
import {PluginSwitchToTag} from "@/pages/pluginEditor/defaultconstants"
import {Uint8ArrayToString} from "@/utils/str"
import {WEB_FUZZ_PROXY} from "@/defaultConstants/HTTPFuzzerPage"
import {onSetRemoteValuesBase} from "../yakitUI/utils"
import {CacheDropDownGV} from "@/yakitGV"
import {newWebsocketFuzzerTab} from "@/pages/websocket/WebsocketFuzzer"
import cloneDeep from "lodash/cloneDeep"
import {parseStatusCodes} from "@/pages/fuzzer/components/HTTPFuzzerPageTable/HTTPFuzzerPageTable"
import {setClipboardText} from "@/utils/clipboard"
const {ipcRenderer} = window.require("electron")

const {Option} = Select

export interface codecHistoryPluginProps {
key: string
label: string
Expand Down Expand Up @@ -2721,14 +2715,14 @@ export const HTTPFlowTable = React.memo<HTTPFlowTableProp>((props) => {
webSocket: true,
default: true,
toWebFuzzer: true,
onClickSingle: (v) => callCopyToClipboard(v.Url),
onClickSingle: (v) => setClipboardText(v.Url),
onClickBatch: (v, number) => {
if (v.length === 0) {
yakitNotify("warning", "请选择数据")
return
}
if (v.length < number) {
callCopyToClipboard(v.map((ele) => `${ele.Url}`).join("\r\n"))
setClipboardText(v.map((ele) => `${ele.Url}`).join("\r\n"))
setSelectedRowKeys([])
setSelectedRows([])
} else {
Expand Down Expand Up @@ -2778,7 +2772,7 @@ export const HTTPFlowTable = React.memo<HTTPFlowTableProp>((props) => {
const flow = v as HTTPFlow
if (!flow) return
generateCSRFPocByRequest(flow.Request, flow.IsHTTPS, (e) => {
callCopyToClipboard(e)
setClipboardText(e)
})
}
},
Expand Down Expand Up @@ -3129,7 +3123,7 @@ export const HTTPFlowTable = React.memo<HTTPFlowTableProp>((props) => {
flow.IsHTTPS,
flow.Request,
(code) => {
callCopyToClipboard(code)
setClipboardText(code)
},
RequestToYakCodeTemplate.Ordinary
)
Expand All @@ -3144,7 +3138,7 @@ export const HTTPFlowTable = React.memo<HTTPFlowTableProp>((props) => {
flow.IsHTTPS,
flow.Request,
(code) => {
callCopyToClipboard(code)
setClipboardText(code)
},
RequestToYakCodeTemplate.Batch
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {WindowPositionType} from "../yakitUI/YakitWindow/YakitWindowType"
import {YakitButton} from "../yakitUI/YakitButton/YakitButton"
import {OutlineXIcon} from "@/assets/icon/outline"
import emiter from "@/utils/eventBus/eventBus"
import {setClipboardText} from "@/utils/clipboard"

const {ipcRenderer} = window.require("electron")

Expand Down Expand Up @@ -118,7 +119,7 @@ export const EngineConsole: React.FC<EngineConsoleProp> = (props) => {

const setCopy = useDebounceFn(
useMemoizedFn((content: string) => {
ipcRenderer.invoke("set-copy-clipboard", content)
setClipboardText(content)
}),
{wait: 10}
).run
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {OutlineQuestionmarkcircleIcon} from "@/assets/icon/outline"
import {grpcFetchLatestYakVersion} from "@/apiUtils/grpc"
import emiter from "@/utils/eventBus/eventBus"
import {WebsiteGV} from "@/enums/website"
import {setClipboardText} from "@/utils/clipboard"

import classNames from "classnames"
import styles from "./InstallEngine.module.scss"
Expand Down Expand Up @@ -651,8 +652,7 @@ export const QuestionModal: React.FC<AgrAndQSModalProps> = React.memo((props) =>
link = `https://${WebsiteGV.OSSSourceAddress}/yak/${latestVersion || "latest"}/yak_windows_amd64.exe`
break
}
ipcRenderer.invoke("set-copy-clipboard", link)
success("复制成功")
setClipboardText(link)
})

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import {forwardRef, useEffect, useImperativeHandle, useRef, useState} from "react"
import {forwardRef, useImperativeHandle, useRef, useState} from "react"
import {IProps} from "xterm-for-react/dist/src/XTerm"
import {XTerm} from "xterm-for-react"
import ReactResizeDetector from "react-resize-detector"
import {xtermFit} from "@/utils/xtermUtils"
import styles from "./YakitCVXterm.module.scss"
import {Terminal as ITerminal} from "xterm"

const {ipcRenderer} = window.require("electron")
import {setClipboardText} from "@/utils/clipboard"

export interface CVXtermProps extends IProps {
isWrite?: boolean
Expand Down Expand Up @@ -105,9 +102,11 @@ export const YakitCVXterm = forwardRef((props: CVXtermProps, ref) => {
timer.current = null
}
timer.current = setTimeout(() => {
ipcRenderer.invoke("copy-clipboard", str).finally(() => {
timer.current = null
setLoading(false)
setClipboardText(str, {
finalCallback: () => {
timer.current = null
setLoading(false)
}
})
}, 300)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ import {AutoCard} from "../../AutoCard"
import {YakitEditor} from "./YakitEditor"
import {YakitButton} from "../YakitButton/YakitButton"
import {monacoEditorClear, monacoEditorWrite} from "@/pages/fuzzer/fuzzerTemplates"
import {failed, yakitNotify} from "@/utils/notification"
import {failed} from "@/utils/notification"
import {fetchCursorContent, fetchSelectionRange} from "./editorUtils"
import {useEffect, useRef, useState} from "react"
import {AutoSpin} from "@/components/AutoSpin"
import {YakitSpin} from "../YakitSpin/YakitSpin"
import {showYakitModal} from "../YakitModal/YakitModalConfirm"
import emiter from "@/utils/eventBus/eventBus"
import {IconSolidAIIcon, IconSolidAIWhiteIcon} from "@/assets/icon/colors"
import {CodecResponseProps, CodecWorkProps} from "@/pages/codec/NewCodec"
import {getClipboardText, setClipboardText} from "@/utils/clipboard"

const {ipcRenderer} = window.require("electron")

Expand Down Expand Up @@ -52,7 +49,7 @@ export const baseMenuLists: OtherMenuListProps = {
}
])
if (flag) {
ipcRenderer.invoke("set-copy-clipboard", `${content}`)
setClipboardText(`${content}`)
editor.focus()
}
}
Expand All @@ -62,7 +59,7 @@ export const baseMenuLists: OtherMenuListProps = {
copy: {
menu: [{key: "copy", label: "复制"}],
onRun: (editor: YakitIMonacoEditor, key: string) => {
if (editor) ipcRenderer.invoke("set-copy-clipboard", `${fetchCursorContent(editor, true)}`)
if (editor) setClipboardText(`${fetchCursorContent(editor, true)}`)
return
}
},
Expand All @@ -75,8 +72,7 @@ export const baseMenuLists: OtherMenuListProps = {
const position = fetchSelectionRange(editor, false)
if (!position) return

ipcRenderer
.invoke("get-copy-clipboard")
getClipboardText()
.then((str: string) => {
if (editor?.executeEdits) {
editor.executeEdits("", [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {failed, info, yakitNotify} from "@/utils/notification"
import {ShareValueProps, newWebFuzzerTab} from "@/pages/fuzzer/HTTPFuzzerPage"
import {generateCSRFPocByRequest} from "@/pages/invoker/fromPacketToYakCode"
import {StringToUint8Array} from "@/utils/str"
import {callCopyToClipboard} from "@/utils/basic"
import {showResponseViaResponseRaw} from "@/components/ShowInBrowser"
import {openExternalWebsite, saveABSFileToOpen} from "@/utils/openWebsite"
import {Modal} from "antd"
Expand All @@ -26,7 +25,7 @@ import {newWebsocketFuzzerTab} from "@/pages/websocket/WebsocketFuzzer"
import {getRemoteValue} from "@/utils/kv"
import {RemoteGV} from "@/yakitGV"
import {HTTPFlowBodyByIdRequest} from "@/components/HTTPHistory"
import emiter from "@/utils/eventBus/eventBus"
import {setClipboardText} from "@/utils/clipboard"
const {ipcRenderer} = window.require("electron")

interface HTTPPacketYakitEditor extends Omit<YakitEditorProps, "menuType"> {
Expand Down Expand Up @@ -109,7 +108,7 @@ export const HTTPPacketYakitEditor: React.FC<HTTPPacketYakitEditor> = React.memo
if (onClickUrlMenu) {
onClickUrlMenu()
} else {
callCopyToClipboard(url || "")
setClipboardText(url || "")
}
}
},
Expand All @@ -128,7 +127,7 @@ export const HTTPPacketYakitEditor: React.FC<HTTPPacketYakitEditor> = React.memo
return
}
generateCSRFPocByRequest(StringToUint8Array(text, "utf8"), defaultHttps, (code) => {
callCopyToClipboard(code)
setClipboardText(code)
})
} catch (e) {
failed("自动生成 CSRF 失败")
Expand Down Expand Up @@ -344,7 +343,7 @@ export const HTTPPacketYakitEditor: React.FC<HTTPPacketYakitEditor> = React.memo
Bytes: bytes.Raw
})
.then((res: {Base64: string}) => {
callCopyToClipboard(res.Base64)
setClipboardText(res.Base64)
})
.catch((err) => {
yakitNotify("error", `${err}`)
Expand Down
23 changes: 14 additions & 9 deletions app/renderer/src/main/src/components/yakitUI/YakitTag/YakitTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {useMemoizedFn} from "ahooks"
import {CheckOutlined, LoadingOutlined} from "@ant-design/icons"
import {success} from "@/utils/notification"
import {OutlineXIcon} from "@/assets/icon/outline"
import {setClipboardText} from "@/utils/clipboard"

const {ipcRenderer} = window.require("electron")

Expand Down Expand Up @@ -79,15 +80,19 @@ export const CopyComponents: React.FC<CopyComponentsProps> = (props) => {
e.stopPropagation()
if (!props.copyText) return
setLoading(true)
ipcRenderer.invoke("set-copy-clipboard", props.copyText)
setTimeout(() => {
setLoading(false)
setIsShowSure(true)
setTimeout(() => {
setIsShowSure(false)
}, 2000)
success("复制成功")
}, 1000)
setClipboardText(props.copyText, {
hiddenHint: true,
finalCallback: () => {
setTimeout(() => {
setLoading(false)
setIsShowSure(true)
setTimeout(() => {
setIsShowSure(false)
}, 2000)
success("复制成功")
}, 1000)
}
})
if (props.onAfterCopy) props.onAfterCopy(e)
})
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import styles from "./YakitXterm.module.scss"
import classNames from "classnames"
import {useMemoizedFn, useThrottleFn} from "ahooks"
import {warn} from "@/utils/notification"
import {callCopyToClipboard, getCallCopyToClipboard} from "@/utils/basic"
import {YakitMenuItemType} from "../YakitMenu/YakitMenu"
import {showByRightContext} from "../YakitMenu/showByRightContext"
import useListenWidth from "@/pages/pluginHub/hooks/useListenWidth"
import {System, SystemInfo, handleFetchSystem} from "@/constants/hardware"
import {getClipboardText, setClipboardText} from "@/utils/clipboard"

export interface YakitXtermRefProps {
terminal: Terminal
Expand Down Expand Up @@ -306,7 +306,12 @@ const YakitXterm: React.FC<IProps> = forwardRef((props, ref) => {
return
}
loading.current = true
callCopyToClipboard(selectedText, false).finally(() => (loading.current = false))
setClipboardText(selectedText, {
hiddenHint: true,
finalCallback: () => {
loading.current = false
}
})
}),
{wait: 200}
).run
Expand All @@ -315,7 +320,7 @@ const YakitXterm: React.FC<IProps> = forwardRef((props, ref) => {
useMemoizedFn(() => {
if (isWrite) {
loading.current = true
getCallCopyToClipboard()
getClipboardText()
.then((str: string) => {
if (terminalRef.current) {
terminalRef.current.paste(str)
Expand Down
Loading