Merge branch 'refactor-infrastructure-api'
This commit is contained in:
commit
bcffd9fd4a
|
@ -204,7 +204,6 @@ extension ProviderPoolViewController: UITableViewDataSource, UITableViewDelegate
|
|||
cell.imageView?.image = group.logo
|
||||
cell.leftText = pool.localizedCountry
|
||||
if group.pools.count > 1 {
|
||||
cell.rightText = pool.area
|
||||
cell.accessoryType = .detailDisclosureButton // no checkmark!
|
||||
} else {
|
||||
cell.rightText = pool.secondaryId
|
||||
|
@ -231,20 +230,9 @@ extension ProviderPoolViewController: UITableViewDataSource, UITableViewDelegate
|
|||
let vc = SingleOptionViewController<Pool>()
|
||||
vc.applyTint(.current)
|
||||
vc.title = group.localizedCountry
|
||||
vc.options = group.pools.sorted {
|
||||
guard let lnum = $0.num else {
|
||||
return true
|
||||
}
|
||||
guard let rnum = $1.num else {
|
||||
return false
|
||||
}
|
||||
guard lnum != rnum else {
|
||||
return $0.secondaryId < $1.secondaryId
|
||||
}
|
||||
return lnum < rnum
|
||||
}
|
||||
vc.options = group.pools.sortedPools()
|
||||
vc.selectedOption = currentPool
|
||||
vc.descriptionBlock = { $0.secondaryId }
|
||||
vc.descriptionBlock = { !$0.secondaryId.isEmpty ? $0.secondaryId : "Default" }
|
||||
vc.selectionBlock = {
|
||||
self.currentPool = $0
|
||||
self.delegate?.providerPoolController(self, didSelectPool: $0)
|
||||
|
|
|
@ -312,22 +312,33 @@ class StatusMenu: NSObject {
|
|||
item.indentationLevel = 1
|
||||
|
||||
for group in category.groups.sorted() {
|
||||
var title = group.localizedCountry
|
||||
if let area = group.area?.uppercased() {
|
||||
title = "\(title) - \(area)"
|
||||
}
|
||||
let title = group.localizedCountry
|
||||
|
||||
let itemGroup = NSMenuItem(title: title, action: #selector(connectToPool(_:)), keyEquivalent: "")
|
||||
let itemGroup = NSMenuItem(title: title, action: #selector(connectToGroup(_:)), keyEquivalent: "")
|
||||
itemGroup.image = group.logo
|
||||
itemGroup.target = self
|
||||
itemGroup.representedObject = group
|
||||
|
||||
let submenuGroup = NSMenu()
|
||||
for pool in group.pools {
|
||||
if pool.id == providerProfile.poolId {
|
||||
itemGroup.state = .on
|
||||
break
|
||||
}
|
||||
|
||||
let title = !pool.secondaryId.isEmpty ? pool.secondaryId : "Default"
|
||||
let item = NSMenuItem(title: title, action: #selector(connectToPool(_:)), keyEquivalent: "")
|
||||
if let extraCountry = pool.extraCountries?.first {
|
||||
item.image = extraCountry.image
|
||||
}
|
||||
item.target = self
|
||||
item.representedObject = pool
|
||||
submenuGroup.addItem(item)
|
||||
}
|
||||
if submenuGroup.numberOfItems > 1 {
|
||||
itemGroup.action = nil
|
||||
itemGroup.submenu = submenuGroup
|
||||
}
|
||||
|
||||
submenu.addItem(itemGroup)
|
||||
}
|
||||
menu.setSubmenu(submenu, for: item)
|
||||
|
@ -408,7 +419,7 @@ class StatusMenu: NSObject {
|
|||
vpn.reconnect(completionHandler: nil)
|
||||
}
|
||||
|
||||
@objc private func connectToPool(_ sender: Any?) {
|
||||
@objc private func connectToGroup(_ sender: Any?) {
|
||||
guard let item = sender as? NSMenuItem else {
|
||||
return
|
||||
}
|
||||
|
@ -426,6 +437,23 @@ class StatusMenu: NSObject {
|
|||
setActiveProfile(profile)
|
||||
}
|
||||
|
||||
@objc private func connectToPool(_ sender: Any?) {
|
||||
guard let item = sender as? NSMenuItem else {
|
||||
return
|
||||
}
|
||||
guard let pool = item.representedObject as? Pool else {
|
||||
return
|
||||
}
|
||||
guard let profile = service.activeProfile as? ProviderConnectionProfile else {
|
||||
return
|
||||
}
|
||||
service.setPoolId(pool.id, forProviderProfile: profile)
|
||||
vpn.reconnect(completionHandler: nil)
|
||||
|
||||
// update menu
|
||||
setActiveProfile(profile)
|
||||
}
|
||||
|
||||
@objc private func connectToEndpoint(_ sender: Any?) {
|
||||
guard let item = sender as? NSMenuItem else {
|
||||
return
|
||||
|
|
|
@ -205,22 +205,7 @@ class ProviderServiceView: NSView {
|
|||
|
||||
popupLocation.removeAllItems()
|
||||
sortedGroupsByCategory[category.name]?.forEach {
|
||||
guard let pool = $0.pools.first else {
|
||||
return
|
||||
}
|
||||
|
||||
var title = $0.localizedCountry
|
||||
let subtitle: String?
|
||||
if $0.pools.count > 1 {
|
||||
subtitle = pool.area?.uppercased()
|
||||
} else {
|
||||
subtitle = pool.secondaryId
|
||||
}
|
||||
if !(subtitle?.isEmpty ?? true) {
|
||||
title.append(" - \(subtitle!)")
|
||||
}
|
||||
|
||||
let item = NSMenuItem(title: title, action: nil, keyEquivalent: "")
|
||||
let item = NSMenuItem(title: $0.localizedCountry, action: nil, keyEquivalent: "")
|
||||
item.image = $0.logo
|
||||
menu.addItem(item)
|
||||
}
|
||||
|
@ -240,10 +225,11 @@ class ProviderServiceView: NSView {
|
|||
// FIXME: inefficient, cache sorted pools
|
||||
currentSortedPools = group.pools.sortedPools()
|
||||
currentSortedPools.forEach {
|
||||
guard !$0.secondaryId.isEmpty else {
|
||||
guard !$0.secondaryId.isEmpty || currentSortedPools.count > 1 else {
|
||||
return
|
||||
}
|
||||
let item = NSMenuItem(title: $0.secondaryId, action: nil, keyEquivalent: "")
|
||||
let title = !$0.secondaryId.isEmpty ? $0.secondaryId : "Default"
|
||||
let item = NSMenuItem(title: title, action: nil, keyEquivalent: "")
|
||||
if let extraCountry = $0.extraCountries?.first {
|
||||
item.image = extraCountry.image
|
||||
}
|
||||
|
|
|
@ -164,16 +164,22 @@ extension Pool {
|
|||
public extension Array where Element: Pool {
|
||||
func sortedPools() -> [Element] {
|
||||
return sorted {
|
||||
guard let lnum = $0.num else {
|
||||
return true
|
||||
guard let larea = $0.area else {
|
||||
guard let lnum = $0.num else {
|
||||
return true
|
||||
}
|
||||
guard let rnum = $1.num else {
|
||||
return false
|
||||
}
|
||||
guard lnum != rnum else {
|
||||
return $0.secondaryId < $1.secondaryId
|
||||
}
|
||||
return lnum < rnum
|
||||
}
|
||||
guard let rnum = $1.num else {
|
||||
guard let rarea = $1.area else {
|
||||
return false
|
||||
}
|
||||
guard lnum != rnum else {
|
||||
return $0.secondaryId < $1.secondaryId
|
||||
}
|
||||
return lnum < rnum
|
||||
return larea < rarea
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,24 +28,14 @@ import Foundation
|
|||
public class PoolGroup: Codable, Hashable, Comparable, CustomStringConvertible {
|
||||
public let country: String
|
||||
|
||||
public let area: String?
|
||||
|
||||
public let pools: [Pool]
|
||||
|
||||
private var id: String {
|
||||
var id = country
|
||||
if let area = area {
|
||||
id += area
|
||||
}
|
||||
return id
|
||||
return country
|
||||
}
|
||||
|
||||
private var localizedId: String {
|
||||
var localizedId = Utils.localizedCountry(country)
|
||||
if let area = area {
|
||||
localizedId += area
|
||||
}
|
||||
return localizedId
|
||||
return Utils.localizedCountry(country)
|
||||
}
|
||||
|
||||
// MARK: Equatable
|
||||
|
@ -69,7 +59,7 @@ public class PoolGroup: Codable, Hashable, Comparable, CustomStringConvertible {
|
|||
// MARK: CustomStringConvertible
|
||||
|
||||
public var description: String {
|
||||
return "{\(country), \(area ?? "--")}"
|
||||
return country
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,9 +74,6 @@ extension PoolGroup {
|
|||
var components: [String] = []
|
||||
components.append(category.name)
|
||||
components.append(country)
|
||||
if let area = area {
|
||||
components.append(area)
|
||||
}
|
||||
return components.joined(separator: "/")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 788446e77f215f8392ad0b031286247d6b245e58
|
||||
Subproject commit 39e7b17959e0eb855acf18cdeafe01593f9a2ac2
|
|
@ -1 +1 @@
|
|||
Subproject commit 3e23f4938ab858316dfa88ae9145c9916b00c44c
|
||||
Subproject commit bebda5619b27c60236266eb6a6e91b846cc90a4b
|
Loading…
Reference in New Issue