chore: auto download external UI when 'external-ui' is set and not empty

This commit is contained in:
Larvan2
2024-08-13 14:19:34 +08:00
parent 5bf22422d9
commit 50d0cd363c
5 changed files with 23 additions and 10 deletions

View File

@@ -23,6 +23,7 @@ import (
"github.com/metacubex/mihomo/component/resolver"
SNI "github.com/metacubex/mihomo/component/sniffer"
"github.com/metacubex/mihomo/component/trie"
"github.com/metacubex/mihomo/component/updater"
"github.com/metacubex/mihomo/config"
C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/constant/features"
@@ -113,6 +114,7 @@ func ApplyConfig(cfg *config.Config, force bool) {
runtime.GC()
tunnel.OnRunning()
hcCompatibleProvider(cfg.Providers)
initExternalUI()
log.SetLevel(cfg.General.LogLevel)
}
@@ -385,6 +387,18 @@ func updateTunnels(tunnels []LC.Tunnel) {
listener.PatchTunnel(tunnels, tunnel.Tunnel)
}
func initExternalUI() {
if updater.ExternalUIFolder != "" {
dirEntries, _ := os.ReadDir(updater.ExternalUIFolder)
if len(dirEntries) > 0 {
log.Infoln("UI already exists")
} else {
log.Infoln("UI not exists, downloading")
updater.UpdateUI()
}
}
}
func updateGeneral(general *config.General) {
tunnel.SetMode(general.Mode)
tunnel.SetFindProcessMode(general.FindProcessMode)