2024-07-17 17:02:25 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import "C"
|
|
|
|
|
import (
|
2024-09-26 14:29:04 +08:00
|
|
|
"core/state"
|
2024-07-17 17:02:25 +08:00
|
|
|
"encoding/json"
|
|
|
|
|
"fmt"
|
|
|
|
|
)
|
|
|
|
|
|
2024-09-26 14:29:04 +08:00
|
|
|
//export getCurrentProfileName
|
|
|
|
|
func getCurrentProfileName() *C.char {
|
|
|
|
|
if state.CurrentState == nil {
|
|
|
|
|
return C.CString("")
|
|
|
|
|
}
|
|
|
|
|
return C.CString(state.CurrentState.CurrentProfileName)
|
2024-07-26 08:05:22 +08:00
|
|
|
}
|
|
|
|
|
|
2024-09-26 14:29:04 +08:00
|
|
|
//export getAndroidVpnOptions
|
|
|
|
|
func getAndroidVpnOptions() *C.char {
|
|
|
|
|
options := state.AndroidVpnOptions{
|
|
|
|
|
Enable: state.CurrentState.Enable,
|
|
|
|
|
Port: state.CurrentRawConfig.MixedPort,
|
|
|
|
|
Ipv4Address: state.DefaultIpv4Address,
|
|
|
|
|
Ipv6Address: state.GetIpv6Address(),
|
|
|
|
|
AccessControl: state.CurrentState.AccessControl,
|
|
|
|
|
SystemProxy: state.CurrentState.SystemProxy,
|
|
|
|
|
AllowBypass: state.CurrentState.AllowBypass,
|
2024-11-09 20:17:57 +08:00
|
|
|
RouteAddress: state.CurrentState.RouteAddress,
|
2024-09-26 14:29:04 +08:00
|
|
|
BypassDomain: state.CurrentState.BypassDomain,
|
|
|
|
|
DnsServerAddress: state.GetDnsServerAddress(),
|
|
|
|
|
}
|
|
|
|
|
data, err := json.Marshal(options)
|
2024-07-17 17:02:25 +08:00
|
|
|
if err != nil {
|
|
|
|
|
fmt.Println("Error:", err)
|
|
|
|
|
return C.CString("")
|
|
|
|
|
}
|
|
|
|
|
return C.CString(string(data))
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-26 08:05:22 +08:00
|
|
|
//export setState
|
|
|
|
|
func setState(s *C.char) {
|
2024-07-17 17:02:25 +08:00
|
|
|
paramsString := C.GoString(s)
|
2024-09-26 14:29:04 +08:00
|
|
|
err := json.Unmarshal([]byte(paramsString), state.CurrentState)
|
2024-07-17 17:02:25 +08:00
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|