mirror of
https://github.com/passepartoutvpn/passepartout-apple.git
synced 2025-02-22 15:52:08 +00:00
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.imageView?.image = group.logo
|
||||||
cell.leftText = pool.localizedCountry
|
cell.leftText = pool.localizedCountry
|
||||||
if group.pools.count > 1 {
|
if group.pools.count > 1 {
|
||||||
cell.rightText = pool.area
|
|
||||||
cell.accessoryType = .detailDisclosureButton // no checkmark!
|
cell.accessoryType = .detailDisclosureButton // no checkmark!
|
||||||
} else {
|
} else {
|
||||||
cell.rightText = pool.secondaryId
|
cell.rightText = pool.secondaryId
|
||||||
@ -231,20 +230,9 @@ extension ProviderPoolViewController: UITableViewDataSource, UITableViewDelegate
|
|||||||
let vc = SingleOptionViewController<Pool>()
|
let vc = SingleOptionViewController<Pool>()
|
||||||
vc.applyTint(.current)
|
vc.applyTint(.current)
|
||||||
vc.title = group.localizedCountry
|
vc.title = group.localizedCountry
|
||||||
vc.options = group.pools.sorted {
|
vc.options = group.pools.sortedPools()
|
||||||
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.selectedOption = currentPool
|
vc.selectedOption = currentPool
|
||||||
vc.descriptionBlock = { $0.secondaryId }
|
vc.descriptionBlock = { !$0.secondaryId.isEmpty ? $0.secondaryId : "Default" }
|
||||||
vc.selectionBlock = {
|
vc.selectionBlock = {
|
||||||
self.currentPool = $0
|
self.currentPool = $0
|
||||||
self.delegate?.providerPoolController(self, didSelectPool: $0)
|
self.delegate?.providerPoolController(self, didSelectPool: $0)
|
||||||
|
@ -312,22 +312,33 @@ class StatusMenu: NSObject {
|
|||||||
item.indentationLevel = 1
|
item.indentationLevel = 1
|
||||||
|
|
||||||
for group in category.groups.sorted() {
|
for group in category.groups.sorted() {
|
||||||
var title = group.localizedCountry
|
let title = group.localizedCountry
|
||||||
if let area = group.area?.uppercased() {
|
|
||||||
title = "\(title) - \(area)"
|
|
||||||
}
|
|
||||||
|
|
||||||
let itemGroup = NSMenuItem(title: title, action: #selector(connectToPool(_:)), keyEquivalent: "")
|
let itemGroup = NSMenuItem(title: title, action: #selector(connectToGroup(_:)), keyEquivalent: "")
|
||||||
itemGroup.image = group.logo
|
itemGroup.image = group.logo
|
||||||
itemGroup.target = self
|
itemGroup.target = self
|
||||||
itemGroup.representedObject = group
|
itemGroup.representedObject = group
|
||||||
|
|
||||||
|
let submenuGroup = NSMenu()
|
||||||
for pool in group.pools {
|
for pool in group.pools {
|
||||||
if pool.id == providerProfile.poolId {
|
if pool.id == providerProfile.poolId {
|
||||||
itemGroup.state = .on
|
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)
|
submenu.addItem(itemGroup)
|
||||||
}
|
}
|
||||||
menu.setSubmenu(submenu, for: item)
|
menu.setSubmenu(submenu, for: item)
|
||||||
@ -408,7 +419,7 @@ class StatusMenu: NSObject {
|
|||||||
vpn.reconnect(completionHandler: nil)
|
vpn.reconnect(completionHandler: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func connectToPool(_ sender: Any?) {
|
@objc private func connectToGroup(_ sender: Any?) {
|
||||||
guard let item = sender as? NSMenuItem else {
|
guard let item = sender as? NSMenuItem else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -426,6 +437,23 @@ class StatusMenu: NSObject {
|
|||||||
setActiveProfile(profile)
|
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?) {
|
@objc private func connectToEndpoint(_ sender: Any?) {
|
||||||
guard let item = sender as? NSMenuItem else {
|
guard let item = sender as? NSMenuItem else {
|
||||||
return
|
return
|
||||||
|
@ -205,22 +205,7 @@ class ProviderServiceView: NSView {
|
|||||||
|
|
||||||
popupLocation.removeAllItems()
|
popupLocation.removeAllItems()
|
||||||
sortedGroupsByCategory[category.name]?.forEach {
|
sortedGroupsByCategory[category.name]?.forEach {
|
||||||
guard let pool = $0.pools.first else {
|
let item = NSMenuItem(title: $0.localizedCountry, action: nil, keyEquivalent: "")
|
||||||
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: "")
|
|
||||||
item.image = $0.logo
|
item.image = $0.logo
|
||||||
menu.addItem(item)
|
menu.addItem(item)
|
||||||
}
|
}
|
||||||
@ -240,10 +225,11 @@ class ProviderServiceView: NSView {
|
|||||||
// FIXME: inefficient, cache sorted pools
|
// FIXME: inefficient, cache sorted pools
|
||||||
currentSortedPools = group.pools.sortedPools()
|
currentSortedPools = group.pools.sortedPools()
|
||||||
currentSortedPools.forEach {
|
currentSortedPools.forEach {
|
||||||
guard !$0.secondaryId.isEmpty else {
|
guard !$0.secondaryId.isEmpty || currentSortedPools.count > 1 else {
|
||||||
return
|
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 {
|
if let extraCountry = $0.extraCountries?.first {
|
||||||
item.image = extraCountry.image
|
item.image = extraCountry.image
|
||||||
}
|
}
|
||||||
|
@ -164,6 +164,7 @@ extension Pool {
|
|||||||
public extension Array where Element: Pool {
|
public extension Array where Element: Pool {
|
||||||
func sortedPools() -> [Element] {
|
func sortedPools() -> [Element] {
|
||||||
return sorted {
|
return sorted {
|
||||||
|
guard let larea = $0.area else {
|
||||||
guard let lnum = $0.num else {
|
guard let lnum = $0.num else {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -175,5 +176,10 @@ public extension Array where Element: Pool {
|
|||||||
}
|
}
|
||||||
return lnum < rnum
|
return lnum < rnum
|
||||||
}
|
}
|
||||||
|
guard let rarea = $1.area else {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return larea < rarea
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,24 +28,14 @@ import Foundation
|
|||||||
public class PoolGroup: Codable, Hashable, Comparable, CustomStringConvertible {
|
public class PoolGroup: Codable, Hashable, Comparable, CustomStringConvertible {
|
||||||
public let country: String
|
public let country: String
|
||||||
|
|
||||||
public let area: String?
|
|
||||||
|
|
||||||
public let pools: [Pool]
|
public let pools: [Pool]
|
||||||
|
|
||||||
private var id: String {
|
private var id: String {
|
||||||
var id = country
|
return country
|
||||||
if let area = area {
|
|
||||||
id += area
|
|
||||||
}
|
|
||||||
return id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private var localizedId: String {
|
private var localizedId: String {
|
||||||
var localizedId = Utils.localizedCountry(country)
|
return Utils.localizedCountry(country)
|
||||||
if let area = area {
|
|
||||||
localizedId += area
|
|
||||||
}
|
|
||||||
return localizedId
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Equatable
|
// MARK: Equatable
|
||||||
@ -69,7 +59,7 @@ public class PoolGroup: Codable, Hashable, Comparable, CustomStringConvertible {
|
|||||||
// MARK: CustomStringConvertible
|
// MARK: CustomStringConvertible
|
||||||
|
|
||||||
public var description: String {
|
public var description: String {
|
||||||
return "{\(country), \(area ?? "--")}"
|
return country
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,9 +74,6 @@ extension PoolGroup {
|
|||||||
var components: [String] = []
|
var components: [String] = []
|
||||||
components.append(category.name)
|
components.append(category.name)
|
||||||
components.append(country)
|
components.append(country)
|
||||||
if let area = area {
|
|
||||||
components.append(area)
|
|
||||||
}
|
|
||||||
return components.joined(separator: "/")
|
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
Block a user