From 8b518161a308c1295aa9a83b185e782b6b7e9211 Mon Sep 17 00:00:00 2001 From: xishang0128 Date: Wed, 20 Sep 2023 14:23:58 +0800 Subject: [PATCH] chore: update external-ui --- config/config.go | 2 ++ config/update_ui.go | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/config/config.go b/config/config.go index 66815274..d0e69e49 100644 --- a/config/config.go +++ b/config/config.go @@ -608,6 +608,8 @@ func parseGeneral(cfg *RawConfig) (*General, error) { return nil, err } } + } else { + ExternalUIFolder = ExternalUIPath } cfg.Tun.RedirectToTun = cfg.EBpf.RedirectToTun diff --git a/config/update_ui.go b/config/update_ui.go index 81b5bb03..5bc2596e 100644 --- a/config/update_ui.go +++ b/config/update_ui.go @@ -9,6 +9,8 @@ import ( "path/filepath" "strings" "sync" + + C "github.com/Dreamacro/clash/constant" ) var ( @@ -24,29 +26,29 @@ func UpdateUI() error { xdMutex.Lock() defer xdMutex.Unlock() - if ExternalUIPath == "" || ExternalUIFolder == "" || ExternalUIName == "" { + if ExternalUIPath == "" || ExternalUIFolder == "" { return fmt.Errorf("ExternalUI configure incomplete") } - err := cleanup(ExternalUIFolder) - if err != nil { - if !os.IsNotExist(err) { - return fmt.Errorf("cleanup exist file error: %w", err) - } - } - data, err := downloadForBytes(ExternalUIURL) if err != nil { return fmt.Errorf("can't download file: %w", err) } - saved := path.Join(ExternalUIPath, "download.zip") + saved := path.Join(C.Path.HomeDir(), "download.zip") if saveFile(data, saved) != nil { return fmt.Errorf("can't save zip file: %w", err) } defer os.Remove(saved) - unzipFolder, err := unzip(saved, ExternalUIPath) + err = cleanup(ExternalUIFolder) + if err != nil { + if !os.IsNotExist(err) { + return fmt.Errorf("cleanup exist file error: %w", err) + } + } + + unzipFolder, err := unzip(saved, C.Path.HomeDir()) if err != nil { return fmt.Errorf("can't extract zip file: %w", err) }