mirror of
https://github.com/putyy/res-downloader.git
synced 2026-01-12 14:14:55 +08:00
feat: add loading check
This commit is contained in:
28
core/app.go
28
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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user