Skip to content

Commit

Permalink
feature/some-function (#1602)
Browse files Browse the repository at this point in the history
* 软件绑定引擎版本对比检查提示

* 1、引擎检查版本中,本地和最新版本强制为顺序同步执行,不再同时获取本地和最新版本
2、加入打印信息日志功能,监听启动引擎成功但未进入UI界面问题
3、删除日志文件逻辑调整,删除老文件的同时,也将无信息的文件同时删除

* 修复测试小问题

* 加入命令运行引擎脚本功能
  • Loading branch information
b1rdfree authored Apr 26, 2024
1 parent 20a8e4e commit dde9b21
Show file tree
Hide file tree
Showing 21 changed files with 355 additions and 37 deletions.
23 changes: 19 additions & 4 deletions app/main/errorCollection.js
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
})
}
3 changes: 3 additions & 0 deletions app/main/filePath.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -132,6 +134,7 @@ module.exports = {
extraLocalCachePath,
engineLog,
renderLog,
printLog,

remoteLinkDir,
remoteLinkFile,
Expand Down
1 change: 1 addition & 0 deletions app/main/handlers/engineStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")
Expand Down
49 changes: 48 additions & 1 deletion app/main/handlers/upgradeUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
})
},
}
11 changes: 8 additions & 3 deletions app/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -56,7 +56,7 @@ const createWindow = () => {
sandbox: true
},
frame: false,
titleBarStyle: "hidden",
titleBarStyle: "hidden"
})
win.setSize(mainWindowState.width, mainWindowState.height)
mainWindowState.manage(win)
Expand Down Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion app/main/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
8 changes: 6 additions & 2 deletions app/main/toolsFunc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion app/main/uiOperate/hardware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down
31 changes: 24 additions & 7 deletions app/main/uiOperate/yaklangAndYakit.js
Original file line number Diff line number Diff line change
@@ -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引擎是否安装 */
Expand All @@ -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引擎最新版本号 */
Expand Down Expand Up @@ -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 ""
}
})
}
5 changes: 5 additions & 0 deletions app/renderer/src/main/src/NewApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ function NewApp() {
/** 是否展示用户协议 */
const [agreed, setAgreed] = useState(false)

useEffect(() => {
// 解压命令执行引擎脚本压缩包
ipcRenderer.invoke("generate-start-engine")
}, [])

/**
* 渲染端全局错误监听,并收集到错误信息文件里
*/
Expand Down
19 changes: 18 additions & 1 deletion app/renderer/src/main/src/components/basics/YakitLoading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [
"没有困难的工作,只有勇敢的打工人。",
Expand Down Expand Up @@ -260,7 +264,20 @@ export const YakitLoading: React.FC<YakitLoadingProp> = (props) => {
</div>
</div>

<div className={styles["engine-log-btn"]}>{btns}</div>
<div className={styles["engine-log-btn"]}>
{btns}
<div
className={styles["engine-help-wrapper"]}
onClick={() => {
ipcRenderer.invoke("open-yaklang-path")
}}
>
打开引擎所在文件
<Tooltip title={`打开文件夹后运行'start-engine-grpc',命令行启动引擎查看具体问题`}>
<OutlineQuestionmarkcircleIcon />
</Tooltip>
</div>
</div>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.check-engine-version-checkbox {
height: 100%;
display: flex;
align-items: center;
}
Loading

0 comments on commit dde9b21

Please sign in to comment.