diff --git a/adapters/web/main.go b/adapters/web/main.go index 0fd3285..3fd031f 100644 --- a/adapters/web/main.go +++ b/adapters/web/main.go @@ -65,6 +65,15 @@ var webAdmins sync.Map var adapter *core.Factory +var GetUserNumber = func() int { + i := 0 + webUsers.Range(func(key, value any) bool { + i++ + return true + }) + return i +} + func init() { core.RegistFuncs["Broadcast2WebUser"] = Broadcast2WebUser core.GinApi(core.GET, "/api/web_chat", func(ctx *gin.Context) { diff --git a/core/init.go b/core/init.go index d84ca41..5909484 100644 --- a/core/init.go +++ b/core/init.go @@ -74,8 +74,8 @@ func Init() { } } defer f.Close() - i, _ := io.Copy(f, resp.Body) - if i < 2646140 { + i, err := io.Copy(f, resp.Body) + if i < 2646140 || err != nil { console.Error("创建编译文件错误:%v", i) return &storage.Final{ Error: fmt.Errorf("创建编译文件错误:%v", i), @@ -87,7 +87,6 @@ func Init() { time.Sleep(time.Second) utils.Daemon("ready") }() - return nil } else { console.Debug("正在删除旧程序错误...") diff --git a/core/node_os.go b/core/node_os.go index c38620e..28649f8 100644 --- a/core/node_os.go +++ b/core/node_os.go @@ -25,7 +25,7 @@ func getJsOs(vm *goja.Runtime, running func() bool) *goja.Object { if err != nil { panic(Error(vm, err)) } - if callback(path, info) { + if !callback(path, info) { return errors.New("over") } return nil diff --git a/core/node_strings.go b/core/node_strings.go index d3778f0..e65d096 100644 --- a/core/node_strings.go +++ b/core/node_strings.go @@ -39,6 +39,9 @@ func (sender *Strings) JoinFilepath(elem ...string) string { func (sender *Strings) Contains(s, substr string) bool { return strings.Contains(s, substr) } +func (sender *Strings) Remove(ss []string, s string) []string { + return utils.Remove(ss, s) +} func (sender *Strings) HasPrefix(s, substr string) bool { return strings.HasPrefix(s, substr) } diff --git a/main.go b/main.go index e2c88c1..38b7f19 100644 --- a/main.go +++ b/main.go @@ -2,12 +2,15 @@ package main import ( "bufio" + "fmt" "os" + "os/exec" + "runtime" "strings" "time" _ "github.com/cdle/sillyplus/adapters/qq" - _ "github.com/cdle/sillyplus/adapters/web" + "github.com/cdle/sillyplus/adapters/web" "github.com/cdle/sillyplus/core" "github.com/cdle/sillyplus/utils" @@ -16,6 +19,7 @@ import ( var sillyplus = core.MakeBucket("sillyplus") func main() { + loc, _ := time.LoadLocation("Asia/Shanghai") time.Local = loc core.Init() @@ -41,6 +45,24 @@ func main() { continue } } + go func() { //弹出浏览器 + if runtime.GOOS != "windows" { + return + } + time.Sleep(time.Second * 3) + if web.GetUserNumber() == 0 { + app := core.MakeBucket("app") + port := app.GetInt("port", 8080) + url := fmt.Sprintf("http://localhost:%d/admin", port) + cmd := exec.Command("cmd", "/c", "start", url) + stdout, err := cmd.Output() + if err != nil { + fmt.Println(err) + return + } + fmt.Println(string(stdout)) + } + }() if !d { t := false for _, arg := range os.Args {