Skip to content

Commit

Permalink
Collapsed unselectable.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrFq1 committed Jul 3, 2022
1 parent 4b44f59 commit 84de92d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
5 changes: 1 addition & 4 deletions ClashX/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,6 @@ extension AppDelegate {

extension AppDelegate {
@IBAction func hideUnselectable(_ sender: NSMenuItem) {
/*
var newState = NSControl.StateValue.off
switch sender.state {
case .off:
Expand All @@ -789,10 +788,8 @@ extension AppDelegate {
default:
return
}
*/
let newState: NSControl.StateValue = sender.state == .on ? .off : .on

sender.state = newState

MenuItemFactory.hideUnselectable = newState.rawValue
}
}
Expand Down
29 changes: 23 additions & 6 deletions ClashX/General/Managers/MenuItemFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down

0 comments on commit 84de92d

Please sign in to comment.