Feature: show delay in menu after speed test
This commit is contained in:
parent
19a92b9e50
commit
132f4b61d0
@ -11,6 +11,7 @@
|
||||
4913C82321157D0200F6B87C /* Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4913C82221157D0200F6B87C /* Notification.swift */; };
|
||||
492C4869210EE6B9004554A0 /* ApiRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 492C4868210EE6B9004554A0 /* ApiRequest.swift */; };
|
||||
492C4871210EF62E004554A0 /* ClashConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 492C4870210EF62E004554A0 /* ClashConfig.swift */; };
|
||||
4931969B21631E5E00A8E6E7 /* SpeedDataRecorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4931969A21631E5D00A8E6E7 /* SpeedDataRecorder.swift */; };
|
||||
4949D154213242F600EF85E6 /* Paths.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4949D153213242F600EF85E6 /* Paths.swift */; };
|
||||
4949D15D2132614B00EF85E6 /* QRCodeUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4949D15C2132614B00EF85E6 /* QRCodeUtil.swift */; };
|
||||
4952C3BF2115C7CA004A4FA8 /* ProxyMenuItemFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4952C3BE2115C7CA004A4FA8 /* ProxyMenuItemFactory.swift */; };
|
||||
@ -104,6 +105,7 @@
|
||||
4913C82221157D0200F6B87C /* Notification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notification.swift; sourceTree = "<group>"; };
|
||||
492C4868210EE6B9004554A0 /* ApiRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApiRequest.swift; sourceTree = "<group>"; };
|
||||
492C4870210EF62E004554A0 /* ClashConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClashConfig.swift; sourceTree = "<group>"; };
|
||||
4931969A21631E5D00A8E6E7 /* SpeedDataRecorder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpeedDataRecorder.swift; sourceTree = "<group>"; };
|
||||
4949D153213242F600EF85E6 /* Paths.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Paths.swift; sourceTree = "<group>"; };
|
||||
4949D15C2132614B00EF85E6 /* QRCodeUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QRCodeUtil.swift; sourceTree = "<group>"; };
|
||||
4952C3BE2115C7CA004A4FA8 /* ProxyMenuItemFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProxyMenuItemFactory.swift; sourceTree = "<group>"; };
|
||||
@ -197,6 +199,7 @@
|
||||
49CF3B6420CEE06C001EBF94 /* ConfigManager.swift */,
|
||||
4949D15C2132614B00EF85E6 /* QRCodeUtil.swift */,
|
||||
4960A6DA2136529200B940C9 /* JSBridgeHandler.swift */,
|
||||
4931969A21631E5D00A8E6E7 /* SpeedDataRecorder.swift */,
|
||||
);
|
||||
path = General;
|
||||
sourceTree = "<group>";
|
||||
@ -210,6 +213,15 @@
|
||||
path = Models;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
4931969C21631F2E00A8E6E7 /* Views */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
495340AF20DE5F7200B0D3FF /* StatusItemView.xib */,
|
||||
495340B220DE68C300B0D3FF /* StatusItemView.swift */,
|
||||
);
|
||||
path = Views;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
4949D157213260BD00EF85E6 /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@ -263,8 +275,6 @@
|
||||
children = (
|
||||
4952C3C82116E952004A4FA8 /* PreferencesWindowController.swift */,
|
||||
4952C3CA2116E952004A4FA8 /* PreferencesWindowController.xib */,
|
||||
495340AF20DE5F7200B0D3FF /* StatusItemView.xib */,
|
||||
495340B220DE68C300B0D3FF /* StatusItemView.swift */,
|
||||
49BC061B212931F4005A0FE7 /* AboutViewController.swift */,
|
||||
49B7F99F2157C1DC00484470 /* SpeedTestViewController.swift */,
|
||||
499976C721359F0400E7BF83 /* ClashWebViewContoller.swift */,
|
||||
@ -313,6 +323,7 @@
|
||||
4997732220D251A60009B136 /* Basic */,
|
||||
492C486E210EF621004554A0 /* Models */,
|
||||
492C4866210EE69B004554A0 /* General */,
|
||||
4931969C21631F2E00A8E6E7 /* Views */,
|
||||
4989F98520D0AA300001E564 /* ViewControllers */,
|
||||
49CF3B5D20CE80D2001EBF94 /* script */,
|
||||
49CF3B4B20CE5232001EBF94 /* ProxyConfig.xcodeproj */,
|
||||
@ -614,6 +625,7 @@
|
||||
49722FF0211F338B00650A41 /* EventStream.swift in Sources */,
|
||||
4952C3BF2115C7CA004A4FA8 /* ProxyMenuItemFactory.swift in Sources */,
|
||||
4966E9E32118153A00A391FB /* NSUserNotificationCenter+Extension.swift in Sources */,
|
||||
4931969B21631E5E00A8E6E7 /* SpeedDataRecorder.swift in Sources */,
|
||||
499976C821359F0400E7BF83 /* ClashWebViewContoller.swift in Sources */,
|
||||
49722FE4211ED56C00650A41 /* parseINI.swift in Sources */,
|
||||
4966E9E6211824F300A391FB /* NSImage+extension.swift in Sources */,
|
||||
|
@ -52,7 +52,14 @@ class ProxyMenuItemFactory {
|
||||
continue
|
||||
}
|
||||
}
|
||||
let proxyItem = NSMenuItem(title: proxy.stringValue, action: #selector(ProxyMenuItemFactory.actionSelectProxy(sender:)), keyEquivalent: "")
|
||||
var speedText = ""
|
||||
let placeHolder = "\t"
|
||||
if let speedInfo = SpeedDataRecorder.shared.speedDict[proxy.stringValue] {
|
||||
speedText = speedInfo > 0 ?"\(placeHolder)\(speedInfo) ms" : "\(placeHolder)fail"
|
||||
}
|
||||
|
||||
let proxyItem = ProxyMenuItem(title: proxy.stringValue + speedText, action: #selector(ProxyMenuItemFactory.actionSelectProxy(sender:)), keyEquivalent: "")
|
||||
proxyItem.proxyName = proxy.stringValue
|
||||
proxyItem.target = ProxyMenuItemFactory.self
|
||||
let selected = proxy.stringValue == selectedName
|
||||
proxyItem.state = selected ? .on : .off
|
||||
@ -62,7 +69,7 @@ class ProxyMenuItemFactory {
|
||||
menu.submenu = submenu
|
||||
|
||||
if (!hasSelected && submenu.items.count>0) {
|
||||
self.actionSelectProxy(sender: submenu.items[0])
|
||||
self.actionSelectProxy(sender: submenu.items[0] as! ProxyMenuItem)
|
||||
}
|
||||
return menu
|
||||
}
|
||||
@ -74,14 +81,15 @@ class ProxyMenuItemFactory {
|
||||
let submenu = NSMenu(title: proxyGroup.key)
|
||||
|
||||
let nowMenuItem = NSMenuItem(title: "now:\(selectedName)", action: nil, keyEquivalent: "")
|
||||
|
||||
submenu.addItem(nowMenuItem)
|
||||
menu.submenu = submenu
|
||||
return menu
|
||||
}
|
||||
|
||||
@objc static func actionSelectProxy(sender:NSMenuItem){
|
||||
@objc static func actionSelectProxy(sender:ProxyMenuItem){
|
||||
guard let proxyGroup = sender.menu?.title else {return}
|
||||
let proxyName = sender.title
|
||||
let proxyName = sender.proxyName
|
||||
|
||||
ApiRequest.updateProxyGroup(group: proxyGroup, selectProxy: proxyName) { (success) in
|
||||
if (success) {
|
||||
@ -97,3 +105,7 @@ class ProxyMenuItemFactory {
|
||||
|
||||
|
||||
}
|
||||
|
||||
class ProxyMenuItem:NSMenuItem {
|
||||
var proxyName:String = ""
|
||||
}
|
||||
|
16
ClashX/General/SpeedDataRecorder.swift
Normal file
16
ClashX/General/SpeedDataRecorder.swift
Normal file
@ -0,0 +1,16 @@
|
||||
//
|
||||
// SpeedDataRecorder.swift
|
||||
// ClashX
|
||||
//
|
||||
// Created by CYC on 2018/10/2.
|
||||
// Copyright © 2018 west2online. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
|
||||
class SpeedDataRecorder {
|
||||
static let shared = SpeedDataRecorder()
|
||||
private init(){}
|
||||
|
||||
var speedDict = [String:Int]()
|
||||
}
|
@ -60,6 +60,7 @@ class SpeedTestViewController: NSViewController {
|
||||
for proxy in proxies {
|
||||
ApiRequest.getProxyDelay(proxyName: proxy.name) {[weak self] (delay) in
|
||||
guard let strongSelf = self else {return}
|
||||
SpeedDataRecorder.shared.speedDict[proxy.name] = delay;
|
||||
proxy.delay = delay
|
||||
strongSelf.tableView.reloadData()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user