Skip to content

Commit

Permalink
optimize: improve remote control reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
yichengchen committed Jul 10, 2020
1 parent 7b295cc commit f695bc8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
23 changes: 18 additions & 5 deletions ClashX/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
self.apiPortMenuItem.title = "Api Port: \(ConfigManager.shared.apiPort)"
self.ipMenuItem.title = "IP: \(NetworkChangeNotifier.getPrimaryIPAddress() ?? "")"

ClashStatusTool.checkPortConfig(cfg: config)
if RemoteControlManager.selectConfig == nil {
ClashStatusTool.checkPortConfig(cfg: config)
}

}.disposed(by: disposeBag)
}
Expand Down Expand Up @@ -307,6 +309,17 @@ class AppDelegate: NSObject, NSApplicationDelegate {
Logger.log("proxy changed to no clashX setting: \(rawProxy)", level: .warning)
NSUserNotificationCenter.default.postProxyChangeByOtherAppNotice()
}.disposed(by: disposeBag)

NotificationCenter
.default
.rx
.notification(.systemNetworkStatusIPUpdate).map({ _ in
NetworkChangeNotifier.getPrimaryIPAddress(allowIPV6: false)
}).bind { [weak self] _ in
if RemoteControlManager.selectConfig != nil {
self?.resetStreamApi()
}
}.disposed(by: disposeBag)
}

func updateProxyList(withMenus menus: [NSMenuItem]) {
Expand Down Expand Up @@ -457,6 +470,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
SystemProxyManager.shared.disableProxy()
SystemProxyManager.shared.enableProxy()
}

if RemoteControlManager.selectConfig != nil {
resetStreamApi()
}
}

@objc func healthHeckOnNetworkChange() {
Expand All @@ -469,10 +486,6 @@ class AppDelegate: NSObject, NSApplicationDelegate {
}
}
}

if RemoteControlManager.selectConfig != nil {
resetStreamApi()
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions ClashX/General/ApiRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ApiRequest {

static func useDirectApi() -> Bool {
if ConfigManager.shared.overrideApiURL != nil {
return true
return false
}
return ConfigManager.builtInApiMode
}
Expand Down Expand Up @@ -412,7 +412,7 @@ extension ApiRequest: WebSocketDelegate {
[weak self] _ in
if self?.loggingWebSocket?.isConnected == true { return }
self?.requestLog()
})
})
loggingWebSocketRetryDelay *= 2
}
}
Expand Down

0 comments on commit f695bc8

Please sign in to comment.