1
0

script.go 814 B

1234567891011121314151617181920212223242526272829303132
  1. package surge
  2. import (
  3. "github.com/sagernet/sing-box/script/jsc"
  4. "github.com/sagernet/sing-box/script/modules/boxctx"
  5. F "github.com/sagernet/sing/common/format"
  6. )
  7. type Script struct {
  8. class jsc.Class[*Module, *Script]
  9. ScriptType string
  10. }
  11. func createScript(module *Module) jsc.Class[*Module, *Script] {
  12. class := jsc.NewClass[*Module, *Script](module)
  13. class.DefineField("name", (*Script).getName, nil)
  14. class.DefineField("type", (*Script).getType, nil)
  15. class.DefineField("startTime", (*Script).getStartTime, nil)
  16. return class
  17. }
  18. func (s *Script) getName() any {
  19. return F.ToString("script:", boxctx.MustFromRuntime(s.class.Runtime()).Tag)
  20. }
  21. func (s *Script) getType() any {
  22. return s.ScriptType
  23. }
  24. func (s *Script) getStartTime() any {
  25. return boxctx.MustFromRuntime(s.class.Runtime()).StartedAt
  26. }