Skip to content

Commit

Permalink
Merge pull request #2283 from yaklang/song/feat/engineVersionDown
Browse files Browse the repository at this point in the history
Song/feat/engine version down
  • Loading branch information
youngster-yj authored Jan 10, 2025
2 parents 9ba90ab + 616ab6b commit ce2791f
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.check-engine-version-checkbox {
height: 100%;
display: flex;
align-items: center;
}
height: 100%;
display: flex;
align-items: center;
}
64 changes: 51 additions & 13 deletions app/renderer/src/main/src/components/layout/FuncDomain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import {randomString} from "@/utils/randomUtil"
import {ExpandAndRetractExcessiveState} from "@/pages/plugins/operator/expandAndRetract/ExpandAndRetract"
import {YakitSpin} from "../yakitUI/YakitSpin/YakitSpin"
import {PluginExecuteResult} from "@/pages/plugins/operator/pluginExecuteResult/PluginExecuteResult"
import {YakitHint} from "../yakitUI/YakitHint/YakitHint"

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

Expand Down Expand Up @@ -1193,21 +1194,22 @@ interface UIOpUpdateProps {
updateContent?: string
onDownload: (type: "yakit" | "yaklang") => any
onUpdateEdit?: (type: "yakit" | "yaklang") => any
isUpdate: boolean

/** yakit属性 */
isUpdateWait?: boolean // 是否已下载未安装

/** yaklang属性 */
localVersion?: string // 本地引擎文件版本
moreYaklangVersionList?: string[] // 更多引擎版本列表
lowerYaklangLastVersion?: boolean // 引擎是否有更新
isRemoteMode?: boolean // 是否为远程模式
onNoticeShow?: (visible: boolean) => void
isUpdateYakit?: boolean // 下载引擎之前判断yakit是否需要先更新
}

/** @name Yakit版本以及更新内容 */
const UIOpUpdateYakit: React.FC<UIOpUpdateProps> = React.memo((props) => {
const {version, lastVersion, isUpdateWait, onDownload, role, updateContent = "", onUpdateEdit} = props
const {version, lastVersion, isUpdate, isUpdateWait, onDownload, role, updateContent = "", onUpdateEdit} = props

// 是否可编辑
const isShowModify = useMemo(() => {
Expand All @@ -1216,8 +1218,6 @@ const UIOpUpdateYakit: React.FC<UIOpUpdateProps> = React.memo((props) => {
return false
}, [role])

const isUpdate = lastVersion !== "" && removePrefixV(lastVersion) !== removePrefixV(version)

const content: string[] = useMemo(() => {
if (updateContent) {
const strs = updateContent.split("\n")
Expand Down Expand Up @@ -1305,21 +1305,18 @@ const UIOpUpdateYaklang: React.FC<UIOpUpdateProps> = React.memo((props) => {
lastVersion,
localVersion = "",
moreYaklangVersionList = [],
lowerYaklangLastVersion = false,
isRemoteMode = false,
onDownload,
role,
updateContent = "",
onUpdateEdit,
onNoticeShow = () => {}
onNoticeShow = () => {},
isUpdate,
isUpdateYakit
} = props

const [updateHint, setUpdateHint] = useState<boolean>(false)
const [moreVersionPopShow, setMoreVersionPopShow] = useState<boolean>(false)

/** 是否存在更新 */
const isUpdate = useMemo(() => {
return lowerYaklangLastVersion
}, [lowerYaklangLastVersion])
/** 判断连接引擎版本和本地引擎文件版本是否相同,不同提示是否重新启动引擎 */
const isKillEngine = useMemo(() => {
return (
Expand Down Expand Up @@ -1404,11 +1401,47 @@ const UIOpUpdateYaklang: React.FC<UIOpUpdateProps> = React.memo((props) => {
<div className={styles["more-version-btn"]}>更多版本</div>
</YakitPopover>
{isUpdate && (
<div className={styles["update-btn"]} onClick={() => onDownload("yaklang")}>
<div
className={styles["update-btn"]}
onClick={() => {
if (isUpdateYakit) {
onNoticeShow(false)
setUpdateHint(true)
} else {
onDownload("yaklang")
}
}}
>
<UpdateSvgIcon style={{marginRight: 4}} />
立即更新
</div>
)}
<YakitHint
visible={updateHint}
title='更新提示'
content='更新Yakit可同步更新引擎,建议先更新Yakit'
okButtonText='更新Yakit'
cancelButtonText='更新引擎'
footerExtra={
<YakitButton
size='max'
type='outline2'
onClick={() => {
setUpdateHint(false)
}}
>
取消
</YakitButton>
}
onOk={() => {
setUpdateHint(false)
onDownload("yakit")
}}
onCancel={() => {
setUpdateHint(false)
onDownload("yaklang")
}}
/>
{isKillEngine && (
<YakitButton
onClick={() => ipcRenderer.invoke("kill-old-engine-process")}
Expand Down Expand Up @@ -1893,6 +1926,9 @@ const UIOpNotice: React.FC<UIOpNoticeProp> = React.memo((props) => {
})

const notice = useMemo(() => {
const isUpdateYakit = yakitLastVersion !== "" && removePrefixV(yakitLastVersion) !== removePrefixV(yakitVersion)
const isUpdateYaklang = lowerYaklangLastVersion

return (
<div className={styles["ui-op-plus-wrapper"]}>
<div className={styles["ui-op-notice-body"]}>
Expand Down Expand Up @@ -1969,19 +2005,21 @@ const UIOpNotice: React.FC<UIOpNoticeProp> = React.memo((props) => {
role={userInfo.role}
updateContent={communityYakit}
onUpdateEdit={UpdateContentEdit}
isUpdate={isUpdateYakit}
/>
<UIOpUpdateYaklang
version={yaklangVersion}
lastVersion={yaklangLastVersion}
localVersion={yaklangLocalVersion}
moreYaklangVersionList={moreYaklangVersionList}
lowerYaklangLastVersion={lowerYaklangLastVersion}
isRemoteMode={isRemoteMode}
onDownload={onDownload}
role={userInfo.role}
updateContent={communityYaklang}
onUpdateEdit={UpdateContentEdit}
onNoticeShow={setShow}
isUpdate={isUpdateYaklang}
isUpdateYakit={isUpdateYakit}
/>
</div>
<div className={styles["history-version"]}>
Expand Down
65 changes: 50 additions & 15 deletions app/renderer/src/main/src/components/layout/UILayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import {grpcFetchLatestYakVersion, grpcFetchYakInstallResult} from "@/apiUtils/g
import {NetWorkApi} from "@/services/fetch"
import {API} from "@/services/swagger/resposeType"
import {visitorsStatisticsFun} from "@/utils/visitorsStatistics"
import { setYakitEngineMode } from "@/constants/software"
import {setYakitEngineMode} from "@/constants/software"

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

Expand Down Expand Up @@ -201,16 +201,17 @@ const UILayout: React.FC<UILayoutProp> = (props) => {
NetWorkApi<any, API.SystemConfigResponse>({
method: "get",
url: "system/config"
}).then((config) => {
const data = config.data || []
setEeSystemConfig([...data])
}).catch(() => {
setEeSystemConfig([])
})
.then((config) => {
const data = config.data || []
setEeSystemConfig([...data])
})
.catch(() => {
setEeSystemConfig([])
})
}
}, [engineLink])


/** ---------- 引擎状态和连接相关逻辑 Start ---------- */
/** 插件漏洞信息库自检 */
const handleBuiltInCheck = useMemoizedFn(() => {
Expand Down Expand Up @@ -799,7 +800,7 @@ const UILayout: React.FC<UILayoutProp> = (props) => {

const [killOldEngine, setKillOldEngine] = useState<boolean>(false)
const [killLoading, setKillLoading] = useState<boolean>(false)
const killOldProcess = useMemoizedFn(() => {
const killOldProcess = useMemoizedFn((callback?: () => void) => {
let isFailed: boolean = false
let port: number = 0
let pid: number = 0
Expand Down Expand Up @@ -850,6 +851,7 @@ const UILayout: React.FC<UILayoutProp> = (props) => {
info(`KILL yak PROCESS: ${pid}`)
setKillOldEngine(false)
setLinkLocalEngine()
callback && callback()
})
.catch((e) => {
failed(`PS | GREP yak failed ${e}`)
Expand Down Expand Up @@ -885,16 +887,39 @@ const UILayout: React.FC<UILayoutProp> = (props) => {
const [builtInVersion, setBuiltInVersion] = useState<string>("")
const [currentVersion, setCurrentVersion] = useState<string>("")

const compareVersions = (version1: string, version2: string) => {
// 用正则表达式将版本号分解成数字部分和beta后面的部分
const parseVersion = (version) => {
const parts = version.split("-") // 分割 beta 部分
const versionNumbers = parts[0].split(".").map((num) => parseInt(num)) // 获取数字部分
const betaPart = parts[1] ? parseInt(parts[1].replace("beta", "")) : null // 如果有beta,提取beta后的数字
return {versionNumbers, betaPart}
}

const v1 = parseVersion(version1)
const v2 = parseVersion(version2)

// 比较数字部分
for (let i = 0; i < Math.min(v1.versionNumbers.length, v2.versionNumbers.length); i++) {
if (v1.versionNumbers[i] > v2.versionNumbers[i]) return 1
if (v1.versionNumbers[i] < v2.versionNumbers[i]) return -1
}

// 如果数字部分相同,比较beta部分
if (v1.betaPart !== null && v2.betaPart !== null) {
if (v1.betaPart > v2.betaPart) return 1
if (v1.betaPart < v2.betaPart) return -1
}

// 如果没有beta部分,或者beta部分相同,则返回0
return 0
}

const showCheckVersion = useMemo(() => {
if (isDev.current) return false
if (!builtInVersion) return false
if (!currentVersion) return false
if (!yakEngineVersionList.length) return false
const index1 = yakEngineVersionList.indexOf(currentVersion)
const index2 = yakEngineVersionList.indexOf(builtInVersion)
if (index1 === -1 || index2 === -1) return false
if (index1 > index2) return true
return false
return compareVersions(currentVersion, builtInVersion) === -1
}, [builtInVersion, currentVersion, yakEngineVersionList])

useEffect(() => {
Expand Down Expand Up @@ -936,7 +961,17 @@ const UILayout: React.FC<UILayoutProp> = (props) => {
const onCheckVersionCancel = useMemoizedFn((flag: boolean) => {
if (flag) {
if (yaklangKillPss) return
emiter.emit("downYaklangSpecifyVersion", JSON.stringify({version: yaklangLastVersionRef.current}))
killOldProcess(() => {
ipcRenderer
.invoke("InitBuildInEngine", {})
.then(() => {
yakitNotify("info", "解压内置引擎成功,即将重启软件")
ipcRenderer.invoke("relaunch")
})
.catch((e) => {
yakitNotify("error", `解压内置引擎失败:${e}`)
})
})
}
setCurrentVersion("")
})
Expand Down

0 comments on commit ce2791f

Please sign in to comment.