diff --git a/backend/app.go b/backend/app.go index 1d2cccc..2b0b6f2 100644 --- a/backend/app.go +++ b/backend/app.go @@ -34,9 +34,6 @@ func (a *App) WailsInit(runtime *wails.Runtime) error { return err } - //设置前端 - a.setAppVersion(a.cfg.AppVersion) - a.setVersionCode(a.cfg.VersionCode) return nil } @@ -51,6 +48,12 @@ func (a *App) WailsShutdown() { } } +//设置前端变量 +func (a *App) SetVar() { + a.setAppVersion(a.cfg.AppVersion) + a.setVersionCode(a.cfg.VersionCode) +} + //检查更新 func (a *App) CheckUpdate() { var err error @@ -180,6 +183,18 @@ func (a *App) installHLAE() error { //识别已安装hlae,则检查更新 if ok, _ := tool.IsFileExisted(path + "/hlae.exe"); ok { a.cfg.HlaePath = tool.FormatPath(path) + //解析修正本地hlae版本号 + changelog, err := tool.ReadAll(a.cfg.HlaePath + "/changelog.xml") + if err != nil { + a.noticeError("读取本地版本号失败: " + err.Error()) + return err + } + if tVersion, err := api.ParseChangelog(changelog); err != nil { + a.noticeError("解析本地版本号失败: " + err.Error()) + return err + } else { + a.cfg.HlaeVersion = tVersion + } if err := a.updateHLAE(); err != nil { return err } @@ -258,7 +273,7 @@ func (a *App) installHLAE() error { var jsonx = jsoniter.ConfigCompatibleWithStandardLibrary //使用高性能json-iterator/go库 err := jsonx.Unmarshal([]byte(cdnData), &cdnInst) //第二个参数要地址传递 if err != nil { - return err //TODO + return err } //获取版本号、下载地址和文件名 cdnVersion = cdnInst.Version @@ -269,13 +284,14 @@ func (a *App) installHLAE() error { //决定下载的文件 if srcVersion == "" && cdnVersion == "" { return errors.New("hlae官方和CDN的API均获取或解析失败") - } else if srcVersion == "" { - a.noticeWarning("hlae官方API解析失败,CDN源可能不是最新版本") } else if cdnVersion == "" { a.noticeWarning("CDN源解析失败,下载速度可能较慢") + } else if srcVersion == "" { + a.noticeWarning("hlae官方API解析失败,CDN源可能不是最新版本") } - if srcVersion != "" && srcVersion == cdnVersion { - //hlae版本非空且和CDN源版本一致,则下载CDN源 + + if srcVersion == "" || (srcVersion != "" && srcVersion == cdnVersion) { + //官方版本非空且和CDN源版本一致,则下载CDN源 version = cdnVersion url = cdnURL filename = cdnFilename @@ -360,7 +376,7 @@ func (a *App) installFFmpeg() error { var jsonx = jsoniter.ConfigCompatibleWithStandardLibrary //使用高性能json-iterator/go库 err := jsonx.Unmarshal([]byte(cdnData), &cdnInst) //第二个参数要地址传递 if err != nil { - return err //TODO + return err } //获取版本号、下载地址和文件名 cdnVersion = cdnInst.Version @@ -376,8 +392,8 @@ func (a *App) installFFmpeg() error { } else if cdnVersion == "" { a.noticeWarning("CDN源解析失败,下载速度可能较慢") } - if srcVersion != "" && srcVersion == cdnVersion { - //FFmpeg版本非空且和CDN源版本一致,则下载CDN源 + if srcVersion == "" || (srcVersion != "" && srcVersion == cdnVersion) { + //官方版本非空且和CDN源版本一致,则下载CDN源 version = cdnVersion url = cdnURL filename = cdnFilename @@ -482,7 +498,7 @@ func (a *App) updateHLAE() error { var jsonx = jsoniter.ConfigCompatibleWithStandardLibrary //使用高性能json-iterator/go库 err := jsonx.Unmarshal([]byte(cdnData), &cdnInst) //第二个参数要地址传递 if err != nil { - return err //TODO + return err } //获取版本号、下载地址和文件名 cdnVersion = cdnInst.Version @@ -498,8 +514,8 @@ func (a *App) updateHLAE() error { } else if cdnVersion == "" { a.noticeWarning("CDN源解析失败,下载速度可能较慢") } - if srcVersion != "" && srcVersion == cdnVersion { - //hlae版本非空且和CDN源版本一致,则下载CDN源 + if srcVersion == "" || (srcVersion != "" && srcVersion == cdnVersion) { + //官方版本非空且和CDN源版本一致,则下载CDN源 version = cdnVersion url = cdnURL filename = cdnFilename @@ -589,7 +605,7 @@ func (a *App) updateFFmpeg() error { var jsonx = jsoniter.ConfigCompatibleWithStandardLibrary //使用高性能json-iterator/go库 err := jsonx.Unmarshal([]byte(cdnData), &cdnInst) //第二个参数要地址传递 if err != nil { - return err //TODO + return err } //获取版本号、下载地址和文件名 cdnVersion = cdnInst.Version @@ -605,8 +621,8 @@ func (a *App) updateFFmpeg() error { } else if cdnVersion == "" { a.noticeWarning("CDN源解析失败,下载速度可能较慢") } - if srcVersion != "" && srcVersion == cdnVersion { - //FFmpeg版本非空且和CDN源版本一致,则下载CDN源 + if srcVersion == "" || (srcVersion != "" && srcVersion == cdnVersion) { + //官方版本非空且和CDN源版本一致,则下载CDN源 version = cdnVersion url = cdnURL filename = cdnFilename diff --git a/backend/config/default.go b/backend/config/default.go index a3f02ec..5e4d761 100644 --- a/backend/config/default.go +++ b/backend/config/default.go @@ -2,7 +2,7 @@ package config var defaultCFG = CFG{ VersionCode: "Testify", - AppVersion: "v0.0.4", + AppVersion: "v1.0.1", HlaeVersion: "", FFmpegVersion: "", HlaeAPI: "https://api.github.com/repos/advancedfx/advancedfx/releases/latest", diff --git a/backend/wails.go b/backend/wails.go index f5aaf34..88bce64 100644 --- a/backend/wails.go +++ b/backend/wails.go @@ -15,43 +15,47 @@ func (a *App) SayHello() string { return "Hello to Frontend!" } -//设置进度条 需要前端Mount +//设置进度条 func (a *App) setProgress(percent int) { a.runtime.Events.Emit("SetProgess", percent) } +//设置日志信息 func (a *App) setLog(log string) { a.runtime.Events.Emit("SetLog", log) } +//设置版本代号 func (a *App) setVersionCode(versionCode string) { a.runtime.Events.Emit("SetVersionCode", versionCode) } +//设置App版本 func (a *App) setAppVersion(appVersion string) { a.runtime.Events.Emit("SetAppVersion", appVersion) } -func (a *App) setStandalone(standalone string) { - a.runtime.Events.Emit("SetStandalone", standalone) -} - +//选择hlae安装方式 func (a *App) doSelectOption() { a.runtime.Events.Emit("DoSelectOption") } +//通知成功 func (a *App) noticeSuccess(msg string) { a.runtime.Events.Emit("NoticeSuccess", msg) } +//通知错误 func (a *App) noticeError(msg string) { a.runtime.Events.Emit("NoticeError", msg) } +//通知警告 func (a *App) noticeWarning(msg string) { a.runtime.Events.Emit("NoticeWarning", msg) } +//选择文件夹 func (a *App) SelectDirectory() string { directory := a.runtime.Dialog.SelectDirectory() if ok, err := tool.IsFileExisted(directory); err != nil || !ok { @@ -63,6 +67,7 @@ func (a *App) SelectDirectory() string { return directory } +//选择文件 func (a *App) SelectFile() string { path := a.runtime.Dialog.SelectFile() if ok, err := tool.IsFileExisted(path); err != nil || !ok { @@ -73,6 +78,7 @@ func (a *App) SelectFile() string { return path } +//选择文件,有标题 func (a *App) SelectFileTitle(Title string) string { path := a.runtime.Dialog.SelectFile(Title) if ok, err := tool.IsFileExisted(path); err != nil || !ok { @@ -83,6 +89,7 @@ func (a *App) SelectFileTitle(Title string) string { return path } +//选择文件,有标题和过滤文件 func (a *App) SelectFileTitleFilter(Title string, Filter string) string { path := a.runtime.Dialog.SelectFile(Title, Filter) if ok, err := tool.IsFileExisted(path); err != nil || !ok { diff --git a/config.json b/config.json new file mode 100644 index 0000000..4759250 --- /dev/null +++ b/config.json @@ -0,0 +1,15 @@ +{ + "VersionCode": "Testify", + "AppVersion": "v1.0.1", + "HlaeVersion": "v2.109.7", + "FFmpegVersion": "4.3.1-2021-01-01", + "HlaeAPI": "https://api.github.com/repos/advancedfx/advancedfx/releases/latest", + "HlaeCdnAPI": "https://cdn.jsdelivr.net/gh/One-Studio/HLAE-Archive@master/api.json", + "FFmpegAPI": "https://www.gyan.dev/ffmpeg/builds", + "FFmpegCdnAPI": "https://cdn.jsdelivr.net/gh/One-Studio/FFmpeg-Win64@master/api.json", + "HlaePath": "C:/Users/Purp1e/AppData/Local/AkiVer/hlae", + "Init": true, + "Standalone": false, + "HlaeState": true, + "FFmpegState": true +} \ No newline at end of file diff --git a/frontend/package.json.md5 b/frontend/package.json.md5 index b60e083..72107c1 100644 --- a/frontend/package.json.md5 +++ b/frontend/package.json.md5 @@ -1 +1 @@ -03afdf9640466e356163d0a142747130 \ No newline at end of file +4437c0505ecf58a57eea92c048cf9cc2 \ No newline at end of file diff --git a/frontend/src/components/Main.vue b/frontend/src/components/Main.vue index a0ec217..efea3c9 100644 --- a/frontend/src/components/Main.vue +++ b/frontend/src/components/Main.vue @@ -25,12 +25,16 @@ {{ log }}
- + - - 打开HLAE + + + + + 打开HLAE +
@@ -42,12 +46,12 @@ export default { name: "Main", data() { return { - versionCode: "Testify", - appVersion: "v1.0.0", + versionCode: "Version", + appVersion: "v0.0.1", progress: 0, log: "", standalone: true, - btnSetting: false, + btnUpdate: false, btnOpenDir: false, btnLaunchHLAE: false, }; @@ -73,6 +77,8 @@ export default { this.selectOption(); }); Wails.Events.On("NoticeSuccess", (msg) => { + // console.log(msg); + // let mes = msg; this.$message.success(msg, 5); }); Wails.Events.On("NoticeError", (msg) => { @@ -81,29 +87,29 @@ export default { Wails.Events.On("NoticeWarning", (msg) => { this.$message.warning(msg, 5); }); + //通知传参 + window.backend.App.SetVar(); + //检查更新 this.checkUpdate(); }, methods: { launchHLAE () { - // console.log("启动HLAE"); this.btnLaunchHLAE = true; window.backend.App.LaunchHLAE().then(ok => { if (ok === false) { this.$message.warning('HLAE启动失败', 5); } + this.btnLaunchHLAE = false; }); - this.btnLaunchHLAE = false; }, - tabSetting () { - console.log("切换到设置Tab页"); //TODO - //用于debug - this.checkUpdate() + manualUpdate () { + this.checkUpdate(); }, openDirHLAE () { - // console.log("打开HLAE安装位置"); this.btnOpenDir = true; - window.backend.App.OpenHlaeDirectory(); - this.btnOpenDir = false; + window.backend.App.OpenHlaeDirectory().then( () => { + this.btnOpenDir = false; + }); //发送wails信息->Go? // window.wails.Events.Emit("error", "这是一条错误信息!"); }, @@ -114,11 +120,10 @@ export default { selectOption() { //选择HLAE安装方法和安装位置 this.$confirm({ - title: '选择HLAE和FFmpeg的安装方式', - content: '附属安装:关联CSGO Demos Manager\n单独安装:单独选择位置安装', - okText: '附属安装', + title: () =>
选择HLAE的安装方式
, + content: () =>
· 关联CSGO Demos Manager安装

· 单独选择位置安装
, + okText: '关联安装', cancelText: '单独安装', - // bodyStyle: 'font-size: 20vw', onOk() { //选择完成,传给后端 window.backend.App.SetOption(false); @@ -135,10 +140,10 @@ export default { }, checkUpdate () { - // console.log("检查HLAE更新"); - this.btnOpenDir = true; //TODO 修改成update相关名称 - window.backend.App.CheckUpdate(); - this.btnOpenDir = false; + this.btnUpdate = true; + window.backend.App.CheckUpdate().then( () => { + this.btnUpdate = false; + }); } } } diff --git a/frontend/src/main.js b/frontend/src/main.js index 091c406..bd45428 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -12,6 +12,7 @@ import * as Wails from '@wailsapp/runtime'; Vue.use(Antd); + Wails.Init(() => { new Vue({ render: h => h(App)