From dde9b21e7c0ec8f6aa04809dad88bee53d53e071 Mon Sep 17 00:00:00 2001 From: nonight <378099757@qq.com> Date: Fri, 26 Apr 2024 12:51:56 +0800 Subject: [PATCH] feature/some-function (#1602) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 软件绑定引擎版本对比检查提示 * 1、引擎检查版本中,本地和最新版本强制为顺序同步执行,不再同时获取本地和最新版本 2、加入打印信息日志功能,监听启动引擎成功但未进入UI界面问题 3、删除日志文件逻辑调整,删除老文件的同时,也将无信息的文件同时删除 * 修复测试小问题 * 加入命令运行引擎脚本功能 --- app/main/errorCollection.js | 23 ++++- app/main/filePath.js | 3 + app/main/handlers/engineStatus.js | 1 + app/main/handlers/upgradeUtil.js | 49 ++++++++++- app/main/index.js | 11 ++- app/main/ipc.js | 2 +- app/main/toolsFunc.js | 8 +- app/main/uiOperate/hardware.js | 2 +- app/main/uiOperate/yaklangAndYakit.js | 31 +++++-- app/renderer/src/main/src/NewApp.tsx | 5 ++ .../src/components/basics/YakitLoading.tsx | 19 +++- .../basics/yakitLoading.module.scss | 20 +++++ .../CheckEngineVersion.module.scss | 5 ++ .../CheckEngineVersion/CheckEngineVersion.tsx | 65 ++++++++++++++ .../layout/LocalEngine/LocalEngine.tsx | 7 +- .../main/src/components/layout/UILayout.tsx | 83 ++++++++++++++++++ .../components/layout/WelcomeConsoleUtil.tsx | 35 +++++--- .../layout/YaklangEngineWatchDog.tsx | 14 ++- app/renderer/src/main/src/enums/engine.ts | 7 ++ bins/scripts/start-engine.zip | Bin 0 -> 1300 bytes electron-builder.yaml | 2 + 21 files changed, 355 insertions(+), 37 deletions(-) create mode 100644 app/renderer/src/main/src/components/layout/CheckEngineVersion/CheckEngineVersion.module.scss create mode 100644 app/renderer/src/main/src/components/layout/CheckEngineVersion/CheckEngineVersion.tsx create mode 100644 app/renderer/src/main/src/enums/engine.ts create mode 100644 bins/scripts/start-engine.zip diff --git a/app/main/errorCollection.js b/app/main/errorCollection.js index cd57416b51..969bfed2ca 100644 --- a/app/main/errorCollection.js +++ b/app/main/errorCollection.js @@ -1,23 +1,38 @@ const {ipcMain} = require("electron") const fs = require("fs") const path = require("path") -const {renderLog} = require("./filePath") +const {renderLog, printLog} = require("./filePath") const {getNowTime} = require("./toolsFunc") /** 引擎错误日志 */ -const logPath = path.join(renderLog, `render-log-${getNowTime()}.txt`) -let writeStream = fs.createWriteStream(logPath, {flags: "a"}) +const renderLogPath = path.join(renderLog, `render-log-${getNowTime()}.txt`) +let renderWriteStream = fs.createWriteStream(renderLogPath, {flags: "a"}) + +/** 引擎错误日志 */ +const printLogPath = path.join(printLog, `print-log-${getNowTime()}.txt`) +let printWriteStream = fs.createWriteStream(printLogPath, {flags: "a"}) module.exports = (win, getClient) => { /** 渲染端错误信息收集 */ ipcMain.handle("render-error-log", (e, error) => { const content = error || "" if (content) { - writeStream.write(content, (err) => { + renderWriteStream.write(`${content}\n`, (err) => { if (err) { console.error("render-error-log-write-error:", err) } }) } }) + + /** 可疑问题的打印信息收集 */ + ipcMain.handle("print-info-log", (e, info) => { + if (info) { + printWriteStream.write(`${info}\n`, (err) => { + if (err) { + console.error("print-error-log-write-error:", err) + } + }) + } + }) } diff --git a/app/main/filePath.js b/app/main/filePath.js index 070bd8e60a..69d5115f86 100644 --- a/app/main/filePath.js +++ b/app/main/filePath.js @@ -102,6 +102,8 @@ const extraLocalCachePath = path.join(basicDir, "yakit-extra-local.json") const engineLog = path.join(YakitProjectPath, "engine-log") /** 渲染端错误日志 */ const renderLog = path.join(YakitProjectPath, "render-log") +/** 可以问题的打印日志 */ +const printLog = path.join(YakitProjectPath, "print-log") /** 远程连接配置信息储存文件夹 */ const remoteLinkDir = path.join(YakitProjectPath, "auth") @@ -132,6 +134,7 @@ module.exports = { extraLocalCachePath, engineLog, renderLog, + printLog, remoteLinkDir, remoteLinkFile, diff --git a/app/main/handlers/engineStatus.js b/app/main/handlers/engineStatus.js index f9346cd5de..b5a76446be 100644 --- a/app/main/handlers/engineStatus.js +++ b/app/main/handlers/engineStatus.js @@ -90,6 +90,7 @@ module.exports = (win, callback, getClient, newClient) => { try { getClient().Version({}, async (err, data) => { if (win && data.Version) win.webContents.send("fetch-yak-version-callback", data.Version) + else win.webContents.send("fetch-yak-version-callback", "") }) } catch (e) { win.webContents.send("fetch-yak-version-callback", "") diff --git a/app/main/handlers/upgradeUtil.js b/app/main/handlers/upgradeUtil.js index 01b48cab68..6df5b52a9d 100644 --- a/app/main/handlers/upgradeUtil.js +++ b/app/main/handlers/upgradeUtil.js @@ -479,7 +479,7 @@ module.exports = { }) zipHandler.on("ready", () => { const targetPath = path.join(YakitProjectPath, output_name) - zipHandler.extract(output_name, targetPath, (err, res) => { + zipHandler.extract(output_name, targetPath, (err, res) => { if (!fs.existsSync(targetPath)) { reject(`Extract Cert Script Failed`) } else { @@ -631,5 +631,52 @@ module.exports = { } return await asyncInitBuildInEngine({}) }) + + // 解压 start-engine.zip + const generateStartEngineGRPC = () => { + return new Promise((resolve, reject) => { + const all = "start-engine.zip" + const output_name = isWindows ? `start-engine-grpc.bat` : `start-engine-grpc.sh` + + // 如果存在就不在解压 + if(fs.existsSync(path.join(yaklangEngineDir,output_name))){ + resolve("") + return + } + + if (!fs.existsSync(loadExtraFilePath(path.join("bins/scripts", all)))) { + reject(all + " not found") + return + } + const zipHandler = new zip({ + file: loadExtraFilePath(path.join("bins/scripts", all)), storeEntries: true, + }) + zipHandler.on("ready", () => { + const targetPath = path.join(yaklangEngineDir, output_name) + zipHandler.extract(output_name, targetPath, (err, res) => { + if (!fs.existsSync(targetPath)) { + reject(`Extract Start Engine GRPC Script Failed`) + } else { + // 如果不是 Windows,给脚本文件添加执行权限 + if (!isWindows) { + fs.chmodSync(targetPath, 0o755); + } + resolve("") + } + zipHandler.close(); + }) + }) + zipHandler.on("error", err => { + console.info(err) + reject(`${err}`) + zipHandler.close() + }) + }) + } + + + ipcMain.handle("generate-start-engine", async (e) => { + return await generateStartEngineGRPC() + }) }, } \ No newline at end of file diff --git a/app/main/index.js b/app/main/index.js index 9dbd0a84b0..97fce33501 100644 --- a/app/main/index.js +++ b/app/main/index.js @@ -6,7 +6,7 @@ const {registerIPC, clearing} = require("./ipc") const process = require("process") const {initExtraLocalCache, getExtraLocalCacheValue, initLocalCache, setCloeseExtraLocalCache} = require("./localCache") const {asyncKillDynamicControl} = require("./handlers/dynamicControlFun") -const {windowStatePatch, engineLog, renderLog} = require("./filePath") +const {windowStatePatch, engineLog, renderLog, printLog} = require("./filePath") const fs = require("fs") const Screenshots = require("./screenshots") const windowStateKeeper = require("electron-window-state") @@ -56,7 +56,7 @@ const createWindow = () => { sandbox: true }, frame: false, - titleBarStyle: "hidden", + titleBarStyle: "hidden" }) win.setSize(mainWindowState.width, mainWindowState.height) mainWindowState.manage(win) @@ -156,10 +156,15 @@ app.whenReady().then(() => { fs.mkdirSync(engineLog, {recursive: true}) } if (fs.existsSync(renderLog)) { - clearFolder(renderLog, 5) + clearFolder(renderLog, 9) } else { fs.mkdirSync(renderLog, {recursive: true}) } + if (fs.existsSync(printLog)) { + clearFolder(printLog, 9) + } else { + fs.mkdirSync(printLog, {recursive: true}) + } // 软件退出的逻辑 ipcMain.handle("app-exit", async (e, params) => { diff --git a/app/main/ipc.js b/app/main/ipc.js index 17403dfc42..fc13e152a7 100644 --- a/app/main/ipc.js +++ b/app/main/ipc.js @@ -269,7 +269,7 @@ module.exports = { // new plugins store require("./handlers/plugins")(win, getClient) - // render-error-log + // (render|print)-error-log require("./errorCollection")(win, getClient) } } diff --git a/app/main/toolsFunc.js b/app/main/toolsFunc.js index 0e000ac6d4..c1e56b24dd 100644 --- a/app/main/toolsFunc.js +++ b/app/main/toolsFunc.js @@ -28,12 +28,16 @@ const clearFolder = (folderPath, length) => { stats: fs.statSync(filePath) } }) + // 有信息的文件集合 + const validFiles = fileStats.filter((item) => item.stats.size && item.stats.size > 0) + // 没信息的文件集合 + const invalidFiles = fileStats.filter((item) => !item.stats.size || item.stats.size <= 0) // 按最后修改时间进行排序 - const sortedFiles = fileStats.sort((a, b) => b.stats.mtime.getTime() - a.stats.mtime.getTime()) + const sortedFiles = validFiles.sort((a, b) => b.stats.mtime.getTime() - a.stats.mtime.getTime()) // 保留最近的十个文件,删除其他文件 - const filesToDelete = sortedFiles.slice(length) + const filesToDelete = sortedFiles.slice(length).concat([...invalidFiles]) filesToDelete.forEach((file) => { fs.unlink(file.path, (err) => { if (err) { diff --git a/app/main/uiOperate/hardware.js b/app/main/uiOperate/hardware.js index 61b2a3d1fa..e29d349f75 100644 --- a/app/main/uiOperate/hardware.js +++ b/app/main/uiOperate/hardware.js @@ -114,7 +114,7 @@ module.exports = (win, getClient) => { }) /** 打开 yaklang 或 yakit 文件所在文件夹 (ps:随着yakit下载移动至下载文件夹中,此方法仅打开yaklang)*/ - ipcMain.handle("open-yakit-or-yaklang", (e) => { + ipcMain.handle("open-yaklang-path", (e) => { return shell.openPath(yaklangEngineDir) }) diff --git a/app/main/uiOperate/yaklangAndYakit.js b/app/main/uiOperate/yaklangAndYakit.js index 782d7de998..3a217577a7 100644 --- a/app/main/uiOperate/yaklangAndYakit.js +++ b/app/main/uiOperate/yaklangAndYakit.js @@ -1,8 +1,9 @@ const {ipcMain, app} = require("electron") +const path = require("path") const fs = require("fs") const https = require("https") -const {getLocalYaklangEngine} = require("../filePath") -const {fetchLatestYakEngineVersion} = require("../handlers/utils/network"); +const {getLocalYaklangEngine, loadExtraFilePath} = require("../filePath") +const {fetchLatestYakEngineVersion} = require("../handlers/utils/network") module.exports = (win, getClient) => { /** yaklang引擎是否安装 */ @@ -14,11 +15,13 @@ module.exports = (win, getClient) => { /** 获取Yaklang引擎最新版本号 */ const asyncFetchLatestYaklangVersion = () => { return new Promise((resolve, reject) => { - fetchLatestYakEngineVersion().then(version => { - resolve(`${version}`.trim()) - }).catch(err => { - reject(err) - }) + fetchLatestYakEngineVersion() + .then((version) => { + resolve(`${version}`.trim()) + }) + .catch((err) => { + reject(err) + }) }) } /** 获取Yaklang引擎最新版本号 */ @@ -52,4 +55,18 @@ module.exports = (win, getClient) => { ipcMain.handle("kill-old-engine-process", (e, type) => { win.webContents.send("kill-old-engine-process-callback", type) }) + + /** 获取软件当前版本对应的引擎版本号 */ + ipcMain.handle("fetch-built-in-engine-version", (e) => { + const versionPath = loadExtraFilePath(path.join("bins", "engine-version.txt")) + if (fs.existsSync(versionPath)) { + try { + return fs.readFileSync(versionPath).toString("utf8") + } catch (error) { + return "" + } + } else { + return "" + } + }) } diff --git a/app/renderer/src/main/src/NewApp.tsx b/app/renderer/src/main/src/NewApp.tsx index 4e81f3591a..b154f95169 100644 --- a/app/renderer/src/main/src/NewApp.tsx +++ b/app/renderer/src/main/src/NewApp.tsx @@ -35,6 +35,11 @@ function NewApp() { /** 是否展示用户协议 */ const [agreed, setAgreed] = useState(false) + useEffect(() => { + // 解压命令执行引擎脚本压缩包 + ipcRenderer.invoke("generate-start-engine") + }, []) + /** * 渲染端全局错误监听,并收集到错误信息文件里 */ diff --git a/app/renderer/src/main/src/components/basics/YakitLoading.tsx b/app/renderer/src/main/src/components/basics/YakitLoading.tsx index abfa860c61..cb328a0a51 100644 --- a/app/renderer/src/main/src/components/basics/YakitLoading.tsx +++ b/app/renderer/src/main/src/components/basics/YakitLoading.tsx @@ -4,11 +4,15 @@ import {YakitStatusType, YaklangEngineMode} from "@/yakitGVDefine" import {YakitButton} from "../yakitUI/YakitButton/YakitButton" import {getReleaseEditionName, isCommunityEdition, isEnpriTrace, isEnpriTraceAgent} from "@/utils/envfile" import {DynamicStatusProps} from "@/store" +import {Tooltip} from "antd" +import {OutlineQuestionmarkcircleIcon} from "@/assets/icon/outline" import yakitSE from "@/assets/yakitSE.png" import yakitEE from "@/assets/yakitEE.png" import styles from "./yakitLoading.module.scss" +const {ipcRenderer} = window.require("electron") + /** 首屏加载蒙层展示语 */ const LoadingTitle: string[] = [ "没有困难的工作,只有勇敢的打工人。", @@ -260,7 +264,20 @@ export const YakitLoading: React.FC = (props) => { -
{btns}
+
+ {btns} +
{ + ipcRenderer.invoke("open-yaklang-path") + }} + > + 打开引擎所在文件 + + + +
+
diff --git a/app/renderer/src/main/src/components/basics/yakitLoading.module.scss b/app/renderer/src/main/src/components/basics/yakitLoading.module.scss index 2d187d50bc..c2de73f36d 100644 --- a/app/renderer/src/main/src/components/basics/yakitLoading.module.scss +++ b/app/renderer/src/main/src/components/basics/yakitLoading.module.scss @@ -115,6 +115,26 @@ .btn-style { width: 280px; } + + .engine-help-wrapper { + width: 280px; + display: flex; + justify-content: center; + align-items: center; + gap: 4px; + line-height: 20px; + color: #b4bbca; + font-size: 14px; + cursor: pointer; + svg { + width: 16px; + height: 16px; + } + + &:hover { + color: var(--yakit-primary-5); + } + } } } } diff --git a/app/renderer/src/main/src/components/layout/CheckEngineVersion/CheckEngineVersion.module.scss b/app/renderer/src/main/src/components/layout/CheckEngineVersion/CheckEngineVersion.module.scss new file mode 100644 index 0000000000..809c1d84f8 --- /dev/null +++ b/app/renderer/src/main/src/components/layout/CheckEngineVersion/CheckEngineVersion.module.scss @@ -0,0 +1,5 @@ +.check-engine-version-checkbox { + height: 100%; + display: flex; + align-items: center; +} diff --git a/app/renderer/src/main/src/components/layout/CheckEngineVersion/CheckEngineVersion.tsx b/app/renderer/src/main/src/components/layout/CheckEngineVersion/CheckEngineVersion.tsx new file mode 100644 index 0000000000..5bc3391653 --- /dev/null +++ b/app/renderer/src/main/src/components/layout/CheckEngineVersion/CheckEngineVersion.tsx @@ -0,0 +1,65 @@ +import React, {useState} from "react" +import {YakitHint} from "@/components/yakitUI/YakitHint/YakitHint" +import {useMemoizedFn} from "ahooks" +import {YakitCheckbox} from "@/components/yakitUI/YakitCheckbox/YakitCheckbox" +import {setRemoteValue} from "@/utils/kv" +import {EngineRemoteGV} from "@/enums/engine" +import {YaklangEngineMode} from "@/yakitGVDefine" + +import styles from "./CheckEngineVersion.module.scss" + +interface CheckEngineVersionProps { + engineMode: YaklangEngineMode + currentVersion: string + builtInVersion: string + visible: boolean + onCancel: (flag: boolean) => any +} + +/** @name Yakit软件更新下载弹窗 */ +export const CheckEngineVersion: React.FC = React.memo((props) => { + const {engineMode, visible, currentVersion, builtInVersion, onCancel} = props + + const [loading, setLoading] = useState(false) + + const [noPrompt, setNoPrompt] = useState(false) + + const onSubmit = useMemoizedFn(() => { + if (loading) return + setRemoteValue(EngineRemoteGV.RemoteCheckEngineVersion, `${noPrompt}`) + onCancel(true) + setTimeout(() => { + setLoading(false) + }, 500) + }) + const onClose = useMemoizedFn(() => { + setRemoteValue(EngineRemoteGV.RemoteCheckEngineVersion, `${noPrompt}`) + onCancel(false) + }) + + return ( + + 检测到当前使用的引擎版本过低,可能会影响部分功能的使用,建议立即更新引擎版本。 +
当前版本 : {currentVersion}
+
建议版本 : {builtInVersion}
+ + } + footerExtra={ +
+ setNoPrompt(e.target.checked)}> + 不再提醒 + +
+ } + okButtonText='立即更新' + okButtonProps={{loading: loading, style: {display: engineMode === "remote" ? "none" : ""}}} + onOk={onSubmit} + cancelButtonText={engineMode === "remote" ? "知道了" : "忽略"} + onCancel={onClose} + /> + ) +}) diff --git a/app/renderer/src/main/src/components/layout/LocalEngine/LocalEngine.tsx b/app/renderer/src/main/src/components/layout/LocalEngine/LocalEngine.tsx index 91761a2cc7..81def5e5db 100644 --- a/app/renderer/src/main/src/components/layout/LocalEngine/LocalEngine.tsx +++ b/app/renderer/src/main/src/components/layout/LocalEngine/LocalEngine.tsx @@ -73,8 +73,7 @@ export const LocalEngine: React.FC = memo( const onFetchLocalAndLatsVersion = useMemoizedFn(() => { setTimeout(() => { - handleFetchYakitAndYaklangLatestVersion() - handleFetchYakitAndYaklangLocalVersion() + handleFetchYakitAndYaklangLocalVersion(handleFetchYakitAndYaklangLatestVersion) }, 500) }) @@ -83,7 +82,7 @@ export const LocalEngine: React.FC = memo( /** 是否已弹出更新框 */ const isShowedUpdateHint = useRef(false) - const handleFetchYakitAndYaklangLocalVersion = useMemoizedFn(async () => { + const handleFetchYakitAndYaklangLocalVersion = useMemoizedFn(async (callback?: () => any) => { try { let localYakit = (await ipcRenderer.invoke("fetch-yakit-version")) || "" setCurrentYakit(localYakit) @@ -104,6 +103,8 @@ export const LocalEngine: React.FC = memo( setLog(["获取引擎版本号...", `错误: ${error}`]) setYakitStatus("checkError") } + + if (callback) callback() }) const handleFetchYakitAndYaklangLatestVersion = useMemoizedFn(() => { diff --git a/app/renderer/src/main/src/components/layout/UILayout.tsx b/app/renderer/src/main/src/components/layout/UILayout.tsx index 14a3fd1b6b..9389b86c2b 100644 --- a/app/renderer/src/main/src/components/layout/UILayout.tsx +++ b/app/renderer/src/main/src/components/layout/UILayout.tsx @@ -51,6 +51,9 @@ import {DownloadYaklang} from "./update/DownloadYaklang" import {HelpDoc} from "./HelpDoc/HelpDoc" import {SolidHomeIcon} from "@/assets/icon/solid" import {ChatCSGV} from "@/enums/chatCS" +import {CheckEngineVersion} from "./CheckEngineVersion/CheckEngineVersion" +import {EngineRemoteGV} from "@/enums/engine" +import {outputToPrintLog} from "./WelcomeConsoleUtil" import classNames from "classnames" import styles from "./uiLayout.module.scss" @@ -361,6 +364,7 @@ const UILayout: React.FC = (props) => { }) onSetYakitStatus("ready") onStartLinkEngine() + outputToPrintLog("local-start-test-engine-link-status") }) const [remoteLinkLoading, setRemoteLinkLoading] = useState(false) @@ -645,6 +649,73 @@ const UILayout: React.FC = (props) => { }, []) /** ---------- yakit和yaklang的更新(以连接引擎的状态下) & kill引擎进程 End ---------- */ + /** ---------- 软件绑定引擎版本检测提示 Start ---------- */ + const [builtInVersion, setBuiltInVersion] = useState("") + const [currentVersion, setCurrentVersion] = useState("") + /** 判断版本检测是否已执行过 */ + const isExecuteRef = useRef(false) + + const showCheckVersion = useMemo(() => { + if (isExecuteRef.current) return false + if (isDev.current) return false + if (!builtInVersion) return false + if (!currentVersion) return false + + // 判断版本号的库 semver,暂时没用,后续可以用 + if (currentVersion < builtInVersion) return true + return false + }, [builtInVersion, currentVersion]) + + useEffect(() => { + // 监听事件-获取当前连接引擎的版本 + ipcRenderer.on("fetch-yak-version-callback", async (e: any, v: string) => { + if (isExecuteRef.current) return + let version = v.replace(/\r?\n/g, "") + if (version.startsWith("v")) version = version.slice(1) + setCurrentVersion(version) + }) + return () => { + ipcRenderer.removeAllListeners("fetch-yak-version-callback") + } + }, []) + + useEffect(() => { + if (engineLink) { + if (isExecuteRef.current) return + getRemoteValue(EngineRemoteGV.RemoteCheckEngineVersion) + .then((v?: string) => { + if (!v || v === "false") { + // 获取软件对应的内置版本 + ipcRenderer + .invoke("fetch-built-in-engine-version") + .then((v: string) => { + if (isExecuteRef.current) return + let version = v.replace(/\r?\n/g, "") + if (version.startsWith("v")) version = version.slice(1) + setBuiltInVersion(version) + }) + .catch(() => {}) + // 获取当前连接引擎的版本 + ipcRenderer.invoke("fetch-yak-version") + } else { + isExecuteRef.current = true + } + }) + .catch(() => {}) + } + }, [engineLink]) + + const onCheckVersionCancel = useMemoizedFn((flag: boolean) => { + isExecuteRef.current = true + if (flag) { + if (yaklangKillPss) return + setYaklangKillPss(true) + } + setBuiltInVersion("") + setCurrentVersion("") + }) + /** ---------- 软件绑定引擎版本检测提示 End ---------- */ + /** ---------- 远程控制(控制端) Start ---------- */ const {dynamicStatus, setDynamicStatus} = yakitDynamicStatus() const {userInfo} = useStore() @@ -936,6 +1007,7 @@ const UILayout: React.FC = (props) => { }, []) const onReady = useMemoizedFn(() => { + outputToPrintLog(`连接成功-start-engineLink:${cacheEngineLink.current}`) if (!cacheEngineLink.current) { isEnpriTraceAgent() ? SELinkedEngine() : onLinkedEngine() } @@ -957,6 +1029,7 @@ const UILayout: React.FC = (props) => { setKeepalive(false) return } + outputToPrintLog(`连接失败: ${count}次`) onSetEngineLink(false) @@ -1276,6 +1349,16 @@ const UILayout: React.FC = (props) => { )} + {engineLink && ( + + )} + { - ipcRenderer.invoke("output-log-to-welcome-console", `${msg}`).then(() => { - }).catch(e => { - console.info(e) - }) + ipcRenderer + .invoke("output-log-to-welcome-console", `${msg}`) + .then(() => {}) + .catch((e) => { + console.info(e) + }) } export const getRandomLocalEnginePort = (callback: (port: number) => any) => { - ipcRenderer.invoke("get-random-local-engine-port").then((port: number) => { - callback(port) - }).catch(e => { - console.info(e) - }) + ipcRenderer + .invoke("get-random-local-engine-port") + .then((port: number) => { + callback(port) + }) + .catch((e) => { + console.info(e) + }) } export const isEngineConnectionAlive = () => { - const text = randomString(30); - return ipcRenderer.invoke("Echo", {text}).then((res: { result: string }) => { + const text = randomString(30) + return ipcRenderer.invoke("Echo", {text}).then((res: {result: string}) => { if (res.result !== text) { throw Error(`Engine dead`) } return true }) } + +export const outputToPrintLog = (msg: string) => { + ipcRenderer.invoke("print-info-log", `${msg || ""}`) +} diff --git a/app/renderer/src/main/src/components/layout/YaklangEngineWatchDog.tsx b/app/renderer/src/main/src/components/layout/YaklangEngineWatchDog.tsx index 1a128222eb..e5798a6bac 100644 --- a/app/renderer/src/main/src/components/layout/YaklangEngineWatchDog.tsx +++ b/app/renderer/src/main/src/components/layout/YaklangEngineWatchDog.tsx @@ -1,6 +1,6 @@ import React, {useEffect, useRef, useState} from "react" import {useDebounceEffect, useMemoizedFn} from "ahooks" -import {isEngineConnectionAlive, outputToWelcomeConsole} from "@/components/layout/WelcomeConsoleUtil" +import {isEngineConnectionAlive, outputToPrintLog, outputToWelcomeConsole} from "@/components/layout/WelcomeConsoleUtil" import {EngineWatchDogCallbackType, YaklangEngineMode} from "@/yakitGVDefine" import {EngineModeVerbose} from "@/components/basics/YakitLoading" import {failed} from "@/utils/notification" @@ -49,6 +49,9 @@ export const YaklangEngineWatchDog: React.FC = React /** 引擎信息认证 */ const engineTest = useMemoizedFn((isDynamicControl?: boolean) => { + outputToPrintLog( + `engineTest-start:\nmode:${props.credential.Mode}|port:${props.credential.Port}|isDynamicControl:${isDynamicControl}` + ) // 重置状态 setAutoStartProgress(false) const mode = props.credential.Mode @@ -69,6 +72,7 @@ export const YaklangEngineWatchDog: React.FC = React ipcRenderer .invoke("connect-yaklang-engine", props.credential) .then(() => { + outputToPrintLog(`engineTest-success: mode:${props.credential.Mode}`) outputToWelcomeConsole(`连接核心引擎成功!`) if (props.onKeepaliveShouldChange) { props.onKeepaliveShouldChange(true) @@ -84,6 +88,7 @@ export const YaklangEngineWatchDog: React.FC = React } }) .catch((e) => { + outputToPrintLog(`engineTest-failed: mode:${props.credential.Mode}`) outputToWelcomeConsole("未连接到引擎,尝试启动引擎进程") switch (mode) { case "local": @@ -137,6 +142,8 @@ export const YaklangEngineWatchDog: React.FC = React return } + outputToPrintLog(`尝试启动新引擎进程: port:${props.credential.Port}`) + // 只有普通模式才涉及到引擎启动的流程 outputToWelcomeConsole(`开始以普通权限启动本地引擎进程,本地端口为: ${props.credential.Port}`) @@ -160,10 +167,12 @@ export const YaklangEngineWatchDog: React.FC = React }) .then(() => { outputToWelcomeConsole("引擎启动成功!") + outputToPrintLog(`本地新引擎进程启动成功`) }) .catch((e) => { console.info(e) outputToWelcomeConsole("引擎启动失败:" + e) + outputToPrintLog(`本地新引擎进程启动失败: ${e}`) }) .finally(() => { startingUp.current = false @@ -174,6 +183,7 @@ export const YaklangEngineWatchDog: React.FC = React `端口被占用,无法启动本地引擎(${EngineModeVerbose(mode as YaklangEngineMode)})` ) outputToWelcomeConsole(`错误原因为: ${e}`) + outputToPrintLog(`端口被占用: ${e}`) }) }, [autoStartProgress, props.onKeepaliveShouldChange, props.credential], @@ -201,6 +211,7 @@ export const YaklangEngineWatchDog: React.FC = React } return } + outputToPrintLog(`开始检测引擎进程是否启动`) let count = 0 let failedCount = 0 @@ -209,6 +220,7 @@ export const YaklangEngineWatchDog: React.FC = React count++ isEngineConnectionAlive() .then(() => { + outputToPrintLog(`keepalive状态: ${keepalive}`) if (!keepalive) { return } diff --git a/app/renderer/src/main/src/enums/engine.ts b/app/renderer/src/main/src/enums/engine.ts new file mode 100644 index 0000000000..7719755c49 --- /dev/null +++ b/app/renderer/src/main/src/enums/engine.ts @@ -0,0 +1,7 @@ +export enum EngineRemoteGV { + /** + * @name 是否启动引擎版本检查 + * 引擎插件:判断当前版本是否比软件适配版本高,如果低于适配版本则弹出引擎版本检查弹窗 + */ + RemoteCheckEngineVersion = "remote-check-engine-version" +} diff --git a/bins/scripts/start-engine.zip b/bins/scripts/start-engine.zip new file mode 100644 index 0000000000000000000000000000000000000000..b68839ad2b4200883c6bd43954c53e4dd183cb0b GIT binary patch literal 1300 zcmWIWW@Zs#-~hr2H8Ua@pgZTVJBjF)##&UGYD4=CZ$+&bbF#e!77d);;j@3kK0uS@fsTof_jPpk5022+izn!= zGsiL9m7E}&oSu-B@WIz7>;r#TM?eG91PNw!0ck@6124u*h4~lT8#NwC2nn$yHkRID ze8gm;dM2Qdk&SKTlRq(gk2E#S3E4a6$fHS@9$lF-<;bLvrws`!Zkap0Ie6eef57zF zGv+WG-e>XfFfiy)dcx%`+%5Fk%jk2Eq*~5p59XDpR-d@SqMiRGSy!X*E|Xc zov*)Q=LW+ya^V$98)z5U9WM?FE=kT4X|Tm1JrF#JFvg$TpRND-k*2G)`l7N zTn0c(K^9|ok_gbT3P6ZATG3rcO1v_DR90a7BHn&ms5_i|F@+ zga`iT&R_M`(Kz9G^|Y_gxyBR!8Iw5K*aBN(5;Kzmlj1zn;!N8J65DPPM2(n|IJ-6HDoVZUu5^f>H|% eENM((BH$l%+pv0wl?`Mf3lJ^