mirror of
https://github.com/qinyuhang/ShadowsocksX-NG-R.git
synced 2026-10-21 15:25:49 +00:00
Using GCD to manage pingserver
Using GCD to manage pingserver, It should be after than before 😃
This commit is contained in:
@@ -59,23 +59,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
|
||||
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
||||
// Insert code here to initialize your application
|
||||
// PingServers.instance.ping()
|
||||
// let newInstance = PingTest.init(hostName: "www.baidu.com")
|
||||
// newInstance.start()
|
||||
|
||||
// let SerMgr = ServerProfileManager.instance
|
||||
// let pingServerQueue : DispatchQueue = DispatchQueue.global(priority: DispatchQueue.GlobalQueuePriority.high)
|
||||
//
|
||||
// for profile in SerMgr.profiles {
|
||||
// let host = profile.serverHost
|
||||
//
|
||||
// pingServerQueue.async(execute: {
|
||||
// print(profile.serverHost)
|
||||
// SimplePingClient().pingHostname(host) { latency in
|
||||
// print("-----------\(host) latency is \(latency ?? "fail")")}
|
||||
//// let pingInstance = PingTest.init(hostName: host)
|
||||
//// pingInstance.start()
|
||||
// })}
|
||||
NSUserNotificationCenter.default.delegate = self
|
||||
|
||||
// Prepare ss-local
|
||||
|
||||
@@ -94,17 +94,21 @@ class PingServers:NSObject{
|
||||
}
|
||||
|
||||
if i >= SerMgr.profiles.count{
|
||||
let notice = NSUserNotification()
|
||||
notice.title = "Ping测试完成!"
|
||||
notice.subtitle = "最快的是\(SerMgr.profiles[fastest_id].remark) \(SerMgr.profiles[fastest_id].serverHost) \(SerMgr.profiles[fastest_id].latency!)ms"
|
||||
NSUserNotificationCenter.default.deliver(notice)
|
||||
DispatchQueue.main.async {
|
||||
// do the UI update HERE
|
||||
let notice = NSUserNotification()
|
||||
notice.title = "Ping测试完成!"
|
||||
notice.subtitle = "最快的是\(self.SerMgr.profiles[self.fastest_id].remark) \(self.SerMgr.profiles[self.fastest_id].serverHost) \(self.SerMgr.profiles[self.fastest_id].latency!)ms"
|
||||
NSUserNotificationCenter.default.deliver(notice)
|
||||
}
|
||||
return
|
||||
}
|
||||
let host = SerMgr.profiles[i].serverHost
|
||||
let host = self.SerMgr.profiles[i].serverHost
|
||||
SimplePingClient.pingHostname(host) { latency in
|
||||
print("-----------\(host) latency is \(latency ?? "fail")")
|
||||
DispatchQueue.global().async {
|
||||
print("[Ping Result]-\(host) latency is \(latency ?? "fail")")
|
||||
self.SerMgr.profiles[i].latency = latency ?? "fail"
|
||||
|
||||
|
||||
if latency != nil {
|
||||
if self.fastest == nil{
|
||||
self.fastest = latency
|
||||
@@ -115,10 +119,13 @@ class PingServers:NSObject{
|
||||
self.fastest_id = i
|
||||
}
|
||||
}
|
||||
(NSApplication.shared().delegate as! AppDelegate).updateServersMenu()
|
||||
(NSApplication.shared().delegate as! AppDelegate).updateRunningModeMenu()
|
||||
DispatchQueue.main.async {
|
||||
// do the UI update HERE
|
||||
(NSApplication.shared().delegate as! AppDelegate).updateServersMenu()
|
||||
(NSApplication.shared().delegate as! AppDelegate).updateRunningModeMenu()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self.ping(i+1)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user