chore: update external-ui

This commit is contained in:
xishang0128 2023-09-20 14:23:58 +08:00
parent 20fafdca65
commit 8b518161a3
2 changed files with 14 additions and 10 deletions

View file

@ -608,6 +608,8 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
return nil, err
}
}
} else {
ExternalUIFolder = ExternalUIPath
}
cfg.Tun.RedirectToTun = cfg.EBpf.RedirectToTun

View file

@ -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)
}