feature(#513): show "Load Balance" in menu item for load balance group

This commit is contained in:
yicheng 2021-04-18 11:58:17 +08:00
parent 8c69bdd8e8
commit 610728aef5
5 changed files with 18 additions and 5 deletions

View File

@ -54,7 +54,7 @@ class MenuItemFactory {
case .select: menu = generateSelectorMenuItem(proxyGroup: proxy, proxyInfo: proxyInfo, leftPadding: leftPadding)
case .urltest, .fallback: menu = generateUrlTestFallBackMenuItem(proxyGroup: proxy, proxyInfo: proxyInfo, leftPadding: leftPadding)
case .loadBalance:
menu = generateLoadBalanceMenuItem(proxyGroup: proxy, proxyInfo: proxyInfo)
menu = generateLoadBalanceMenuItem(proxyGroup: proxy, proxyInfo: proxyInfo, leftPadding: leftPadding)
case .relay:
menu = generateListOnlyMenuItem(proxyGroup: proxy, proxyInfo: proxyInfo)
default: continue
@ -181,10 +181,13 @@ class MenuItemFactory {
(menu as? ProxyGroupMenu)?.add(delegate: speedTestItem)
}
private static func generateLoadBalanceMenuItem(proxyGroup: ClashProxy, proxyInfo: ClashProxyResp) -> NSMenuItem? {
private static func generateLoadBalanceMenuItem(proxyGroup: ClashProxy, proxyInfo: ClashProxyResp, leftPadding: Bool) -> NSMenuItem? {
let proxyMap = proxyInfo.proxiesMap
let menu = NSMenuItem(title: proxyGroup.name, action: nil, keyEquivalent: "")
if !ConfigManager.shared.disableShowCurrentProxyInMenu {
menu.view = ProxyGroupMenuItemView(group: proxyGroup.name, targetProxy: NSLocalizedString("Load Balance", comment: ""), hasLeftPadding: leftPadding, observeUpdate: false)
}
let submenu = ProxyGroupMenu(title: proxyGroup.name)
for proxy in proxyGroup.all ?? [] {

View File

@ -1,3 +1,4 @@
/* No comment provided by engineer. */
"Add a remote config" = "Add a remote config";
@ -76,6 +77,9 @@
/* No comment provided by engineer. */
"Legacy Install" = "Legacy Install";
/* No comment provided by engineer. */
"Load Balance" = "Load Balance";
/* No comment provided by engineer. */
"Need to Restart the ClashX to Take effect, Please start clashX manually" = "Need to Restart the ClashX to Take effect, Please start clashX manually";

View File

@ -1,3 +1,4 @@
/* No comment provided by engineer. */
"Add a remote config" = "添加托管配置文件";
@ -76,6 +77,9 @@
/* No comment provided by engineer. */
"Legacy Install" = "传统安装";
/* No comment provided by engineer. */
"Load Balance" = "负载均衡";
/* No comment provided by engineer. */
"Need to Restart the ClashX to Take effect, Please start clashX manually" = "需要重启ClashX生效请手动启动ClashX";

View File

@ -31,7 +31,7 @@ class ProxyGroupMenuItemView: MenuItemBaseView {
return [groupNameLabel.cell, selectProxyLabel.cell, arrowLabel.cell]
}
init(group: ClashProxyName, targetProxy: ClashProxyName, hasLeftPadding: Bool) {
init(group: ClashProxyName, targetProxy: ClashProxyName, hasLeftPadding: Bool, observeUpdate:Bool = true) {
groupNameLabel = VibrancyTextField(labelWithString: group)
selectProxyLabel = VibrancyTextField(labelWithString: targetProxy)
super.init(autolayout: true)
@ -74,8 +74,9 @@ class ProxyGroupMenuItemView: MenuItemBaseView {
groupNameLabel.textColor = NSColor.labelColor
selectProxyLabel.textColor = NSColor.secondaryLabelColor
// noti
NotificationCenter.default.addObserver(self, selector: #selector(proxyInfoDidUpdate(note:)), name: .proxyUpdate(for: group), object: nil)
if observeUpdate {
NotificationCenter.default.addObserver(self, selector: #selector(proxyInfoDidUpdate(note:)), name: .proxyUpdate(for: group), object: nil)
}
if #available(macOS 11, *) {
updateLeftMenuPadding(show: hasLeftPadding)
NotificationCenter.default.addObserver(self, selector: #selector(showLeftPaddingUpdate(note:)), name: .proxyMeneViewShowLeftPadding, object: nil)

View File

@ -1,3 +1,4 @@
/* Class = "NSMenuItem"; title = "ERROR"; ObjectID = "0iu-lB-eZN"; */
"0iu-lB-eZN.title" = "ERROR";