This commit is contained in:
cdle
2023-06-08 07:14:50 +08:00
parent 78a0943966
commit bc96db7ba3
5 changed files with 38 additions and 5 deletions
+9
View File
@@ -65,6 +65,15 @@ var webAdmins sync.Map
var adapter *core.Factory var adapter *core.Factory
var GetUserNumber = func() int {
i := 0
webUsers.Range(func(key, value any) bool {
i++
return true
})
return i
}
func init() { func init() {
core.RegistFuncs["Broadcast2WebUser"] = Broadcast2WebUser core.RegistFuncs["Broadcast2WebUser"] = Broadcast2WebUser
core.GinApi(core.GET, "/api/web_chat", func(ctx *gin.Context) { core.GinApi(core.GET, "/api/web_chat", func(ctx *gin.Context) {
+2 -3
View File
@@ -74,8 +74,8 @@ func Init() {
} }
} }
defer f.Close() defer f.Close()
i, _ := io.Copy(f, resp.Body) i, err := io.Copy(f, resp.Body)
if i < 2646140 { if i < 2646140 || err != nil {
console.Error("创建编译文件错误:%v", i) console.Error("创建编译文件错误:%v", i)
return &storage.Final{ return &storage.Final{
Error: fmt.Errorf("创建编译文件错误:%v", i), Error: fmt.Errorf("创建编译文件错误:%v", i),
@@ -87,7 +87,6 @@ func Init() {
time.Sleep(time.Second) time.Sleep(time.Second)
utils.Daemon("ready") utils.Daemon("ready")
}() }()
return nil return nil
} else { } else {
console.Debug("正在删除旧程序错误...") console.Debug("正在删除旧程序错误...")
+1 -1
View File
@@ -25,7 +25,7 @@ func getJsOs(vm *goja.Runtime, running func() bool) *goja.Object {
if err != nil { if err != nil {
panic(Error(vm, err)) panic(Error(vm, err))
} }
if callback(path, info) { if !callback(path, info) {
return errors.New("over") return errors.New("over")
} }
return nil return nil
+3
View File
@@ -39,6 +39,9 @@ func (sender *Strings) JoinFilepath(elem ...string) string {
func (sender *Strings) Contains(s, substr string) bool { func (sender *Strings) Contains(s, substr string) bool {
return strings.Contains(s, substr) 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 { func (sender *Strings) HasPrefix(s, substr string) bool {
return strings.HasPrefix(s, substr) return strings.HasPrefix(s, substr)
} }
+23 -1
View File
@@ -2,12 +2,15 @@ package main
import ( import (
"bufio" "bufio"
"fmt"
"os" "os"
"os/exec"
"runtime"
"strings" "strings"
"time" "time"
_ "github.com/cdle/sillyplus/adapters/qq" _ "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/core"
"github.com/cdle/sillyplus/utils" "github.com/cdle/sillyplus/utils"
@@ -16,6 +19,7 @@ import (
var sillyplus = core.MakeBucket("sillyplus") var sillyplus = core.MakeBucket("sillyplus")
func main() { func main() {
loc, _ := time.LoadLocation("Asia/Shanghai") loc, _ := time.LoadLocation("Asia/Shanghai")
time.Local = loc time.Local = loc
core.Init() core.Init()
@@ -41,6 +45,24 @@ func main() {
continue 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 { if !d {
t := false t := false
for _, arg := range os.Args { for _, arg := range os.Args {