state.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package main
  2. import "C"
  3. import (
  4. "encoding/json"
  5. "fmt"
  6. )
  7. type AccessControl struct {
  8. Mode string `json:"mode"`
  9. AcceptList []string `json:"acceptList"`
  10. RejectList []string `json:"rejectList"`
  11. IsFilterSystemApp bool `json:"isFilterSystemApp"`
  12. }
  13. type AndroidProps struct {
  14. Enable bool `json:"enable"`
  15. AccessControl *AccessControl `json:"accessControl"`
  16. AllowBypass bool `json:"allowBypass"`
  17. SystemProxy bool `json:"systemProxy"`
  18. }
  19. type State struct {
  20. AndroidProps
  21. CurrentProfileName string `json:"currentProfileName"`
  22. MixedPort int `json:"mixedPort"`
  23. OnlyProxy bool `json:"onlyProxy"`
  24. }
  25. var state State
  26. //export getState
  27. func getState() *C.char {
  28. data, err := json.Marshal(state)
  29. if err != nil {
  30. fmt.Println("Error:", err)
  31. return C.CString("")
  32. }
  33. return C.CString(string(data))
  34. }
  35. //export setState
  36. func setState(s *C.char) {
  37. paramsString := C.GoString(s)
  38. err := json.Unmarshal([]byte(paramsString), &state)
  39. if err != nil {
  40. return
  41. }
  42. }