Improve a few things about provider profile menus

- Add "Connect" item to connect to current server

- Sort provider categories ("Default" should also come first)

Reuse bundle from constants.
This commit is contained in:
Davide De Rosa 2022-08-13 16:44:08 +02:00
parent 80f71507e3
commit 7a700408a8
5 changed files with 19 additions and 6 deletions

View File

@ -96,6 +96,7 @@ class DefaultLightProviderManager: LightProviderManager {
fatalError("Unrecognized VPN protocol: \(vpnProtocol)")
}
return providerManager.categories(name, vpnProtocol: vpnProtocolType)
.sorted()
.map(DefaultLightProviderCategory.init)
}

View File

@ -27,7 +27,7 @@ import Foundation
extension Constants {
enum Mac {
private static var bundle: Bundle {
static var bundle: Bundle {
Bundle(for: PassepartoutMac.self)
}

View File

@ -26,9 +26,7 @@
import Foundation
import AppKit
private var bundle: Bundle {
Bundle(for: PassepartoutMenu.StatusButton.self)
}
private let bundle = Constants.Mac.bundle
extension LightVPNStatus {
var localizedDescription: String {

View File

@ -58,6 +58,10 @@ extension ProviderProfileItem {
return category.name == profile.providerServer?.categoryName
}
func connectTo() {
vpnManager.connect(with: profile.id)
}
func downloadIfNeeded() {
providerManager.downloadIfNeeded(providerName, vpnProtocol: vpnProtocol)
}

View File

@ -51,12 +51,21 @@ struct ProviderProfileItem: Item {
private func submenu() -> NSMenu {
let menu = NSMenu()
let categories = viewModel.categories
if categories.isEmpty {
guard !categories.isEmpty else {
let downloadItem = TextItem(L10n.Global.Strings.download) {
viewModel.downloadIfNeeded()
}
menu.addItem(downloadItem.asMenuItem(withParent: menu))
} else if categories.count > 1 {
return menu
}
let connectItem = TextItem(L10n.Global.Strings.connect) {
viewModel.connectTo()
}
menu.addItem(connectItem.asMenuItem(withParent: menu))
menu.addItem(.separator())
if categories.count > 1 {
viewModel.categories.forEach {
menu.addItem(categoryItem(with: $0, parent: menu))
}
@ -65,6 +74,7 @@ struct ProviderProfileItem: Item {
menu.addItem(locationItem(with: $0, parent: menu))
}
}
return menu
}