2018-10-09 14:18:10 +08:00
|
|
|
package main // import "github.com/yichengchen/clashX/ClashX"
|
2018-10-02 10:58:56 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"C"
|
|
|
|
|
|
|
|
"github.com/Dreamacro/clash/config"
|
|
|
|
"github.com/Dreamacro/clash/hub"
|
|
|
|
"github.com/Dreamacro/clash/proxy"
|
|
|
|
"github.com/Dreamacro/clash/tunnel"
|
2018-10-14 23:42:53 +08:00
|
|
|
"github.com/Dreamacro/clash/constant"
|
2018-10-02 10:58:56 +08:00
|
|
|
)
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
)
|
|
|
|
|
|
|
|
//export run
|
|
|
|
func run() *C.char {
|
|
|
|
tunnel.Instance().Run()
|
|
|
|
proxy.Instance().Run()
|
|
|
|
hub.Run()
|
|
|
|
|
|
|
|
config.Init()
|
|
|
|
err := config.Instance().Parse()
|
|
|
|
if err != nil {
|
|
|
|
return C.CString(err.Error())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return C.CString("success")
|
|
|
|
}
|
|
|
|
|
|
|
|
//export updateAllConfig
|
|
|
|
func updateAllConfig() *C.char {
|
|
|
|
err := config.Instance().Parse()
|
|
|
|
if err != nil {
|
|
|
|
return C.CString(err.Error())
|
|
|
|
}
|
|
|
|
return C.CString("")
|
|
|
|
}
|
|
|
|
|
2018-10-14 23:42:53 +08:00
|
|
|
//export setConfigHomeDir
|
|
|
|
func setConfigHomeDir(root string){
|
|
|
|
constant.SetHomeDir(root)
|
|
|
|
}
|
2018-10-02 10:58:56 +08:00
|
|
|
func main() {
|
|
|
|
run()
|
|
|
|
sigCh := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
<-sigCh
|
|
|
|
}
|