diff --git a/ClashX/AppDelegate.swift b/ClashX/AppDelegate.swift index 74e0882e3..e18142cf6 100644 --- a/ClashX/AppDelegate.swift +++ b/ClashX/AppDelegate.swift @@ -777,7 +777,6 @@ extension AppDelegate { extension AppDelegate { @IBAction func hideUnselectable(_ sender: NSMenuItem) { - /* var newState = NSControl.StateValue.off switch sender.state { case .off: @@ -789,10 +788,8 @@ extension AppDelegate { default: return } - */ - let newState: NSControl.StateValue = sender.state == .on ? .off : .on + sender.state = newState - MenuItemFactory.hideUnselectable = newState.rawValue } } diff --git a/ClashX/General/Managers/MenuItemFactory.swift b/ClashX/General/Managers/MenuItemFactory.swift index 91b414a08..a9b2b9d1a 100644 --- a/ClashX/General/Managers/MenuItemFactory.swift +++ b/ClashX/General/Managers/MenuItemFactory.swift @@ -58,12 +58,9 @@ class MenuItemFactory { let hideState = NSControl.StateValue(rawValue: hideUnselectable) var menuItems = [NSMenuItem]() + var collapsedItems = [NSMenuItem]() + for proxy in proxyInfo.proxyGroups { - if hideState != .off, - [.urltest, .fallback, .loadBalance, .relay].contains(proxy.type) { - continue - } - var menu: NSMenuItem? switch proxy.type { case .select: menu = generateSelectorMenuItem(proxyGroup: proxy, proxyInfo: proxyInfo, leftPadding: leftPadding) @@ -75,11 +72,31 @@ class MenuItemFactory { default: continue } - if let menu = menu { + guard let menu = menu else { + continue + } + + switch hideState { + case .mixed where [.urltest, .fallback, .loadBalance, .relay].contains(proxy.type): + collapsedItems.append(menu) + menu.isEnabled = true + case .on where [.urltest, .fallback, .loadBalance, .relay].contains(proxy.type): + continue + default: menuItems.append(menu) menu.isEnabled = true } } + + if hideState == .mixed { + let collapsedItem = NSMenuItem(title: "Collapsed", action: nil, keyEquivalent: "") + collapsedItem.isEnabled = true + collapsedItem.submenu = .init(title: "") + collapsedItem.submenu?.items = collapsedItems + + menuItems.append(collapsedItem) + } + let items = Array(menuItems.reversed()) updateProxyList(withMenus: items) }