From 334f5bbcf0e056f6dc6bfdc3c09dfdba07ce9abb Mon Sep 17 00:00:00 2001 From: Mmx <1624045573@qq.com> Date: Sun, 19 Sep 2021 20:54:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=87=8D=E6=9E=84=E5=AE=88=E6=8A=A4?= =?UTF-8?q?=E5=85=A5=E5=8F=A3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/guardian.go | 2 +- controllers/login.go | 4 ++-- main.go | 13 +++++-------- models/config.go | 10 ++++------ 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/controllers/guardian.go b/controllers/guardian.go index 9f7a275..100c012 100644 --- a/controllers/guardian.go +++ b/controllers/guardian.go @@ -21,7 +21,6 @@ func Guardian(output bool) { os.Exit(1) } global.Status.Output = output - time.Sleep(time.Duration(global.Config.Settings.Guardian) * time.Second) go func() { defer func() { _ = recover() @@ -37,6 +36,7 @@ func Guardian(output bool) { c <- false }() <-c + time.Sleep(time.Duration(global.Config.Settings.Guardian) * time.Second) } } diff --git a/controllers/login.go b/controllers/login.go index 8ba20c1..9372a64 100644 --- a/controllers/login.go +++ b/controllers/login.go @@ -15,8 +15,8 @@ func Login(output bool) error { util.Log.Println("Step0: 检查状态…") G := global.Config.Generate() - if !global.Status.Guardian && global.Config.Settings.QuitIfNetOk && util.Checker.NetOk() { - util.Log.Println("网络正常,程序退出") + if util.Checker.NetOk() { + util.Log.Println("网络 ok") return nil } diff --git a/main.go b/main.go index c241f6c..b198430 100644 --- a/main.go +++ b/main.go @@ -4,23 +4,20 @@ import ( "autoLogin/controllers" "autoLogin/global" "autoLogin/util" - "os" ) func main() { defer util.Log.CatchRecover() - if err := controllers.Login(true); err != nil { + if global.Config.Settings.Guardian != 0 { + controllers.EnterGuardian() + } else if err := controllers.Login(true); err != nil { util.Log.Println("运行出错,状态异常") - if global.Config.Settings.ForceGuardianEvenFailed { - util.Log.Println(err) - } else if global.Config.Settings.DemoMode { + if global.Config.Settings.DemoMode { util.Log.Fatalln(err) } else { util.Log.Println(err) - os.Exit(3) + return } } - - controllers.EnterGuardian() } diff --git a/models/config.go b/models/config.go index ef81f59..e65d810 100644 --- a/models/config.go +++ b/models/config.go @@ -6,12 +6,10 @@ import ( ) type Settings struct { - QuitIfNetOk bool `json:"quit_if_net_ok"` - DemoMode bool `json:"demo_mode"` - Dns string `json:"dns"` - Guardian uint `json:"guardian"` - Daemon bool `json:"daemon"` - ForceGuardianEvenFailed bool `json:"force_guardian_even_failed"` + DemoMode bool `json:"demo_mode"` + Dns string `json:"dns"` + Guardian uint `json:"guardian"` + Daemon bool `json:"daemon"` } type Config struct {