feat: 细化配置文件,不兼容性更新

This commit is contained in:
Mmx
2021-11-25 08:25:03 +08:00
parent 5aa82c3fd9
commit 884934b951
5 changed files with 23 additions and 7 deletions

View File

@@ -16,7 +16,7 @@ type daemon struct {
var Daemon = daemon{ var Daemon = daemon{
Mark: fmt.Sprint(time.Now().UnixNano()), Mark: fmt.Sprint(time.Now().UnixNano()),
Path: ".autoLoginDaemon", Path: global.Config.Settings.Daemon.Path,
} }
func init() { func init() {

View File

@@ -35,7 +35,7 @@ func Guardian(output bool) {
c <- false c <- false
}() }()
<-c <-c
time.Sleep(time.Duration(global.Config.Settings.Guardian) * time.Second) time.Sleep(time.Duration(global.Config.Settings.Guardian.Duration) * time.Second)
} }
} }
@@ -43,7 +43,7 @@ func EnterGuardian() {
global.Status.Output = true global.Status.Output = true
global.Status.Guardian = true global.Status.Guardian = true
util.Log.Println("[Guardian mode]") util.Log.Println("[Guardian mode]")
if global.Config.Settings.Daemon { if global.Config.Settings.Daemon.Enable {
if err := exec.Command(os.Args[0], "-daemon").Start(); err != nil { if err := exec.Command(os.Args[0], "-daemon").Start(); err != nil {
util.Log.Fatalln(err) util.Log.Fatalln(err)
} }

View File

@@ -16,7 +16,7 @@ func init() {
if e := config.Load(config.Options{ if e := config.Load(config.Options{
Config: &Config, Config: &Config,
Default: &models.Config{ Default: &models.Config{
From: models.LoginForm{ Form: models.LoginForm{
Domain: "www.msftconnecttest.com", Domain: "www.msftconnecttest.com",
UserType: "cmcc", UserType: "cmcc",
}, },
@@ -28,6 +28,12 @@ func init() {
}, },
Settings: models.Settings{ Settings: models.Settings{
Timeout: 1, Timeout: 1,
Daemon: models.Daemon{
Path: ".autoLogin",
},
Guardian: models.Guardian{
Duration: 300,
},
}, },
}, },
Path: Flags.Path, Path: Flags.Path,

View File

@@ -9,7 +9,7 @@ import (
func main() { func main() {
defer util.Log.CatchRecover() defer util.Log.CatchRecover()
if global.Config.Settings.Guardian != 0 { if global.Config.Settings.Guardian.Enable {
controllers.EnterGuardian() controllers.EnterGuardian()
} else if err := controllers.Login(true, false); err != nil { } else if err := controllers.Login(true, false); err != nil {
util.Log.Println("运行出错,状态异常") util.Log.Println("运行出错,状态异常")

View File

@@ -1,10 +1,20 @@
package models package models
type Daemon struct {
Enable bool `json:"enable"`
Path string `json:"path"`
}
type Guardian struct {
Enable bool `json:"enable"`
Duration uint `json:"duration"`
}
type Settings struct { type Settings struct {
Timeout uint `json:"timeout"` Timeout uint `json:"timeout"`
DemoMode bool `json:"demo_mode"` DemoMode bool `json:"demo_mode"`
Guardian uint `json:"guardian"` Guardian Guardian
Daemon bool `json:"daemon"` Daemon Daemon
} }
type Config struct { type Config struct {