From 8d55a86c060d307273ba6bdbf0b8a2b31aeefd85 Mon Sep 17 00:00:00 2001 From: putyy Date: Sun, 14 Sep 2025 21:40:28 +0800 Subject: [PATCH] feat: add loading check --- core/app.go | 28 +++++++++++++++++ core/bind.go | 9 ++++++ frontend/src/locales/en.json | 6 +++- frontend/src/locales/zh.json | 6 +++- frontend/src/views/index.vue | 48 ++++++++++++++++++++++++++---- frontend/wailsjs/go/core/Bind.d.ts | 2 ++ frontend/wailsjs/go/core/Bind.js | 4 +++ 7 files changed, 95 insertions(+), 8 deletions(-) diff --git a/core/app.go b/core/app.go index 3998df7..11e299a 100644 --- a/core/app.go +++ b/core/app.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/vrischmann/userdir" "os" + "os/exec" "path/filepath" "regexp" "res-downloader/core/shared" @@ -25,6 +26,7 @@ type App struct { PublicCrt []byte `json:"-"` PrivateKey []byte `json:"-"` IsProxy bool `json:"IsProxy"` + IsReset bool `json:"-"` } var ( @@ -51,6 +53,7 @@ func GetApp(assets embed.FS, wjs string) *App { Version: version, Description: "res-downloader是一款集网络资源嗅探 + 高速下载功能于一体的软件,高颜值、高性能和多样化,提供个人用户下载自己上传到各大平台的网络资源功能!", Copyright: "Copyright © 2023~" + strconv.Itoa(time.Now().Year()), + IsReset: false, PublicCrt: []byte(`-----BEGIN CERTIFICATE----- MIIDwzCCAqugAwIBAgIUFAnC6268dp/z1DR9E1UepiWgWzkwDQYJKoZIhvcNAQEL BQAwcDELMAkGA1UEBhMCQ04xEjAQBgNVBAgMCUNob25ncWluZzESMBAGA1UEBwwJ @@ -129,6 +132,10 @@ func (a *App) Startup(ctx context.Context) { func (a *App) OnExit() { a.UnsetSystemProxy() globalLogger.Close() + if appOnce.IsReset { + err := a.ResetApp() + fmt.Println("err:", err) + } } func (a *App) installCert() (string, error) { @@ -179,3 +186,24 @@ func (a *App) lock() error { } return nil } + +func (a *App) ResetApp() error { + exePath, err := os.Executable() + if err != nil { + return err + } + + exePath, err = filepath.Abs(exePath) + if err != nil { + return err + } + + _ = os.Remove(filepath.Join(appOnce.UserDir, "install.lock")) + _ = os.Remove(filepath.Join(appOnce.UserDir, "pass.cache")) + _ = os.Remove(filepath.Join(appOnce.UserDir, "config.json")) + _ = os.Remove(filepath.Join(appOnce.UserDir, "cert.crt")) + + cmd := exec.Command(exePath) + cmd.Start() + return nil +} diff --git a/core/bind.go b/core/bind.go index b20af32..4c80e46 100644 --- a/core/bind.go +++ b/core/bind.go @@ -1,5 +1,9 @@ package core +import ( + "github.com/wailsapp/wails/v2/pkg/runtime" +) + type Bind struct { } @@ -14,3 +18,8 @@ func (b *Bind) Config() *ResponseData { func (b *Bind) AppInfo() *ResponseData { return httpServerOnce.buildResp(1, "ok", appOnce) } + +func (b *Bind) ResetApp() { + appOnce.IsReset = true + runtime.Quit(appOnce.ctx) +} diff --git a/frontend/src/locales/en.json b/frontend/src/locales/en.json index 390c1f6..710cfc1 100644 --- a/frontend/src/locales/en.json +++ b/frontend/src/locales/en.json @@ -84,7 +84,11 @@ "win_install_tip": "For the first time using this software, please right-click and select 'Run as administrator'", "download_queued": "Download has been added to the queue, current queue length:{count}", "search": "Search", - "search_description": "Keyword Search..." + "search_description": "Keyword Search...", + "start_err_tip": "Error Message", + "start_err_content": "The current startup process has encountered an issue. Do you want to reset the application?", + "start_err_positiveText": "Clear cache and restart", + "start_err_negativeText": "Close the software" }, "setting": { "restart_tip": "Keep default if unsure, please restart software after modification", diff --git a/frontend/src/locales/zh.json b/frontend/src/locales/zh.json index 88b0e58..2e33bd1 100644 --- a/frontend/src/locales/zh.json +++ b/frontend/src/locales/zh.json @@ -84,7 +84,11 @@ "win_install_tip": "首次启用本软件,请使用鼠标右键选择以管理员身份运行", "download_queued": "下载已加入队列,当前队列长度:{count}", "search": "搜索", - "search_description": "关键字搜索..." + "search_description": "关键字搜索...", + "start_err_tip": "错误提示", + "start_err_content": "当前启动过程遇到了问题,是否重置应用?", + "start_err_positiveText": "清理缓存并重启", + "start_err_negativeText": "关闭软件" }, "setting": { "restart_tip": "如果不清楚保持默认就行,修改后请重启软件", diff --git a/frontend/src/views/index.vue b/frontend/src/views/index.vue index 2bfa5e5..ce6aa96 100644 --- a/frontend/src/views/index.vue +++ b/frontend/src/views/index.vue @@ -51,7 +51,7 @@ {{ t('index.cancel_down') }} - +