14.04.2026 Update
This commit is contained in:
@@ -4,12 +4,14 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"alpine-router/mihomo"
|
||||
"nano-router/config"
|
||||
"nano-router/mihomo"
|
||||
)
|
||||
|
||||
func HandleMihomoStatus(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -29,6 +31,7 @@ func HandleMihomoStart(w http.ResponseWriter, r *http.Request) {
|
||||
fail(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
saveMihomoEnabled(true)
|
||||
ok(w, map[string]string{"message": "mihomo started"})
|
||||
}
|
||||
|
||||
@@ -41,6 +44,7 @@ func HandleMihomoStop(w http.ResponseWriter, r *http.Request) {
|
||||
fail(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
saveMihomoEnabled(false)
|
||||
ok(w, map[string]string{"message": "mihomo stopped"})
|
||||
}
|
||||
|
||||
@@ -53,9 +57,24 @@ func HandleMihomoRestart(w http.ResponseWriter, r *http.Request) {
|
||||
fail(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
// Restart keeps enabled=true (already set when it was first started).
|
||||
ok(w, map[string]string{"message": "mihomo restarted"})
|
||||
}
|
||||
|
||||
// saveMihomoEnabled persists mihomo.enabled to config.yaml so the binary
|
||||
// auto-starts Mihomo on the next launch when enabled=true.
|
||||
func saveMihomoEnabled(enabled bool) {
|
||||
cfg, err := config.Load()
|
||||
if err != nil {
|
||||
log.Printf("Warning: load config to save mihomo enabled: %v", err)
|
||||
return
|
||||
}
|
||||
cfg.Mihomo.Enabled = enabled
|
||||
if err := config.Save(cfg); err != nil {
|
||||
log.Printf("Warning: save mihomo enabled state: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func HandleMihomoConfig(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.Method {
|
||||
case http.MethodGet:
|
||||
|
||||
Reference in New Issue
Block a user