Skip to content

Commit

Permalink
chore: update external-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
xishang0128 committed Sep 20, 2023
1 parent 20fafdc commit 8b51816
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,8 @@ func parseGeneral(cfg *RawConfig) (*General, error) {
return nil, err
}
}
} else {
ExternalUIFolder = ExternalUIPath
}

cfg.Tun.RedirectToTun = cfg.EBpf.RedirectToTun
Expand Down
22 changes: 12 additions & 10 deletions config/update_ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"path/filepath"
"strings"
"sync"

C "github.com/Dreamacro/clash/constant"
)

var (
Expand All @@ -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)
}
Expand Down

0 comments on commit 8b51816

Please sign in to comment.