Skip to content

Commit

Permalink
improve: try fix "open port fail" error.
Browse files Browse the repository at this point in the history
  • Loading branch information
yichengchen committed May 16, 2020
1 parent 42d3d17 commit ebab2f6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
6 changes: 4 additions & 2 deletions ClashX/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
setupData()
runAfterConfigReload = { [weak self] in
self?.selectOutBoundModeWithMenory()
self?.selectAllowLanWithMenory()
if !ConfigManager.builtInApiMode {
self?.selectAllowLanWithMenory()
}
}
updateConfig(showNotification: false)
updateLoggingLevel()
Expand Down Expand Up @@ -353,7 +355,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}

Logger.log("Trying start proxy")
let string = run(ConfigManager.builtInApiMode.goObject())?.toString() ?? ""
let string = run(ConfigManager.builtInApiMode.goObject(), ConfigManager.allowConnectFromLan.goObject())?.toString() ?? ""
let jsonData = string.data(using: .utf8) ?? Data()
if let res = try? JSONDecoder().decode(StartProxyResp.self, from: jsonData) {
let port = res.externalController.components(separatedBy: ":").last ?? "9090"
Expand Down
2 changes: 1 addition & 1 deletion ClashX/goClash/go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/yichengchen/clashX/ClashX

require (
github.com/Dreamacro/clash v0.20.1-0.20200508135217-3638b077cdc5
github.com/Dreamacro/clash v0.20.1-0.20200512032953-3a27cfc4a130
github.com/oschwald/geoip2-golang v1.4.0
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
)
Expand Down
4 changes: 2 additions & 2 deletions ClashX/goClash/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/Dreamacro/clash v0.20.1-0.20200508135217-3638b077cdc5 h1:0B7URouk7YzZoVOTNl6/rTCvu39+zFe7sroCVf6RT0Y=
github.com/Dreamacro/clash v0.20.1-0.20200508135217-3638b077cdc5/go.mod h1:KiPMTu1n6emQzUyY/A7W4mZYzQLfhToryDUp8ypta7E=
github.com/Dreamacro/clash v0.20.1-0.20200512032953-3a27cfc4a130 h1:d4iusQxlY7rPXzkIUIczLZazoRXusB1bEth07CkPVY8=
github.com/Dreamacro/clash v0.20.1-0.20200512032953-3a27cfc4a130/go.mod h1:KiPMTu1n6emQzUyY/A7W4mZYzQLfhToryDUp8ypta7E=
github.com/Dreamacro/go-shadowsocks2 v0.1.5 h1:BizWSjmwzAyQoslz6YhJYMiAGT99j9cnm9zlxVr+kyI=
github.com/Dreamacro/go-shadowsocks2 v0.1.5/go.mod h1:LSXCjyHesPY3pLjhwff1mQX72ItcBT/N2xNC685cYeU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
8 changes: 4 additions & 4 deletions ClashX/goClash/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func initClashCore() {
constant.SetConfig(configFile)
}

func parseConfig(checkPort bool) (*config.Config, error) {
func parseDefaultConfigThenStart(checkPort, allowLan bool) (*config.Config, error) {
cfg, err := executor.Parse()
if err != nil {
return nil, err
Expand All @@ -50,8 +50,8 @@ func parseConfig(checkPort bool) (*config.Config, error) {
cfg.General.ExternalController = "127.0.0.1:" + strconv.Itoa(port)
cfg.General.Secret = ""
}
cfg.General.AllowLan = allowLan
}

go route.Start(cfg.General.ExternalController, cfg.General.Secret)

executor.ApplyConfig(cfg, true)
Expand All @@ -74,8 +74,8 @@ func verifyClashConfig(content *C.char) *C.char {
}

//export run
func run(checkConfig bool) *C.char {
cfg, err := parseConfig(checkConfig)
func run(checkConfig, allowLan bool) *C.char {
cfg, err := parseDefaultConfigThenStart(checkConfig,allowLan)
if err != nil {
return C.CString(err.Error())
}
Expand Down

0 comments on commit ebab2f6

Please sign in to comment.